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


PHP DI::set方法代码示例

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


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

示例1: set

 /**
  * Registers a service in the services container
  *
  * @param  string  $name
  * @param  mixed   $definition
  * @param  boolean $shared
  * @throws RuntimeException
  * @return \Phalcon\DI\ServiceInterface
  */
 public static function set($name, $definition, $shared = null)
 {
     if (self::$di == null) {
         throw new RuntimeException('IoC container is null!');
     }
     self::$di->set($name, $definition, $shared);
 }
开发者ID:hushibing,项目名称:EvaEngine,代码行数:16,代码来源:IoC.php

示例2: 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

示例3: testProfilerInitialization

 public function testProfilerInitialization()
 {
     $this->di->set(ProfilerDataCollector::DI_NAME, function () {
         return (new ProfilerManager())->setEventsManager($this->di->getShared('eventsManager'));
     }, true);
     $manager = $this->di->get(ProfilerDataCollector::DI_NAME);
     $this->assertInstanceOf('\\Vegas\\Profiler\\Manager', $manager);
 }
开发者ID:vegas-cmf,项目名称:profiler,代码行数:8,代码来源:ManagerTest.php

示例4: create

 /**
  * @return DummyLatteTemplateAdapter
  */
 public static function create()
 {
     $view = new PhView();
     $di = new PhDi();
     $di->set('tag', new PhTag());
     $di->set('security', new PhSecurity());
     $di->set('url', new PhUrl());
     $latteFactory = new LatteFactory();
     $latteFactory->setTempDir(TEMP_DIR);
     $adapter = new DummyLatteTemplateAdapter($view, $di, $latteFactory);
     return $adapter;
 }
开发者ID:phalette,项目名称:platte,代码行数:15,代码来源:LatteTemplateAdapterFactory.php

示例5: register

 /**
  * @param string $moduleName
  * @param string $modulePath
  */
 public function register($moduleName, $modulePath)
 {
     $pPath = $this->dependencyInjection->get('config')->projectPath;
     $pDir = substr($pPath, 0, strlen($pPath) - 10);
     $relModulePath = substr($modulePath, strlen($pDir));
     $x = implode('/', array_map(function () {
         return '..';
     }, explode('/', str_replace('//', '/', $relModulePath))));
     $this->view->setMainView('/../' . $x . '/common/views/index');
     $this->view->setPartialsDir('/../' . $x . '/common/views/partial/');
     $this->view->setViewsDir($modulePath . '/views/');
     $this->registerEngine();
     $this->dependencyInjection->set('view', $this->view);
 }
开发者ID:mirobrando,项目名称:ng-phalcon,代码行数:18,代码来源:RegisterView.php

示例6: attachCache

 public function attachCache($cacheService)
 {
     static $mode, $collector, $hasAttachd = array();
     if (in_array($cacheService, $hasAttachd)) {
         return;
     }
     $hasAttachd[] = $cacheService;
     if (!$this->shouldCollect('cache', false)) {
         return;
     }
     if (!is_string($cacheService)) {
         throw new \Exception('The parameter must be a cache service name.');
     }
     if (!$mode) {
         $mode = $this->config->options->cache->get('mode', 0);
     }
     if (!$collector) {
         $mc = null;
         if ($this->hasCollector('messages')) {
             $mc = $this->getCollector('messages');
         }
         $collector = new CacheCollector($mode, $mc);
         $this->addCollector($collector);
     }
     $backend = $this->di->get($cacheService);
     if ($backend instanceof Multiple || $backend instanceof Backend) {
         if ($this->shouldCollect('cache', false)) {
             $this->di->remove($cacheService);
             $self = $this;
             $this->di->set($cacheService, function () use($self, $backend, $collector) {
                 return $self->createProxy(clone $backend, $collector);
             });
         }
     }
 }
开发者ID:snowair,项目名称:phalcon-debugbar,代码行数:35,代码来源:PhalconDebugbar.php

示例7: _getDI

 protected function _getDI()
 {
     DI::reset();
     $di = new DI();
     $di->set('modelsManager', function () {
         return new Manager();
     });
     $di->set('modelsMetadata', function () {
         return new Memory();
     });
     $di->set('db', function () {
         require PATH_CONFIG . 'config.db.php';
         return new Mysql($configMysql);
     });
     return $di;
 }
开发者ID:lisong,项目名称:cphalcon,代码行数:16,代码来源:UnitTest.php

示例8: getFlash

 /**
  * Return flash instance
  */
 protected function getFlash()
 {
     $flash = new PhFlash($this->classes);
     $di = new PhDI();
     $di->set('session', new Helper\InMemorySession(), true);
     $flash->setDI($di);
     return $flash;
 }
开发者ID:acwtools,项目名称:cphalcon,代码行数:11,代码来源:FlashSessionDefaultTest.php

示例9: getDi

 private function getDi()
 {
     $di = new PhalconDi();
     $di->set('request', function () {
         return new PhalconRequest();
     });
     return $di;
 }
