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


PHP Phalcon\DI类代码示例

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


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

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

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

示例4: setUp

 /**
  * Set up test vars
  *
  * @return void
  * @author Dan Cox
  */
 public function setUp()
 {
     $di = new DI();
     $di->setShared('output', new Output());
     $di->setShared('input', new Input());
     $this->helpers = new Helpers($di);
 }
开发者ID:danzabar,项目名称:phalcon-cli,代码行数:13,代码来源:HelperTest.php

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

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

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

示例8: setUp

 public function setUp()
 {
     parent::setUp();
     $config = DI::getDefault()->get('config');
     require_once $config->application->moduleDir . '/Test/forms/Fake.php';
     $this->prepareFakeObject();
 }
开发者ID:szytko,项目名称:core,代码行数:7,代码来源:CrudTest.php

示例9: __construct

 /**
  * @param DI $di
  */
 public function __construct(DI $di = null)
 {
     if (!class_exists('\\Whoops\\Run')) {
         return;
     }
     if (!$di) {
         $di = DI::getDefault();
     }
     // There's only ever going to be one error page...right?
     $di->setShared('whoops.pretty_page_handler', function () use($di) {
         return (new DebugbarHandler())->setDi($di);
     });
     // There's only ever going to be one error page...right?
     $di->setShared('whoops.json_response_handler', function () {
         $jsonHandler = new JsonResponseHandler();
         $jsonHandler->onlyForAjaxRequests(true);
         return $jsonHandler;
     });
     $di->setShared('whoops', function () use($di) {
         $run = new Run();
         $run->silenceErrorsInPaths(array('/phalcon-debugbar/'), E_ALL);
         $run->pushHandler($di['whoops.pretty_page_handler']);
         $run->pushHandler($di['whoops.json_response_handler']);
         return $run;
     });
     $di['whoops']->register();
 }
开发者ID:minhlaoleu,项目名称:phalcon-debugbar,代码行数:30,代码来源:WhoopsServiceProvider.php

示例10: getTableName

 /**
  * Get table name.
  *
  * @return string
  */
 public static function getTableName()
 {
     $reader = DI::getDefault()->get('annotations');
     $reflector = $reader->get(get_called_class());
     $annotations = $reflector->getClassAnnotations();
     return $annotations->get('Source')->getArgument(0);
 }
开发者ID:biggtfish,项目名称:cms,代码行数:12,代码来源:AbstractModel.php

示例11: __construct

 /**
  * @param array $options
  * @throws \Exception
  */
 public function __construct($options = array())
 {
     if (empty($options)) {
         $options = array('db' => DI::getDefault()->get('mongo'), 'roles' => 'vegas_acl_roles', 'resources' => 'vegas_acl_resources', 'resourcesAccesses' => 'vegas_acl_resources_accesses', 'accessList' => 'vegas_acl_access_list');
     }
     if (!is_array($options)) {
         throw new Exception("Acl options must be an array");
     }
     if (!isset($options['db'])) {
         throw new Exception("Parameter 'db' is required");
     }
     if (!isset($options['roles'])) {
         throw new Exception("Parameter 'roles' is required");
     }
     if (!isset($options['resources'])) {
         throw new Exception("Parameter 'resources' is required");
     }
     if (!isset($options['resourcesAccesses'])) {
         throw new Exception("Parameter 'resourcesAccesses' is required");
     }
     if (!isset($options['accessList'])) {
         throw new Exception("Parameter 'accessList' is required");
     }
     $this->options = $options;
     $this->_defaultAccess = Acl::DENY;
 }
开发者ID:vegas-cmf,项目名称:acl,代码行数:30,代码来源:Mongo.php

示例12: send

 public function send()
 {
     $di = \Phalcon\DI::getDefault();
     $res = $di->get('response');
     $req = $di->get('request');
     //query string, filter, default
     if (!$req->get('suppress_response_codes', null, null)) {
         $res->setStatusCode($this->getCode(), $this->response)->sendHeaders();
     } else {
         $res->setStatusCode('200', 'OK')->sendHeaders();
     }
     $error = array('errorCode' => $this->getCode(), 'userMessage' => $this->getMessage(), 'devMessage' => $this->devMessage, 'more' => $this->additionalInfo, 'applicationCode' => $this->errorCode);
     if (!$req->get('type') || $req->get('type') == 'json' | $req->get('type') == 'option') {
         $response = new JSONResponse();
         $response->send($error, true);
         return;
     } else {
         if ($req->get('type') == 'xml') {
             $response = new XMLResponse();
             $response->send($error, true);
             return;
         } else {
             if ($req->get('type') == 'csv') {
                 $response = new CSVResponse();
                 $response->send(array($error));
                 return;
             }
         }
     }
     error_log('HTTPException: ' . $this->getFile() . ' at ' . $this->getLine());
     return true;
 }
开发者ID:sarahsampan,项目名称:compare-api,代码行数:32,代码来源:HTTPException.php

示例13: __construct

 /**
  * Create regex validator.
  *
  * @param array $params Validator parameters.
  */
 public function __construct($params = [])
 {
     if (isset($params['message'])) {
         $params['message'] = DI::getDefault()->get('i18n')->_($params['message']);
     }
     parent::__construct($params);
 }
开发者ID:biggtfish,项目名称:cms,代码行数:12,代码来源:Regex.php

示例14: testSerialization

 public function testSerialization()
 {
     $router = \Phalcon\DI::getDefault()->getShared('router');
     $serialized = serialize($router);
     $unserialized = unserialize($serialized);
     $this->assertEquals($unserialized, $router);
 }
开发者ID:ovide,项目名称:phest,代码行数:7,代码来源:RouterTest.php

示例15: getDi

 /**
  * Get DI
  *
  * @return DI
  */
 public function getDi()
 {
     if (empty($this->di)) {
         $this->di = DI::getDefault();
     }
     return $this->di;
 }
开发者ID:kachit,项目名称:phalcon-lib,代码行数:12,代码来源:InjectableTrait.php


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