当前位置: 首页>>代码示例>>PHP>>正文


PHP Set::singleton方法代码示例

本文整理汇总了PHP中Slim\Helper\Set::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::singleton方法的具体用法?PHP Set::singleton怎么用?PHP Set::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim\Helper\Set的用法示例。


在下文中一共展示了Set::singleton方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: configureIoc

 /**
  * Configure inversion of control/dependency injection container.
  *
  * @param \Slim\Helper\Set $container IOC container
  */
 protected function configureIoc(\Slim\Helper\Set $container)
 {
     $container->singleton('i18nCache', function ($c) {
         return new JsonCache($c->settings['i18n.path'], $c->log);
     });
     $container->singleton('i18nContext', function ($c) {
         return new I18nContext($c->i18nCache, $c->settings['i18n.default'], $c->log);
     });
     $container->singleton('mailer', function ($c) {
         return new Mailer(['Host' => $c->settings['smtp.host']], $c->log);
     });
     $container->singleton('parsoid', function ($c) {
         return new ParsoidClient($c->settings['parsoid.url'], $c->settings['parsoid.cache'], $c->log);
     });
     $container->singleton('logs', function ($c) {
         return new Logs(new \Elastica\Client(['url' => $c->settings['es.url']]), $c->log);
     });
     // TODO: figure out where to send logs
 }
开发者ID:bd808,项目名称:SAL,代码行数:24,代码来源:App.php

示例2: configureIoc

 /**
  * Configure inversion of control/dependency injection container.
  *
  * @param \Slim\Helper\Set $container IOC container
  */
 protected function configureIoc(\Slim\Helper\Set $container)
 {
     $container->singleton('i18nCache', function ($c) {
         return new JsonCache($c->settings['i18n.path'], $c->log);
     });
     $container->singleton('i18nContext', function ($c) {
         return new I18nContext($c->i18nCache, $c->settings['i18n.default'], $c->log);
     });
     $container->singleton('mailer', function ($c) {
         return new Mailer(array('Host' => $c->settings['smtp.host']), $c->log);
     });
     $container->singleton('parsoid', function ($c) {
         return new ParsoidClient($c->settings['parsoid.url'], $c->settings['parsoid.cache'], $c->log);
     });
     $container->singleton('quips', function ($c) {
         $settings = array('url' => $c->settings['es.url'], 'log' => true);
         if ($c->settings['es.user'] !== '') {
             $creds = base64_encode($c->settings['es.user'] . ':' . $c->settings['es.password']);
             $settings['headers'] = array('Authorization' => "Basic {$creds}");
         }
         $client = new \Elastica\Client($settings);
         $client->setLogger($c->log);
         return new Quips($client, $c->log);
     });
     $container->singleton('oauthConfig', function ($c) {
         $conf = new \MediaWiki\OAuthClient\ClientConfig($c->settings['oauth.endpoint']);
         $conf->setRedirURL($c->settings['oauth.redir']);
         $conf->setConsumer(new \MediaWiki\OAuthClient\Consumer($c->settings['oauth.consumer_token'], $c->settings['oauth.secret_token']));
         return $conf;
     });
     $container->singleton('oauthClient', function ($c) {
         $client = new \MediaWiki\OAuthClient\Client($c->oauthConfig, $c->log);
         $client->setCallback($c->settings['oauth.callback']);
         return $client;
     });
     $container->singleton('userManager', function ($c) {
         return new OAuthUserManager($c->oauthClient, $c->log);
     });
     $container->singleton('authManager', function ($c) {
         return new AuthManager($c->userManager);
     });
     // TODO: figure out where to send logs
 }
开发者ID:bd808,项目名称:quips,代码行数:48,代码来源:App.php

示例3: __construct

 /**
  * Constructor
  * @param  array $userSettings Associative array of application settings
  */
 public function __construct(array $userSettings = array())
 {
     // Setup IoC container
     $this->container = new \Slim\Helper\Set();
     $this->container['settings'] = array_merge(static::getDefaultSettings(), $userSettings);
     // Default environment
     $this->container->singleton('environment', function ($c) {
         return \Slim\Environment::getInstance();
     });
     // Default request
     $this->container->singleton('request', function ($c) {
         return new \Slim\Http\Request($c['environment']);
     });
     // Default response
     $this->container->singleton('response', function ($c) {
         return new \Slim\Http\Response();
     });
     // Default router
     $this->container->singleton('router', function ($c) {
         return new \Slim\Router();
     });
     // Default view
     $this->container->singleton('view', function ($c) {
         $viewClass = $c['settings']['view'];
         return $viewClass instanceof \Slim\View ? $viewClass : new $viewClass();
     });
     // Default log writer
     $this->container->singleton('logWriter', function ($c) {
         $logWriter = $c['settings']['log.writer'];
         return is_object($logWriter) ? $logWriter : new \Slim\LogWriter($c['environment']['slim.errors']);
     });
     // Default log
     $this->container->singleton('log', function ($c) {
         $log = new \Slim\Log($c['logWriter']);
         $log->setEnabled($c['settings']['log.enabled']);
         $log->setLevel($c['settings']['log.level']);
         $env = $c['environment'];
         $env['slim.log'] = $log;
         return $log;
     });
     // Default mode
     $this->container['mode'] = function ($c) {
         $mode = $c['settings']['mode'];
         if (isset($_ENV['SLIM_MODE'])) {
             $mode = $_ENV['SLIM_MODE'];
         } else {
             $envMode = getenv('SLIM_MODE');
             if ($envMode !== false) {
                 $mode = $envMode;
             }
         }
         return $mode;
     };
     // Define default middleware stack
     $this->middleware = array($this);
     $this->add(new \Slim\Middleware\Flash());
     $this->add(new \Slim\Middleware\MethodOverride());
     // Make default if first instance
     if (is_null(static::getInstance())) {
         $this->setName('default');
     }
 }
