本文整理汇总了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);
}
}
示例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);
}
}
示例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());
}
示例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);
}
示例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;
}
}
示例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]);
}
}
示例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);
}
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例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]);
}
示例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;
}
示例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);
}
示例15: getView
/**
* @param Dispatcher $dispatcher
*
* @return View
*/
public function getView(Dispatcher $dispatcher)
{
return $dispatcher->getDI()->getShared('view');
}