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


PHP Dispatcher::getDI方法代码示例

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


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

示例1: afterExecuteRoute

 public function afterExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher)
 {
     $view = $dispatcher->getDI()->getService('view')->resolve();
     $viewHelper = $dispatcher->getDI()->get(ViewHelper::SERVICE_NAME);
     if ($viewHelper) {
         $view->setVar('helper', $viewHelper);
     }
 }
开发者ID:sb15,项目名称:phalcon-ext,代码行数:8,代码来源:ViewHelperPlugin.php

示例2: beforeDispatchLoop

 /**
  * @param Event         $event
  * @param MvcDispatcher $dispatcher
  */
 public function beforeDispatchLoop(Event $event, MvcDispatcher $dispatcher)
 {
     if (!$dispatcher->getDI()->has('request')) {
         return;
     }
     /** @var \Phalcon\Http\Request $request */
     $request = $dispatcher->getDI()->get('request');
     if ($request->isAjax()) {
         /** @var MvcView $view */
         $view = $dispatcher->getDI()->get('view');
         $view->setRenderLevel(MvcView::LEVEL_ACTION_VIEW);
     }
 }
开发者ID:mamuz,项目名称:phalcon-application,代码行数:17,代码来源:View.php

示例3: beforeExecuteRoute

 public function beforeExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher)
 {
     /** @var \Phalcon\Http\Request $request */
     $request = $dispatcher->getDI()->getService('request')->resolve();
     if ($dispatcher->getParam('lang')) {
         $lang = $dispatcher->getParam('lang');
     } else {
         $lang = $request->getBestLanguage();
     }
     $view = $dispatcher->getDI()->getService('view')->resolve();
     $translationHelper = $dispatcher->getDI()->get(\Sb\Phalcon\Helpers\TranslationHelper::SERVICE_NAME);
     $translationHelper->setLang($lang);
     $view->setVar('t', $translationHelper->getTranslation());
 }
开发者ID:sb15,项目名称:phalcon-ext,代码行数:14,代码来源:TranslationPlugin.php

示例4: beforeDispatchLoop

 /**
  * beforeDispatchLoop
  *
  * @param  Event                           $event
  * @param  Dispatcher                      $dispatcher
  * @return \Phalcon\Http\ResponseInterface
  */
 public function beforeDispatchLoop(Event $event, Dispatcher $dispatcher)
 {
     if ($this->auth->hasRememberMe()) {
         $this->auth->loginWithRememberMe(false);
     }
     if ($this->auth->isUserSignedIn()) {
         $actionName = $dispatcher->getActionName();
         $controllerName = $dispatcher->getControllerName();
         if ($controllerName == 'user' && $actionName == 'login') {
             return $this->response->redirect($config->pup->redirect->success);
         }
     }
     $config = $dispatcher->getDI()->get('config');
     $pupConfig = $this->getConfigStructure($config);
     $needsIdentity = $this->needsIdentity($pupConfig, $dispatcher);
     $identity = $this->auth->getIdentity();
     if (true === $needsIdentity) {
         if (!is_array($identity)) {
             $this->flash->notice('Private area. Please login.');
             $this->view->disable();
             return $this->response->redirect($config->pup->redirect->failure)->send();
         }
     }
     $this->view->setVar('identity', $identity);
 }
开发者ID:hinjanobara,项目名称:mbimages,代码行数:32,代码来源:Security.php

示例5: beforeExecuteRoute

 /**
  *  Executes before executing any route.
  *  Handles sign up policy. Blocks page if open sign up disabled by configuration.
  *  @param \Phalcon\Mvc\Dispatcher $dispatcher Phalcon application dispatcher instance
  *  @return void
  */
 public function beforeExecuteRoute($dispatcher)
 {
     $di = $dispatcher->getDI();
     $config = $di->get('config');
     if ($dispatcher->getActionName() == "signup" && !$config->information->openSignUp) {
         return false;
     }
 }
开发者ID:netassist-ua,项目名称:netgraphz2-gpl,代码行数:14,代码来源:AccountController.php

示例6: afterExecuteRoute

 public function afterExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher)
 {
     /** @var \Phalcon\Mvc\Router $route */
     $route = $dispatcher->getDI()->get('router');
     $view = $dispatcher->getDI()->getService('view')->resolve();
     $wasForwarded = $dispatcher->wasForwarded();
     if ($wasForwarded) {
         return;
     }
     if ($route->getMatchedRoute()) {
         $paths = $route->getMatchedRoute()->getPaths();
         $controller = $paths['controller'];
         $action = \Phalcon\Text::uncamelize($paths['action']);
         $action = str_replace("_", "-", $action);
         $template = $controller . '/' . $action;
         $view->pick([$template]);
     }
 }
