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


PHP Dispatcher::getNamespaceName方法代码示例

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


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

示例1: beforeDispatch

 /**
  * This action is executed before execute any action in the application
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     // Ignore all this if the user is logging out
     $sModuleName = strtolower(explode('\\', $dispatcher->getNamespaceName())[0]);
     if ($this->dispatcher->getActionName() == 'logout' && $this->dispatcher->getControllerName() == 'users' && $sModuleName == 'frontend' || $sModuleName == 'raw') {
         return null;
     }
     // Otherwise proceed with various whatnots and security checks
     /** @var Users $oLoggedInUser */
     $oLoggedInUser = false;
     $oRs = new \RememberedSessions();
     $sUsername = $oRs->getValidPersistentSession();
     if ($sUsername) {
         $oLoggedInUser = Users::findFirst(array('username = :un:', 'bind' => array('un' => $sUsername)));
         $sUserHash = $oLoggedInUser->getLoginSessionHash();
         $aSessionData = array('userhash' => $sUserHash, 'full_name' => $oLoggedInUser->getFullName());
         $this->session->set('auth', $aSessionData);
     } else {
         $auth = $this->session->get('auth');
         if ($auth && isset($auth['userhash'])) {
             $oLoggedInUser = Users::findFirst(array('MD5(CONCAT(password, username, "' . Users::HASH_SALT . '")) = :userhash:', 'bind' => array('userhash' => $auth['userhash'])));
         }
     }
     /** @var Users $oLoggedInUser */
     if ($oLoggedInUser) {
         Users::setCurrent($oLoggedInUser);
     }
     $sModuleName = strtolower(explode('\\', $dispatcher->getNamespaceName())[0]);
     if ($sModuleName != 'frontend' && !$oLoggedInUser) {
         if ($this->getDI()->get('request')->isAjax()) {
             die(json_encode(array('status' => 'error', 'message' => 'Insufficient permissions')));
         } else {
             $this->getDI()->get('response')->redirect('/users/login', true);
             return false;
         }
     }
     $acl = array('frontend' => '*', 'content' => array('admin', 'data_entry'), 'admin' => 'admin');
     $aUserRoleSlugs = array();
     if ($sModuleName != 'frontend') {
         /** @var \UsersRoles $oUR */
         foreach (Users::getCurrent()->usersRoles as $oUR) {
             $aUserRoleSlugs[] = $oUR->getRoleSlug();
             $aUserRoleSlugs = array_unique($aUserRoleSlugs);
         }
     }
     if (isset($acl[$sModuleName]) && $acl[$sModuleName] != '*') {
         $aPermissions = (array) $acl[$sModuleName];
         if (array_intersect($aUserRoleSlugs, $aPermissions) == array()) {
             throw new \Exception('You do not have sufficient permissions to access this part of the website.');
         }
     }
     return true;
 }
开发者ID:kp-favorite,项目名称:bitfalls_utils,代码行数:56,代码来源:Security.php

示例2: beforeExecuteRoute

 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $actionName = $dispatcher->getActionName();
     $controllerName = $dispatcher->getControllerName() . 'Controller';
     $nameSpaceName = $dispatcher->getNamespaceName();
     $className = $nameSpaceName . '\\' . ucwords($controllerName);
     $no_auth_array = [];
     if (class_exists($className)) {
         $no_auth_array = array_merge($className::$no_auth_array, self::$no_auth_array);
     }
     if (in_array($actionName, $no_auth_array)) {
         return true;
     }
     if ($this->isLogin()) {
         //判断是否有权限操作此资源
         if (!$this->isAllowed($actionName)) {
             //echo '没有权限';
             $dispatcher->forward(array('controller' => 'index', 'action' => 'noauth'));
             //die();
             return false;
         }
         return true;
     } else {
         if (!($host = $this->request->getServerName())) {
             $host = $this->request->getHttpHost();
         }
         $sourceUrl = $this->request->getScheme() . '://' . $host . $this->request->getURI();
         $url = $this->request->getScheme() . '://' . $host . self::USER_LOGIN_URL . '?ref=' . $sourceUrl;
         $this->redirect($url);
     }
 }
开发者ID:abc2001x,项目名称:phalcon_mode,代码行数:31,代码来源:AdminAuthController.php

示例3: beforeExecuteRoute

 /**
  * @param Event         $event
  * @param MvcDispatcher $dispatcher
  */
 public function beforeExecuteRoute(Event $event, MvcDispatcher $dispatcher)
 {
     if ($dispatcher->getNamespaceName() !== $dispatcher->getDefaultNamespace()) {
         /** @var MvcView $view */
         $view = $dispatcher->getDI()->get('view');
         if ($view->isDisabled()) {
             return;
         }
         $viewPathParts = array_values(array_diff(explode('\\', strtolower($dispatcher->getHandlerClass())), explode('\\', strtolower($dispatcher->getDefaultNamespace()))));
         $viewPathParts[] = $dispatcher->getActionName();
         $view->setLayout($viewPathParts[0]);
         $view->pick(implode(DIRECTORY_SEPARATOR, $viewPathParts));
     }
 }
开发者ID:mamuz,项目名称:phalcon-application,代码行数:18,代码来源:View.php

