當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Application::setDI方法代碼示例

本文整理匯總了PHP中Phalcon\Mvc\Application::setDI方法的典型用法代碼示例。如果您正苦於以下問題:PHP Application::setDI方法的具體用法?PHP Application::setDI怎麽用?PHP Application::setDI使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phalcon\Mvc\Application的用法示例。


在下文中一共展示了Application::setDI方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 /**
  * @param array $config 配置文件
  */
 public function run(array $config)
 {
     $this->di = new FactoryDefault();
     $this->app = new Application();
     if (defined('APP_ENV') && APP_ENV == 'product') {
         $this->debug = false;
         error_reporting(0);
     } else {
         $this->debug = true;
         error_reporting(E_ALL);
     }
     $this->initConfig($config);
     try {
         $this->onBefore();
         $this->initRouters();
         $this->initUrl();
         $this->initView();
         $this->initDatabase();
         $this->initModelsMetadata();
         $this->initCookie();
         $this->initCrypt();
         $this->initLogger();
         $this->onAfter();
         $this->app->setDI($this->di);
         $this->registerModules();
         echo $this->app->handle()->getContent();
     } catch (\Exception $e) {
         echo $e->getMessage();
     }
 }
開發者ID:c78702505,項目名稱:phalcon-phputils,代碼行數:33,代碼來源:Bootstrap.php

示例2: registerApplication

 /**
  * Init application
  *
  * @return Application
  */
 public function registerApplication()
 {
     $this->registerConfig();
     $this->registerServices();
     $this->registerModules();
     $this->application->setDI($this->di);
     return $this->application;
 }
開發者ID:kachit,項目名稱:phalcon-lib,代碼行數:13,代碼來源:AbstractBootstrap.php

示例3: setUp

 /**
  *
  */
 public function setUp()
 {
     $di = new DI();
     $_SERVER['HTTP_HOST'] = 'example.com';
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb';
     $_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb');
     $request = new Request();
     $request->setDI($di);
     $this->request = $request;
     $response = new Response();
     $response->setDI($di);
     $dispatcher = new Dispatcher();
     $dispatcher->setDI($di);
     $this->dispatcher = $dispatcher;
     $cache = new BackendCache(new FrontendCache());
     $di->set('viewCache', $cache);
     $config = new Config(array('cache' => array('enable' => true)));
     $di->set('config', $config);
     $eventsManager = new Manager();
     $di->set('request', $request, true);
     $di->set('response', $response, true);
     $di->set('dispatcher', $dispatcher, true);
     $di->set('eventsManager', $eventsManager);
     $this->di = $di;
     $application = new Application();
     $application->setDI($di);
     $application->setEventsManager($eventsManager);
     $this->application = $application;
 }
開發者ID:hushibing,項目名稱:EvaEngine,代碼行數:33,代碼來源:DispatchTest.php

示例4: setUp

 public function setUp()
 {
     $di = new DI();
     $_SERVER['HTTP_HOST'] = 'example.com';
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb';
     $_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb');
     $request = new Request();
     $request->setDI($di);
     $this->request = $request;
     $response = new Response();
     $response->setDI($di);
     $this->response = $response;
     $eventsManager = new Manager();
     $cors = new Cors(array(array('domain' => 'bar.com')));
     $di->set('request', $request, true);
     $di->set('response', $response, true);
     $di->set('eventsManager', $eventsManager);
     $di->set('cors', $cors);
     $this->di = $di;
     $application = new Application();
     $application->setDI($di);
     $application->setEventsManager($eventsManager);
     $this->application = $application;
 }
開發者ID:evaengine,項目名稱:evaengine,代碼行數:25,代碼來源:CorsTest.php

示例5: run

 /**
  * Runs the application performing all initializations
  *
  * @param $options
  *
  * @return mixed
  */
 public function run($options)
 {
     $loaders = array('session', 'config', 'loader', 'url', 'router', 'view', 'cache', 'markdown');
     foreach ($loaders as $service) {
         $function = 'init' . ucfirst($service);
         $this->{$function}();
     }
     $application = new PhApplication();
     $application->setDI($this->di);
     return $application->handle($_SERVER['REQUEST_URI'])->getContent();
 }
開發者ID:phanbook,項目名稱:portal.phanbook,代碼行數:18,代碼來源:bootstrap.php

示例6: __construct

 /**
  * HMVCApplication Constructor
  *
  * @param Phalcon\DiInterface
  */
 public function __construct(DiInterface $di)
 {
     $loader = new Loader();
     //Application Loader
     $loader->registerDirs(array('../app/controllers/'))->register();
     //Register the view service
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir('../app/views/');
         return $view;
     };
     //Register the app itself as a service
     $di['app'] = $this;
     //Sets the parent Id
     parent::setDI($di);
 }
開發者ID:boiler256,項目名稱:mvc,代碼行數:21,代碼來源:index.php