开发者ID:sb15,项目名称:phalcon-ext,代码行数:18,代码来源:ViewTemplateName.php

示例7: afterExecuteRoute

 public function afterExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher)
 {
     $view = $dispatcher->getDI()->getService('view')->resolve();
     $controllerData = $event->getData();
     if (is_array($controllerData)) {
         foreach ($controllerData as $key => $value) {
             $view->setVar($key, $value);
         }
     }
 }
开发者ID:sb15,项目名称:legacy-library,代码行数:10,代码来源:ViewReturnPlugin.php

示例8: action

 /**
  * 校验拦截器,用以传入参数的校验。
  * @param \Phalcon\Events\Event $event
  * @param \Phalcon\Mvc\Dispatcher $dispatcher
  * @param array $params
  * @return mixed
  */
 public function action($event, $dispatcher, $params)
 {
     //$module = $dispatcher->getModuleName();
     //$controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     if ($action == 'auth') {
         return;
     }
     $auth = $dispatcher->getDI()->get(AppConstant::DI_SERVICE_SESSION)->get(AppConstant::HTTP_USER_AUTH);
     if (!$auth) {
         ResponseApi::sendErrorAndEnd(null, Message::$_ERROR_UNLOGIN);
     }
 }
开发者ID:huxiaohe,项目名称:api-framework,代码行数:20,代码来源:LoginInterceptor.php

示例9: createMvcFrom

 /**
  * @param array $config
  * @return MvcDispatcher
  */
 public static function createMvcFrom(array $config) : MvcDispatcher
 {
     $dispatcher = new MvcDispatcher();
     $dispatcher->setEventsManager(new EventManager());
     $dispatcher->setControllerSuffix(null);
     $dispatcher->setDefaultNamespace($config['controllerDefaultNamespace']);
     $dispatcher->getEventsManager()->attach('dispatch:afterDispatchLoop', function (Event $event, MvcDispatcher $dispatcher) {
         if ($dispatcher->getReturnedValue() instanceof \Phalcon\Http\Response) {
             $dispatcher->getDI()->setShared('response', $dispatcher->getReturnedValue());
         }
     });
     return $dispatcher;
 }
开发者ID:mamuz,项目名称:phalcon-application,代码行数:17,代码来源:Dispatcher.php

示例10: afterExecuteRoute

 public function afterExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher)
 {
     /** @var \Model\ModelsRepository $modelsRepository */
     $modelsRepository = $dispatcher->getDI()->getService('modelsRepository')->resolve();
     if (!$modelsRepository) {
         return;
     }
     $returnedValue = $dispatcher->getReturnedValue();
     if (is_null($returnedValue)) {
         $returnedValue = [];
     }
     $modelsRepository->getPageContent()->processContent($dispatcher->getParams(), $returnedValue);
 }
开发者ID:sb15,项目名称:phalcon-ext,代码行数:13,代码来源:PageContentPlugin.php

示例11: afterExecuteRoute

 public function afterExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher)
 {
     /** @var \Phalcon\Mvc\View $view */
     $view = $dispatcher->getDI()->getService('view')->resolve();
     $returnedValue = $dispatcher->getReturnedValue();
     if ($returnedValue instanceof \Phalcon\Http\Response) {
         return false;
     }
     if (is_array($view->getParamsToView()) && array_key_exists(self::SET_JSON_RESPONSE, $view->getParamsToView())) {
         $view->disable();
         header('Content-type: application/json');
         echo json_encode($returnedValue);
         return false;
     }
     if (is_array($returnedValue)) {
         $view->setVars($returnedValue);
     }
 }
开发者ID:sb15,项目名称:phalcon-ext,代码行数:18,代码来源:ViewReturnPlugin.php

示例12: __construct

 public function __construct(Dispatcher $dispatcher, array $modules, $defaultLanguage = 'en')
 {
     $this->lang = $dispatcher->getParam('language');
     if (is_null($this->lang)) {
         $this->lang = $defaultLanguage;
     }
     $config = $dispatcher->getDI()->get('config');
     $translations = $this->getMessages($config->projectPath . 'common/');
     if (!is_array($translations)) {
         $translations = [];
     }
     $translationsModule = $this->getMessages($modules[$dispatcher->getModuleName()]);
     if (!is_array($translationsModule)) {
         $translationsModule = [];
     }
     $translations = array_merge($translations, $translationsModule);
     $this->translate = new NativeArray(['content' => $translations]);
 }
