當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。