示例7: run

 /**
  * Runs the application performing all initializations
  *
  * @param $options
  *
  * @return mixed
  */
 public function run($options)
 {
     $loaders = array('session', 'config', 'loader', 'url', 'router', 'view', 'cache');
     foreach ($loaders as $service) {
         $function = 'init' . ucfirst($service);
         $this->{$function}();
     }
     $application = new PhApplication();
     $application->setDI($this->di);
     if (PHP_OS == 'Linux') {
         $uri = $_SERVER['REQUEST_URI'];
     } else {
         $uri = null;
     }
     return $application->handle($uri)->getContent();
 }
開發者ID:zoonman,項目名稱:website,代碼行數:23,代碼來源:bootstrap.php

示例8: run

 /**
  * Runs the application performing all initializations
  *
  * @param $options
  *
  * @return mixed
  */
 public function run($options)
 {
     $loaders = array('config', 'session', 'loader', 'url', 'router', 'database', 'view', 'cache', 'log', 'utils', 'debug');
     try {
         // Handing missing controller errors
         $this->di->set('dispatcher', function () {
             //Create an EventsManager
             $eventsManager = new EventsManager();
             // Attach a listener
             $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
                 // Handle 404 exceptions
                 if ($exception instanceof DispatchException) {
                     $dispatcher->forward(array('controller' => 'index', 'action' => 'internalServerError'));
                     return false;
                 }
                 // Alternative way, controller or action doesn't exist
                 if ($event->getType() == 'beforeException') {
                     switch ($exception->getCode()) {
                         case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                         case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                             $dispatcher->forward(array('controller' => 'index', 'action' => 'internalServerError'));
                             return false;
                     }
                 }
             });
             // Instantiate the Security plugin
             $security = new Security($di);
             // Listen for events produced in the dispatcher using the Security plugin
             $eventsManager->attach('dispatch', $security);
             $dispatcher = new \Phalcon\Mvc\Dispatcher();
             // Bind the EventsManager to the dispatcher
             $dispatcher->setEventsManager($eventsManager);
             return $dispatcher;
         }, true);
         foreach ($loaders as $service) {
             $function = 'init' . ucfirst($service);
             $this->{$function}();
         }
         $application = new PhApplication();
         $application->setDI($this->di);
         return $application->handle()->getContent();
     } catch (PhException $e) {
         echo $e->getMessage();
     } catch (\PDOException $e) {
         echo $e->getMessage();
     }
 }
開發者ID:hacktm15,項目名稱:CityBox,代碼行數:54,代碼來源:bootstrap.php

示例9: run

 /**
  * Runs the application performing all initializations
  *
  * @param $options
  *
  * @return mixed
  */
 public function run($options)
 {
     $loaders = array('session', 'config', 'loader', 'url', 'router', 'view', 'cache');
     try {
         foreach ($loaders as $service) {
             $function = 'init' . ucfirst($service);
             $this->{$function}();
         }
         $application = new PhApplication();
         $application->setDI($this->di);
         return $application->handle()->getContent();
     } catch (PhException $e) {
         echo $e->getMessage();
     } catch (\PDOException $e) {
         echo $e->getMessage();
     }
 }
開發者ID:rajeshmsaaryan01,項目名稱:website,代碼行數:24,代碼來源:bootstrap.php

示例10: run

 /**
  * Runs the application performing all initializations
  * 
  * @param $options
  *
  * @return mixed
  */
 public function run($options)
 {
     $loaders = array('config', 'loader', 'environment', 'timezone', 'debug', 'flash', 'url', 'dispatcher', 'view', 'logger', 'database', 'session', 'cache', 'behaviors');
     try {
         foreach ($loaders as $service) {
             $function = 'init' . ucfirst($service);
             $this->{$function}($options);
         }
         $application = new PhApplication();
         $application->setDI($this->_di);
         return $application->handle()->getContent();
     } catch (PhException $e) {
         echo $e->getMessage();
     } catch (\PDOException $e) {
         echo $e->getMessage();
     }
 }
開發者ID:vnlita,項目名稱:phalcon-angular-harryhogfootball,代碼行數:24,代碼來源:Bootstrap.php

示例11: __construct

 /**
  * Application Constructor
  *
  * @param \Phalcon\DiInterface $di
  */
 public function __construct(DiInterface $di)
 {
     /**
      * Sets the parent DI and register the app itself as a service,
      * necessary for redirecting HMVC requests
      */
     parent::setDI($di);
     $di->set('app', $this);
     /**
      * Register application wide accessible services
      */
     $this->_registerServices();
     /**
      * Register the installed/configured modules
      */
     $this->registerModules(require __DIR__ . '/../../../config/modules.php');
 }
開發者ID:sarahsampan,項目名稱:compare-api,代碼行數:22,代碼來源:Application.php