开发者ID:mirobrando,项目名称:ng-phalcon,代码行数:18,代码来源:Translation.php

示例13: beforeExecuteRoute

 /**
  * @param \Phalcon\Mvc\Dispatcher|\Phalcon\Mvc\DispatcherInterface $dispatcher
  * @return bool
  */
 public function beforeExecuteRoute($dispatcher)
 {
     $this->operator = new OperatorIdentity();
     $this->operator->cookies = $this->cookies;
     $this->operator->load();
     // 判断登录
     $moduleConfig = $this->di->get('moduleConfig');
     $controllerName = $dispatcher->getControllerName();
     $actionName = $dispatcher->getActionName();
     if ($controllerName == $moduleConfig->operator->login->controller && $actionName == $moduleConfig->operator->login->action) {
         return true;
     }
     if ($this->operator->isLogin()) {
         // 判断权限
         $result = OperatorGroupRight::verify($this->operator->group, $controllerName, $actionName, $dispatcher->getDI());
         // 权限不足,输出错误
         if (!$result) {
             $content = '';
             if ($this->request->isAjax()) {
                 $resp = new ResponseResult();
                 $resp->sendError(ResponseResultStatus::RIGHT_VERIFY_FAIL, '权限不足!');
                 $content = $resp->getContent();
             } else {
                 $content = '访问权限不足!';
             }
             $this->view->disable();
             echo $content;
         }
         return $result;
     }
     if ($this->request->isAjax()) {
         $resp = new ResponseResult();
         $resp->sendError(ResponseResultStatus::USER_TOKEN_EXPIRES, '未登录!');
         echo $resp->getContent();
     } else {
         $this->response->redirect($moduleConfig->operator->login->url);
     }
     $this->view->disable();
     return false;
 }
开发者ID:fu-tao,项目名称:meelier_c,代码行数:44,代码来源:BaseController.php

示例14: testModelBinding

 public function testModelBinding(IntegrationTester $I)
 {
     $dispatcher = new Dispatcher();
     $dispatcher->setModelBinding(true);
     $dispatcher->setDI(Di::getDefault());
     $I->assertInstanceOf('Phalcon\\Di', $dispatcher->getDI());
     $I->haveServiceInDi('dispatcher', $dispatcher);
     // Model to test with
     $model = People::findFirst();
     $dispatcher->setControllerName('test10');
     $dispatcher->setActionName('view');
     $dispatcher->setParams([$model->cedula]);
     $dispatcher->dispatch();
     $I->assertInstanceOf('Phalcon\\Test\\Models\\People', $dispatcher->getReturnedValue());
     $I->assertEquals($model->cedula, $dispatcher->getReturnedValue()->cedula);
     // Reset dispatcher
     $dispatcher = new Dispatcher();
     $dispatcher->setDI(Di::getDefault());
     $I->assertInstanceOf('Phalcon\\Di', $dispatcher->getDI());
     $I->haveServiceInDi('dispatcher', $dispatcher);
     $dispatcher->setControllerName('test9');
     $dispatcher->setActionName('view');
     $dispatcher->setParams([$model->cedula]);
     try {
         $dispatcher->dispatch();
         $I->assertTrue(false, 'Here must be the exception about passing non model to the controller action');
     } catch (\Exception $e) {
         // PHP 5.x
         $I->assertEquals('Argument 1 passed to Test9Controller::viewAction() must be an instance of Phalcon\\Mvc\\Model, string given', $e->getMessage());
     } catch (\TypeError $e) {
         // PHP 7.x
         $I->assertEquals('Argument 1 passed to Test9Controller::viewAction() must be an instance of Phalcon\\Mvc\\Model, string given', $e->getMessage());
     }
     $dispatcher->setModelBinding(true);
     $dispatcher->dispatch();
     $I->assertInstanceOf('Phalcon\\Test\\Models\\People', $dispatcher->getReturnedValue());
     $I->assertEquals($dispatcher->getReturnedValue()->cedula, $model->cedula);
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:38,代码来源:ControllersCest.php

示例15: getView

 /**
  * @param Dispatcher $dispatcher
  *
  * @return View
  */
 public function getView(Dispatcher $dispatcher)
 {
     return $dispatcher->getDI()->getShared('view');
 }
开发者ID:TheCodemasterZz,项目名称:PhalconUserPlugin,代码行数:9,代码来源:Security.php


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