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


PHP DI::has方法代码示例

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


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

示例1: testRegisterRoutes

 public function testRegisterRoutes()
 {
     $this->testable->registerRoutes();
     /* @var Router $router */
     $router = $this->testable->getRouter();
     $this->assertFalse($this->di->has('router'));
     $this->assertNotEmpty($router->getRoutes());
     $this->assertTrue(is_array($router->getRoutes()));
     $this->assertCount(8, $router->getRoutes());
     $this->assertInstanceOf('Phalcon\\Mvc\\Router\\Route', $router->getRouteByName('fifi'));
     $this->assertInstanceOf('Phalcon\\Mvc\\Router\\Route', $router->getRouteByName('get-all'));
 }
开发者ID:kachit,项目名称:phalcon-lib,代码行数:12,代码来源:RouterTest.php

示例2: modifyResponse

 /**
  * @param  Response $response
  *
  * @return mixed
  * @throws Exception
  */
 public function modifyResponse($response)
 {
     $request = $this->di['request'];
     $config = $this->config;
     if (!$this->isEnabled()) {
         return $response;
     }
     if ($this->shouldCollect('config', false) && $this->di->has('config')) {
         try {
             $config_data = $this->di['config']->toArray();
             $protect = $config->options->config->get('protect');
             $configCollector = new ConfigCollector($config_data);
             $configCollector->setProtect($protect);
             $this->addCollector($configCollector);
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add ConfigCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->shouldCollect('session') && $this->di->has('session')) {
         try {
             $this->addCollector(new SessionCollector($this->di['session']));
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add SessionCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->shouldCollect('phalcon_request', true) and !$this->hasCollector('request')) {
         try {
             $this->addCollector(new PhalconRequestCollector($this->di['request'], $response, $this->di));
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add PhalconRequestCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->hasCollector('pdo')) {
         /** @var Profiler $profiler */
         $profiler = $this->getCollector('pdo')->getProfiler();
         $profiler->handleFailed();
     }
     if ($this->isDebugbarRequest) {
         // Notice: All Collectors must be added before check if is debugbar request.
         return $response;
     }
     try {
         if ($this->isRedirection($response)) {
             $this->stackData();
         } elseif ($this->isJsonRequest($request) && $this->config->get('capture_ajax', true)) {
             $this->sendDataInHeaders(true);
         } elseif ($content_type = $response->getHeaders()->get('Content-Type') and strpos($response->getHeaders()->get('Content-Type'), 'html') === false) {
             $this->collect();
         } elseif ($this->config->get('inject', true)) {
             $response->setHeader('Phalcon-Debugbar', 'on');
             $this->injectDebugbar($response);
         }
     } catch (\Exception $e) {
         $this->addException($e);
     }
     // Stop further rendering (on subrequests etc)
     $this->disable();
     return $response;
 }
开发者ID:snowair,项目名称:phalcon-debugbar,代码行数:65,代码来源:PhalconDebugbar.php

示例3: __construct

 public function __construct(DI $di, $aggregate = true, $formatter = 'line')
 {
     $this->_di = $di;
     $this->_debugbar = $this->_di['debugbar'];
     $this->_formatter = strtolower($formatter);
     if ($di->has('log') && ($log = $di->get('log'))) {
         $debugbar_loger = new Debugbar($di['debugbar']);
         if ($log instanceof Adapter) {
             $di->remove('log');
             $multiple = new Multiple();
             $multiple->push(clone $log);
             $multiple->push($debugbar_loger);
             /** @var DI\Service $service */
             $di->set('log', $multiple);
         } elseif ($log instanceof Multiple) {
             $log->push($debugbar_loger);
         }
         $this->_aggregate = $this->isAggregate($aggregate);
     }
 }
开发者ID:vpg,项目名称:phalcon-debugbar,代码行数:20,代码来源:LogsCollector.php

示例4: has

 /**
  * {@inheritdoc}
  */
 public function has($id)
 {
     return $this->di->has($id);
 }
开发者ID:theDisco,项目名称:phalcon-expressive,代码行数:7,代码来源:PhalconDI.php

示例5: _initDb

 /**
  * Init database.
  *
  * @param DI            $di            Dependency Injection.
  * @param Config        $config        Config object.
  * @param EventsManager $eventsManager Event manager.
  *
  * @return Pdo
  */
 protected function _initDb($di, $config, $eventsManager)
 {
     $adapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $config->db->mysql->adapter;
     /** @var Pdo $connection */
     $connection = new $adapter(['host' => $config->db->mysql->host, 'port' => $config->db->mysql->port, 'username' => $config->db->mysql->username, 'password' => $config->db->mysql->password, 'dbname' => $config->db->mysql->dbname]);
     $isProfiler = $config->global->profiler;
     if ($isProfiler) {
         // Attach logger & profiler.
         $profiler = null;
         if ($isProfiler) {
             $profiler = new PhDbProfiler();
         }
         $eventsManager->attach('db', function ($event, $connection) use($profiler) {
             if ($event->getType() == 'beforeQuery') {
                 $statement = $connection->getSQLStatement();
                 if ($profiler) {
                     $profiler->startProfile($statement);
                 }
             }
             if ($event->getType() == 'afterQuery') {
                 // Stop the active profile.
                 if ($profiler) {
                     $profiler->stopProfile();
                 }
             }
         });
         if ($profiler && $di->has('profiler')) {
             $di->get('profiler')->setDbProfiler($profiler);
         }
         $connection->setEventsManager($eventsManager);
     }
     $di->set('db', $connection);
     /**
      * Add db service connect to five.vn database
      */
     $di->set('dbfive', function () use($config) {
         $fiveAdapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $config->db->dbfive->adapter;
         return new $fiveAdapter(['host' => $config->db->dbfive->host, 'port' => $config->db->dbfive->port, 'username' => $config->db->dbfive->username, 'password' => $config->db->dbfive->password, 'dbname' => $config->db->dbfive->dbname]);
     });
     $di->set('modelsManager', function () use($config, $eventsManager) {
         $modelsManager = new PhModelsManager();
         $modelsManager->setEventsManager($eventsManager);
         // Attach a listener to models-manager
         $eventsManager->attach('modelsManager', new ModelAnnotationsInitializer());
         return $modelsManager;
     }, true);
     /**
      * If the configuration specify the use of metadata adapter use it or use memory otherwise.
      */
     $di->set('modelsMetadata', function () use($config) {
         if (ENV == ENV_PRODUCTION && isset($config->global->metadata)) {
             $metaDataConfig = $config->global->metadata;
             $metadataAdapter = '\\Phalcon\\Mvc\\Model\\Metadata\\' . $metaDataConfig->adapter;
             $metaData = new $metadataAdapter($config->global->metadata->toArray());
         } else {
             $metaData = new \Phalcon\Mvc\Model\MetaData\Memory();
         }
         $metaData->setStrategy(new PhStrategyAnnotations());
         return $metaData;
     }, true);
     return $connection;
 }
开发者ID:nguyenducduy,项目名称:haraapp,代码行数:71,代码来源:Init.php

示例6: _initDatabase

 /**
  * Init database.
  *
  * @param DI            $di            Dependency Injection.
  * @param Config        $config        Config object.
  * @param EventsManager $eventsManager Event manager.
  *
  * @return Pdo
  */
 protected function _initDatabase($di, $config, $eventsManager)
 {
     if (!$config->installed) {
         return;
     }
     $adapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $config->database->adapter;
     /** @var Pdo $connection */
     $connection = new $adapter(["host" => $config->database->host, "port" => $config->database->port, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname]);
     $isDebug = $config->application->debug;
     $isProfiler = $config->application->profiler;
     if ($isDebug || $isProfiler) {
         // Attach logger & profiler.
         $logger = null;
         $profiler = null;
         if ($isDebug) {
             $logger = new File($config->application->logger->path . "db.log");
         }
         if ($isProfiler) {
             $profiler = new DatabaseProfiler();
         }
         $eventsManager->attach('db', function ($event, $connection) use($logger, $profiler) {
             if ($event->getType() == 'beforeQuery') {
                 $statement = $connection->getSQLStatement();
                 if ($logger) {
                     $logger->log($statement, Logger::INFO);
                 }
                 if ($profiler) {
                     $profiler->startProfile($statement);
                 }
             }
             if ($event->getType() == 'afterQuery') {
                 // Stop the active profile.
                 if ($profiler) {
                     $profiler->stopProfile();
                 }
             }
         });
         if ($profiler && $di->has('profiler')) {
             $di->get('profiler')->setDbProfiler($profiler);
         }
         $connection->setEventsManager($eventsManager);
     }
     $di->set('db', $connection);
     $di->set('modelsManager', function () use($config, $eventsManager) {
         $modelsManager = new ModelsManager();
         $modelsManager->setEventsManager($eventsManager);
         // Attach a listener to models-manager
         $eventsManager->attach('modelsManager', new ModelAnnotationsInitializer());
         return $modelsManager;
     }, true);
     /**
      * If the configuration specify the use of metadata adapter use it or use memory otherwise.
      */
     $di->set('modelsMetadata', function () use($config) {
         if (!$config->application->debug && isset($config->application->metadata)) {
             $metaDataConfig = $config->application->metadata;
             $metadataAdapter = '\\Phalcon\\Mvc\\Model\\Metadata\\' . $metaDataConfig->adapter;
             $metaData = new $metadataAdapter($config->application->metadata->toArray());
         } else {
             $metaData = new \Phalcon\Mvc\Model\MetaData\Memory();
         }
         $metaData->setStrategy(new StrategyAnnotations());
         return $metaData;
     }, true);
     return $connection;
 }
开发者ID:biggtfish,项目名称:cms,代码行数:75,代码来源:ApplicationInitialization.php


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