开发者ID:tmquang6805,项目名称:phalex,代码行数:8,代码来源:RouterTest.php

示例10: setUpBeforeClassAndDataProviders

 public static function setUpBeforeClassAndDataProviders()
 {
     self::$previousDependencyInjector = DI::getDefault();
     $di = new DI();
     $di->set('modelsMetadata', function () {
         return new MemoryMetadata();
     }, true);
     $di->set('modelsManager', function () {
         return new ModelsManager();
     }, true);
     $di->set('db', function () {
         return new MysqlAdapter(array('host' => 'localhost', 'port' => '3306', 'username' => 'root', 'password' => '', 'dbname' => 'incubator_tests', 'charset' => 'utf8mb4'));
     }, true);
     if (self::$previousDependencyInjector instanceof DI) {
         DI::setDefault($di);
     }
     spl_autoload_register(array(__CLASS__, 'autoloadModels'), true, true);
 }
开发者ID:nejtr0n,项目名称:incubator,代码行数:18,代码来源:EagerLoadingTest.php

示例11: getRequestObject

 /**
  * Initializes the request object and returns it
  *
  * @author Nikolaos Dimopoulos <nikos@phalconphp.com>
  * @since  2014-10-05
  *
  * @return PhRequest
  */
 protected function getRequestObject()
 {
     PhDI::reset();
     $di = new PhDI();
     $di->set('filter', function () {
         return new PhTFilter();
     });
     $request = new PhTRequest();
     $request->setDI($di);
     return $request;
 }
开发者ID:lisong,项目名称:cphalcon,代码行数:19,代码来源:HttpBase.php

示例12: setUp

 /**
  * Initialize testing object
  *
  * @uses Auth
  * @uses \ReflectionClass
  */
 public function setUp()
 {
     $this->di = new FactoryDefault();
     $this->di->reset();
     // Setup DI
     $this->di = new DI();
     $this->di->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $this->di->set('tag', function () {
         $tag = new \Phalcon\Tag();
         return $tag;
     });
     $this->di->set('escaper', function () {
         $escaper = new \Phalcon\Escaper();
         return $escaper;
     });
     DI::setDefault($this->di);
     $this->reflection = new \ReflectionClass('ULogin\\Auth');
     $this->auth = new Auth();
 }
开发者ID:stanislav-web,项目名称:phalcon-ulogin,代码行数:29,代码来源:AuthTest.php

示例13: registerServices

 /**
  * @param DI $di
  */
 public function registerServices($di)
 {
     $this->registerAutoloaders();
     $di->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $di->set('view', function () use($di) {
         $view = new View();
         $view->setViewsDir(MINI_ADMIN_ROOT . '/views/');
         return $view;
     });
 }
开发者ID:moaljazaery,项目名称:phalcon-module-admin,代码行数:17,代码来源:module.php

示例14: setUp

 /**
  * Sets the test up by loading the DI container and other stuff
  *
  * @author Nikos Dimopoulos <nikos@phalconphp.com>
  * @since  2012-09-30
  *
  * @param \Phalcon\DiInterface $di
  * @param \Phalcon\Config $config
  * @return DI
  */
 protected function setUp(DiInterface $di = null, Config $config = null)
 {
     $this->checkExtension('phalcon');
     if (!is_null($config)) {
         $this->config = $config;
     }
     if (is_null($di)) {
         // Reset the DI container
         DI::reset();
         // Instantiate a new DI container
         $di = new DI();
         // Set the URL
         $di->set('url', function () {
             $url = new Url();
             $url->setBaseUri('/');
             return $url;
         });
         $di->set('escaper', function () {
             return new \Phalcon\Escaper();
         });
     }
     $this->di = $di;
 }
开发者ID:sneakybobito,项目名称:incubator,代码行数:33,代码来源:UnitTestCase.php

示例15: registerServices

 /**
  * This methods registers the services to be used by the application
  */
 protected function registerServices()
 {
     $di = new DI();
     //Registering a router
     $di->set('router', function () {
         return new Router();
     });
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Single\\Controllers\\');
         return $dispatcher;
     });
     //Registering a Http\Response
     $di->set('response', function () {
         return new Response();
     });
     //Registering a Http\Request
     $di->set('request', function () {
         return new Request();
     });
     //Registering the view component
     $di->set('view', function () {
         $view = new View();
         $view->setViewsDir('../apps/views/');
         return $view;
     });
     $di->set('db', function () {
         return new Database(array("host" => "localhost", "username" => "root", "password" => "", "dbname" => "invo"));
     });
     //Registering the Models-Metadata
     $di->set('modelsMetadata', function () {
         return new MemoryMetaData();
     });
     //Registering the Models Manager
     $di->set('modelsManager', function () {
         return new ModelsManager();
     });
     $this->setDI($di);
 }
开发者ID:boiler256,项目名称:mvc,代码行数:43,代码来源:index.php


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