getUniqueId() публичный Метод

Returns the unique ID of this action among the whole application.
public getUniqueId ( ) : string
Результат string the unique ID of this action among the whole application.
Пример #1
0
 /**
  * Returns a value indicating whether the filer is active for the given action.
  * @param \yii\base\Action $action the action being filtered
  * @return boolean whether the filer is active for the given action.
  */
 protected function isActive($action)
 {
     if ($action->getUniqueId() === Yii::$app->getErrorHandler()->errorAction) {
         return false;
     }
     return parent::isActive($action);
 }
Пример #2
0
 /**
  * check the permission, if we rewrite and controller, the controller id and module id is not changed
  * @param \yii\base\Action $action
  * @param \yii\web\User $user
  * @param \yii\web\Request $request
  * @return bool
  */
 public function matchActionAccess($action, $user, $request)
 {
     if ($user->getIsGuest()) {
         return false;
     }
     /** @var \core\auth\Module $authModule */
     $authModule = \Yii::$app->getModule('core_auth');
     foreach ($authModule->getAdmins() as $key => $admin) {
         if ($user->getIdentity()->username == $admin['username']) {
             return true;
         }
     }
     if ($action->controller->module instanceof Application) {
         $key = 'default' . '_' . $action->controller->id . '_' . $action->id;
     } else {
         $key = $action->getUniqueId();
         $key = explode('/', $key);
         array_shift($key);
         $key = implode('_', $key);
     }
     $key = lcfirst(implode('', array_map(function ($k) {
         return ucfirst($k);
     }, explode('-', $key))));
     return $user->can($key, $this->params);
 }
Пример #3
0
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * You may override this method to do last-minute preparation for the action.
  * @param Action $action the action to be executed.
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (!$this->enabled) {
         return true;
     }
     $this->cache = Instance::ensure($this->cache, Cache::className());
     $properties = [];
     foreach (['cache', 'duration', 'dependency', 'variations'] as $name) {
         $properties[$name] = $this->{$name};
     }
     $id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__;
     $response = Yii::$app->getResponse();
     ob_start();
     ob_implicit_flush(false);
     if ($this->view->beginCache($id, $properties)) {
         $response->on(Response::EVENT_AFTER_SEND, [$this, 'cacheResponse']);
         return true;
     } else {
         $data = $this->cache->get($this->calculateCacheKey());
         if (is_array($data)) {
             $this->restoreResponse($response, $data);
         }
         $response->content = ob_get_clean();
         return false;
     }
 }
Пример #4
0
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * You may override this method to do last-minute preparation for the action.
  * @param Action $action the action to be executed.
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     $properties = [];
     foreach (['cache', 'duration', 'dependency', 'variations', 'enabled'] as $name) {
         $properties[$name] = $this->{$name};
     }
     $id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__;
     ob_start();
     ob_implicit_flush(false);
     if ($this->view->beginCache($id, $properties)) {
         return true;
     } else {
         Yii::$app->getResponse()->content = ob_get_clean();
         return false;
     }
 }
 /**
  * @param Action $action
  *
  * @return string
  */
 private function getActionLogCategory(Action $action)
 {
     return $this->actionCategoryPrefix . $action->getUniqueId();
 }
Пример #6
0
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * You may override this method to do last-minute preparation for the action.
  * @param Action $action the action to be executed.
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     $properties = [];
     foreach (['cache', 'duration', 'dependency', 'variations', 'enabled'] as $name) {
         $properties[$name] = $this->{$name};
     }
     $id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__;
     // Disable layout, cache only action result
     $controller = $action->controller;
     $this->_controllerLayout = $controller->layout;
     $controller->layout = false;
     ob_start();
     ob_implicit_flush(false);
     if ($this->view->beginCache($id, $properties)) {
         return true;
     } else {
         $actionContent = ob_get_clean();
         $controller->layout = $this->_controllerLayout;
         Yii::$app->getResponse()->content = $controller->renderContent($actionContent);
         return false;
     }
 }
Пример #7
0
 /**
  * Returns a value indicating whether a current url exists in the `allowActions` list.
  *
  * @param Action $action
  *
  * @return bool
  */
 private function isAllowedAction($action)
 {
     if ($this->owner instanceof Module) {
         $ownerId = $this->owner->getUniqueId();
         $id = $action->getUniqueId();
         if (!empty($ownerId) && strpos($id, $ownerId . '/') === 0) {
             $id = substr($id, strlen($ownerId) + 1);
         }
     } else {
         $id = $action->id;
     }
     foreach ($this->allowActions as $route) {
         if (substr($route, -1) === '*') {
             $route = rtrim($route, '*');
             if ($route === '' || strpos($id, $route) === 0) {
                 return true;
             }
         } else {
             if ($id === $route) {
                 return true;
             }
         }
     }
     return false;
 }