示例4: load

 public function load()
 {
     $strContext = __CLASS__ . '->' . __FUNCTION__ . ': ';
     $oLogger = $this->_di->getFileLogger();
     $oDispatcher = $this->_di->getDispatcher();
     $arParams = $oDispatcher->getParams();
     if ($strPath = $this->pathFinder($arParams['media'], $arParams['major'], $arParams['minor'])) {
         $oLogger->debug($strContext . ' got path: ' . $strPath);
         $oLoader = $this->_di->getLoader();
         $oLogger->debug(Tester::ec("'" . $this->dispatcher->getNamespaceName() . "'", true));
         $arRequiredNamespace = array($this->dispatcher->getNamespaceName() => $strPath);
         $oLoader->registerNamespaces($arRequiredNamespace, true);
         $oLogger->debug($strContext . ' registered namespace: ' . print_r($arRequiredNamespace, true));
         $arNewNamespaces = $oLoader->getNamespaces();
         $oLogger->debug($strContext . ' complete namespaces list is:  ' . print_r($arNewNamespaces, true));
     } else {
         $oLogger->debug($strContext . ' got no path: "' . $strPath . '"');
     }
     //		$oDispatcher->get
     //		$this->setExistingRoutes();
     //
     //		$oLogger->debug(__CLASS__ . ': routes are: ' . print_r($this->routes, true));
     //
     //		$oRouter = $this->_di->getRouter();
     //
     ////		$oRouter->handle($oRouter->getRewriteUri());
     //
     //		$boolMatched = $oRouter->wasMatched();
     //
     //		$strMatched = $boolMatched ? 'matched' : 'mismatched';
     //
     //		$oLogger->debug(__CLASS__ . ': route: ' . $strMatched);
     ////		$oRouter->get
     //
     //		$oLogger->debug(__CLASS__ . ': route matched for "' . $oRouter->getRewriteUri() . '"  is: ' . $oRouter->getMatchedRoute()->getPattern());
     $oLogger->debug(__CLASS__ . ': trying to dispatch:' . ' module: ' . $oDispatcher->getModuleName() . ' media: ' . $arParams['media'] . ' version: v' . $arParams['major'] . '_' . $arParams['minor'] . ' controller: ' . $oDispatcher->getControllerName() . ' controller class: ' . $oDispatcher->getControllerClass() . ' action: ' . $oDispatcher->getActionName() . ' active method: ' . $oDispatcher->getActiveMethod());
 }
开发者ID:rcmonitor,项目名称:abboom_phalcon_code_example,代码行数:37,代码来源:VersionLoader.php

示例5: beforeDispatch

 /**
  * This action is executed before execute any action in the application
  *
  * @param Event $event
  * @param Dispatcher $dispatcher
  * @return bool
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     $auth = $this->session->get('auth');
     if (!$auth) {
         $role = 'Guests';
     } else {
         $role = 'Users';
     }
     $namespace = $dispatcher->getNamespaceName();
     $controller = $dispatcher->getControllerName();
     $path = $namespace . '\\' . $controller;
     $action = $dispatcher->getActionName();
     $acl = $this->getAcl();
     $allowed = $acl->isAllowed($role, $path, $action);
     if ($allowed != Acl::ALLOW) {
         $dispatcher->forward(array('namespace' => 'App\\Controllers', 'controller' => 'errors', 'action' => 'show401'));
         $this->session->destroy();
         return false;
     }
 }
开发者ID:kenikori,项目名称:phalcon2_invo,代码行数:27,代码来源:SecurityPlugin.php

示例6: beforeDispatch

 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     $role = 'Guests';
     // If the user is not logged in set his/her role to guest, otherwise get group name
     if ($this->session->get('auth')) {
         $role = Groups::findFirstByGroupId($this->session->get('auth')['group_id'])->name;
     }
     // Get namespace of the controller we're trying to access
     $namespace = $dispatcher->getNamespaceName();
     // Get all ACL rules for this namespace
     $acl = $this->getAcl($namespace);
     // Get the controller we're trying to access
     $controller = $dispatcher->getControllerName();
     // Get the action we are trying to access
     $action = $dispatcher->getActionName();
     // Check if user is allowed to use this action
     $allowed = $acl->isAllowed($role, $controller, $action);
     // If not return a 401 error
     if ($allowed != Acl::ALLOW) {
         $dispatcher->forward(array('namespace' => 'Controllers\\BaseControllers', 'controller' => 'error', 'action' => 'send403'));
     }
     // In all other situations return true
     return true;
 }
开发者ID:Archcry,项目名称:PhalconApiBase,代码行数:24,代码来源:SecurityPlugin.php

示例7: checkPermission

 private function checkPermission(Event $event, Dispatcher $dispatcher)
 {
     $namespaceName = $dispatcher->getNamespaceName();
     if ($namespaceName != 'MyApp\\Controllers') {
         $prefix = strtolower(substr($namespaceName, strrpos($namespaceName, '\\') + 1));
         $controller = $prefix . '/' . $dispatcher->getControllerName();
     } else {
         $controller = $dispatcher->getControllerName();
     }
     $action = $dispatcher->getActionName();
     // 不检查public 与 api/sso控制器, 防止forward后二次检查
     if (in_array($controller, ['public', 'api/sso'])) {
         return true;
     }
     $acl = $this->getAcl($dispatcher);
     $user_id = $this->session->get('user_id');
     if (!isset($user_id)) {
         $role = 'Guests';
     } else {
         $role = 'Users';
     }
     // 无权限
     if ($acl->isResource($controller) != $acl->isAllowed($role, $controller, $action)) {
         $dispatcher->forward(['namespace' => 'MyApp\\Controllers', 'controller' => 'public', 'action' => 'show401']);
         return false;
     }
 }
开发者ID:xxtime,项目名称:phalcon,代码行数:27,代码来源:SecurityPlugin.php


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