示例12: initApplication

 protected function initApplication()
 {
     $di = $this->getDI();
     if (!$this->getUserOption('app') instanceof Application) {
         $this->setUserOption('app', new Application());
     }
     $this->app = $this->getUserOption('app');
     $this->app->setDI($di);
     $this->app->setEventsManager($di->get('eventsManager'));
     // disable implicit views if using simple views
     if ($di->has('view') && !$di->get('view') instanceof ViewInterface) {
         $this->app->useImplicitView(false);
     }
     $di->setShared('app', $this->app);
     if (!defined('APP_ENV')) {
         define('APP_ENV', getenv('APP_ENV') ?: static::ENV_PRODUCTION);
     }
 }
開發者ID:logikostech,項目名稱:core,代碼行數:18,代碼來源:Bootstrap.php

示例13: __construct

 /**
  * 構建網站服務入口(Constructor)
  *
  * @param $di
  */
 public function __construct(\Phalcon\DiInterface $di)
 {
     $this->_di = $di;
     $loaders = array('loader', 'config', 'timezone', 'db', 'crypt', 'cache', 'language', 'url', 'router');
     // 注冊各載入服務(Register services)
     try {
         foreach ($loaders as $service) {
             $this->{$service}();
         }
     } catch (\Exception $e) {
         exit('網站模塊注冊出錯!請通知管理員盡快恢複正常運行,謝謝!');
     }
     // 注冊服務模塊(Register modules)
     $this->registerModules(array('home' => array('className' => 'App\\Home\\Module', 'path' => APP_PATH . '/home/Module.php'), 'admin' => array('className' => 'App\\Admin\\Module', 'path' => APP_PATH . '/admin/Module.php'), 'backend' => array('className' => 'App\\Backend\\Module', 'path' => APP_PATH . '/backend/Module.php')));
     // 注冊本類為應用服務(Register the app itself as a service)
     $this->_di->set('app', $this);
     // 調用父類注冊入口(Sets the parent Di)
     parent::setDI($this->_di);
 }
開發者ID:kluas,項目名稱:keyscms,代碼行數:24,代碼來源:Bootstrap.php

示例14: run

 /**
  * Runs the application performing all initializations
  *
  * @param $options
  *
  * @return mixed
  */
 public function run($options)
 {
     $loaders = ['config', 'loader', 'session', 'permission', 'url', 'database', 'logger', 'environment', 'flash', 'flashsession', 'router', 'dispatcher', 'modelsmanager', 'metadata', 'annotations', 'view', 'cache', 'security', 'crypt', 'cookie', 'beanstalkd', 'acl', 'filemanager', 'authentication'];
     foreach ($loaders as $service) {
         $function = 'init' . ucfirst($service);
         $this->{$function}($options);
     }
     $application = new PhApplication();
     $application->setDI($this->di);
     $modules = $this->getModules();
     $application->registerModules($modules);
     $eventsManager = new PhEventsManager();
     $application->setEventsManager($eventsManager);
     $eventsManager->attach('application:beforeHandleRequest', function ($event, $application) {
         $config = $this->di->get('config');
         $response = $this->di->get('response');
         $dispatcher = $this->di->get('dispatcher');
         $cookie = $this->di->get('cookie');
         //Detect mobile device
         $detect = new \Fly\Mobile_Detect();
         if ($config->app_mobile == true && $detect->isMobile() && SUBDOMAIN != 'm' && $dispatcher->getModuleName() == 'common') {
             //begin redirect link to mobile version
             $curPageURL = \Fly\Helper::getCurrentUrl();
             $curPageURL = str_replace(array('http://', 'https://'), array('http://m.', 'https://m.'), $curPageURL);
             $response->redirect($curPageURL, true);
         }
         //Setting language service
         $this->di->setShared('lang', function () use($dispatcher, $cookie) {
             $language = '';
             // Detect language via cookie
             if ($cookie->has('language')) {
                 $language = $cookie->get('language')->getValue();
             } else {
                 //Get default language
                 $language = $this->config->defaultLanguage;
             }
             return new FlyTranslate(['module' => strtolower($dispatcher->getModuleName()), 'controller' => $dispatcher->getControllerName(), 'language' => $language]);
         });
     });
     return $application->handle()->getContent();
 }
開發者ID:aisuhua,項目名稱:phalcon-jumpstart,代碼行數:48,代碼來源:Bootstrap.php

示例15: run

 /**
  * 開始運行
  */
 public function run()
 {
     try {
         $this->onBefore();
         $this->initLoader();
         $this->initRouters();
         $this->initUrl();
         $this->initDatabase();
         $this->initModelsMetadata();
         $this->initCookie();
         $this->initLogger();
         $this->initShortFunc();
         \Phalcon\Mvc\Model::setup(['notNullValidations' => false]);
         $this->onAfter();
         $this->app->setDI($this->di);
         $this->registerModules();
         echo $this->app->handle()->getContent();
     } catch (\Exception $e) {
         echo $e->getMessage();
     }
 }
開發者ID:fu-tao,項目名稱:meelier_c,代碼行數:24,代碼來源:Bootstrap.php


注:本文中的Phalcon\Mvc\Application::setDI方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。