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


PHP DI::getShared方法代码示例

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


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

示例1: get

 /**
  * {@inheritdoc}
  */
 public function get($id)
 {
     if (!$this->has($id)) {
         throw new Exception\ServiceNotFound("Service `{$id}` not found in the container.");
     }
     try {
         return $this->di->getShared($id);
     } catch (DI\Exception $e) {
         throw new Exception\ContainerError("Cannot retrieve `{$id}` from the container.", 0, $e);
     }
 }
开发者ID:theDisco,项目名称:phalcon-expressive,代码行数:14,代码来源:PhalconDI.php

示例2: registerServices

 /**
  * @param DI $di
  */
 public function registerServices($di)
 {
     //Registering a dispatcher
     $di->setShared('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Admin");
         $eventsManager = $di->getShared('eventsManager');
         $eventsManager->attach('dispatch', new AdminSecurity($di));
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     $auto_admin = new \AutoAdmin\Module();
     $auto_admin->registerServices($di);
     $di->setShared('admin_views_dir', function () {
         return ADMINROOT . '/views/';
     });
     $di->setShared('session', function () {
         $session = new Session();
         $session->start();
         return $session;
     });
     $di->setShared('config', function () use($di) {
         $configFront = (require COREROOT . '/app/config/config.php');
         $configBack = (require ADMINROOT . '/config/config.php');
         $configFront->merge($configBack);
         return $configFront;
     });
 }
开发者ID:moaljazaery,项目名称:phalcon-module-admin,代码行数:31,代码来源:module.php

示例3: registerServices

 /**
  * Registration services for specific module
  * @param \Phalcon\DI $di
  * @access public
  * @return mixed
  */
 public function registerServices($di)
 {
     // Dispatch register
     $di->set('dispatcher', function () use($di) {
         $eventsManager = $di->getShared('eventsManager');
         $eventsManager->attach('dispatch:beforeException', new \Plugins\Dispatcher\NotFoundPlugin());
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace('Modules\\' . self::MODULE . '\\Controllers');
         return $dispatcher;
     }, true);
     // Registration of component representations (Views)
     $di->set('view', function () {
         $view = new View();
         $view->setViewsDir($this->_config['application']['viewsBack'])->setMainView('auth-layout')->setPartialsDir('partials');
         return $view;
     });
     require_once APP_PATH . '/Modules/' . self::MODULE . '/config/services.php';
     // call profiler
     if ($this->_config->database->profiler === true) {
         new \Plugins\Debugger\Develop($di);
     }
     if (APPLICATION_ENV == 'development') {
         // share Fabfuel topbar
         $profiler = new \Fabfuel\Prophiler\Profiler();
         $di->setShared('profiler', $profiler);
         $pluginManager = new \Fabfuel\Prophiler\Plugin\Manager\Phalcon($profiler);
         $pluginManager->register();
         // add toolbar in your basic BaseController
     }
     return;
 }
开发者ID:stanislav-web,项目名称:phalcon-development,代码行数:38,代码来源:Module.php

示例4: testProfilersMustBeExecutedBeforeSerialization

 /**
  * @depends testProfilerManagerAttachesDataCollectorsToVariousEvents
  */
 public function testProfilersMustBeExecutedBeforeSerialization()
 {
     $profiler = $this->di->get(ProfilerDataCollector::DI_NAME);
     $eventsManager = $this->di->getShared('eventsManager');
     $profiler->enable($this->getDataCollectors());
     try {
         json_encode($profiler);
         $this->fail();
     } catch (\Exception $e) {
         do {
             $e = $e->getPrevious();
         } while ($e && $e->getPrevious());
         $this->assertInstanceOf('\\Vegas\\Profiler\\Exception\\EventNotTriggeredException', $e);
     }
     $eventsManager->fire('db:beforeQuery', $this->di->getShared('db'));
     $this->di->getShared('db')->execute('SELECT 1');
     $eventsManager->fire('db:afterQuery', $this->di->getShared('db'));
     $eventsManager->fire('dispatch:beforeException', $this->di->getShared('dispatcher'), new \Vegas\Exception());
     $eventsManager->fire('dispatch:afterDispatchLoop', $this->di->getShared('dispatcher'));
     $eventsManager->fire('view:afterRender', $this->di->getShared('view'));
     $result = json_encode($profiler);
     $this->assertJson($result);
 }
开发者ID:vegas-cmf,项目名称:profiler,代码行数:26,代码来源:ManagerTest.php

示例5: getConnection

 /**
  * Return the config object in the services container
  *
  * @return \Phalcon\Mvc\Url
  */
 public static function getConnection()
 {
     return self::$di->getShared('db');
 }
开发者ID:doit76,项目名称:phalcon-devtools,代码行数:9,代码来源:Tools.php

示例6: attachView

 /**
  * @param $view
  *
  * @throws \DebugBar\DebugBarException
  */
 public function attachView($view)
 {
     if (!$this->shouldCollect('view', true) || isset($this->collectors['views'])) {
         return;
     }
     // You can add only One View instance
     if (is_string($view)) {
         $view = $this->di[$view];
     }
     $engins = $view->getRegisteredEngines();
     if (isset($engins['.volt'])) {
         $volt = $engins['.volt'];
         if (is_object($volt)) {
             if ($volt instanceof \Closure) {
                 $volt = $volt($view, $this->di);
             }
         } elseif (is_string($volt)) {
             if (class_exists($volt)) {
                 $volt = new Volt($view, $this->di);
             } elseif ($this->di->has($volt)) {
                 $volt = $this->di->getShared($volt, array($view, $this->di));
             }
         }
         $engins['.volt'] = $volt;
         $view->registerEngines($engins);
         $volt->getCompiler()->addExtension(new VoltFunctions($this->di));
     }
     $viewProfiler = new Registry();
     $viewProfiler->templates = array();
     $viewProfiler->engines = $view->getRegisteredEngines();
     $config = $this->config;
     $eventsManager = $view->getEventsManager();
     if (!is_object($eventsManager)) {
         $eventsManager = new Manager();
     }
     $eventsManager->attach('view:beforeRender', function ($event, $view) use($viewProfiler) {
         $viewProfiler->startRender = microtime(true);
     });
     $eventsManager->attach('view:afterRender', function ($event, $view) use($viewProfiler, $config) {
         $viewProfiler->stopRender = microtime(true);
         if ($config->options->views->get('data', false)) {
             $viewProfiler->params = $view->getParamsToView();
         } else {
             $viewProfiler->params = null;
         }
     });
     $eventsManager->attach('view:beforeRenderView', function ($event, $view) use($viewProfiler) {
         $viewFilePath = $view->getActiveRenderPath();
         if (Version::getId() >= 2000140) {
             if (!$view instanceof \Phalcon\Mvc\ViewInterface && $view instanceof \Phalcon\Mvc\ViewBaseInterface) {
                 $viewFilePath = realpath($view->getViewsDir()) . DIRECTORY_SEPARATOR . $viewFilePath;
             }
         } elseif ($view instanceof Simple) {
             $viewFilePath = realpath($view->getViewsDir()) . DIRECTORY_SEPARATOR . $viewFilePath;
         }
         $templates = $viewProfiler->templates;
         $templates[$viewFilePath]['startTime'] = microtime(true);
         $viewProfiler->templates = $templates;
     });
     $eventsManager->attach('view:afterRenderView', function ($event, $view) use($viewProfiler) {
         $viewFilePath = $view->getActiveRenderPath();
         if (Version::getId() >= 2000140) {
             if (!$view instanceof \Phalcon\Mvc\ViewInterface && $view instanceof \Phalcon\Mvc\ViewBaseInterface) {
                 $viewFilePath = realpath($view->getViewsDir()) . DIRECTORY_SEPARATOR . $viewFilePath;
             }
         } elseif ($view instanceof Simple) {
             $viewFilePath = realpath($view->getViewsDir()) . DIRECTORY_SEPARATOR . $viewFilePath;
         }
         $templates = $viewProfiler->templates;
         $templates[$viewFilePath]['stopTime'] = microtime(true);
         $viewProfiler->templates = $templates;
     });
     $view->setEventsManager($eventsManager);
     $collector = new ViewCollector($viewProfiler, $view);
     $this->addCollector($collector);
 }
开发者ID:snowair,项目名称:phalcon-debugbar,代码行数:81,代码来源:PhalconDebugbar.php


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