开发者ID:pantnik,项目名称:DIYiotServer,代码行数:66,代码来源:Slim.php

示例4: testConsumeSlimContainer

 public function testConsumeSlimContainer()
 {
     $anoterContainer = new Set();
     $anoterContainer->foo = [];
     $anoterContainer->bar = new \stdClass();
     $anoterContainer->baz = function ($c) {
         return 'Hello';
     };
     $anoterContainer->singleton('foobar', function ($c) {
         return 'Hello';
     });
     $anoterContainer->barfoo = [$this, 'fakeMethod'];
     $this->container->consumeSlimContainer($anoterContainer);
     $this->assertTrue($this->sm->has('foo'));
     $this->assertTrue($this->container->has('foo'));
     $this->assertTrue($this->sm->has('bar'));
     $this->assertTrue($this->container->has('bar'));
     $this->assertTrue($this->sm->has('baz'));
     $this->assertTrue($this->container->has('baz'));
     $this->assertTrue($this->sm->has('foobar'));
     $this->assertTrue($this->container->has('foobar'));
     $this->assertTrue($this->sm->has('barfoo'));
     $this->assertTrue($this->container->has('barfoo'));
 }
开发者ID:acelaya,项目名称:slim-container-sm,代码行数:24,代码来源:ContainerTest.php

示例5: __construct

 /**
  * Constructor
  * @param  array $userSettings Associative array of application settings
  */
 public function __construct(array $userSettings = array())
 {
     // Setup IoC container
     $this->container = new \Slim\Helper\Set();
     $this->container['settings'] = array_merge(static::getDefaultSettings(), $userSettings);
     // Default environment
     $this->container->singleton('environment', function ($c) {
         return \Slim\Environment::getInstance();
     });
     // Default request
     $this->container->singleton('request', function ($c) {
         return new \Slim\Http\Request($c['environment']);
     });
     // Default response
     $this->container->singleton('response', function ($c) {
         return new \Slim\Http\Response();
     });
     // Default router
     $this->container->singleton('router', function ($c) {
         return new \Slim\Router();
     });
     // Default view
     $this->container->singleton('view', function ($c) {
         $viewClass = $c['settings']['view'];
         $templatesPath = $c['settings']['templates.path'];
         $view = $viewClass instanceof \Slim\View ? $viewClass : new $viewClass();
         $view->setTemplatesDirectory($templatesPath);
         return $view;
     });
     // Default log writer
     $this->container->singleton('logWriter', function ($c) {
         $logWriter = $c['settings']['log.writer'];
         return is_object($logWriter) ? $logWriter : new \Slim\LogWriter($c['environment']['slim.errors']);
     });
     // Default log
     $this->container->singleton('log', function ($c) {
         $log = new \Slim\Log($c['logWriter']);
         $log->setEnabled($c['settings']['log.enabled']);
         /**
          * set exception and message queue cnofiguration to logger 
          * @author Mustafa Zeynel Dağlı
          */
         $log->setExceptionsQueue($c['settings']['exceptions.rabbitMQ']);
         /**
          * set message queue logging format on message receiver
          * @author Mustafa Zeynel Dağlı
          */
         $log->setExceptionsQueueLogging($c['settings']['exceptions.rabbitMQ.logging']);
         /**
          * set exception queue name
          * @author Mustafa Zeynel Dağlı
          */
         $log->setExceptionsQueueName($c['settings']['exceptions.rabbitMQ.queue.name']);
         /**
          * set serial for message queue in log class
          * @author Mustafa Zeynel Dağlı
          */
         $log->setSerial($c['settings']['request.serial']);
         //print_r('slim construct log level-->'.$c['settings']['log.level']);
         $log->setLevel($c['settings']['log.level']);
         $env = $c['environment'];
         $env['slim.log'] = $log;
         return $log;
     });
     // Default mode
     $this->container['mode'] = function ($c) {
         $mode = $c['settings']['mode'];
         if (isset($_ENV['SLIM_MODE'])) {
             $mode = $_ENV['SLIM_MODE'];
         } else {
             $envMode = getenv('SLIM_MODE');
             if ($envMode !== false) {
                 $mode = $envMode;
             }
         }
         return $mode;
     };
     // Define default middleware stack
     $this->middleware = array($this);
     //$this->add(new \Slim\Middleware\Flash());
     $this->add(new \Slim\Middleware\MethodOverride());
     //$this->add(new \Slim\Middleware\MiddlewareTest());
     $this->add(new \Slim\Middleware\Flash());
     //$this->add(new \Slim\Middleware\MethodOverride());
     // Make default if first instance
     if (is_null(static::getInstance())) {
         $this->setName('default');
     }
 }
开发者ID:corner82,项目名称:Slim_SanalFabrika,代码行数:93,代码来源:Slim.php


注:本文中的Slim\Helper\Set::singleton方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。