actions() public method

This method is meant to be overwritten to declare external actions for the controller. It should return an array, with array keys being action IDs, and array values the corresponding action class names or action configuration arrays. For example, php return [ 'action1' => 'app\components\Action1', 'action2' => [ 'class' => 'app\components\Action2', 'property1' => 'value1', 'property2' => 'value2', ], ]; [[\Yii::createObject()]] will be used later to create the requested action using the configuration provided here.
public actions ( )
 private static function controllerActions(\yii\base\Controller $controller)
 {
     $actions = array_keys($controller->actions());
     $reflection = new \ReflectionClass($controller);
     foreach ($reflection->getMethods() as $method) {
         if (!preg_match('/^action([A-Z].*)/', $method->name, $matches)) {
             continue;
         }
         $actions[] = self::getRouteName($matches[1]);
     }
     return $actions;
 }
Beispiel #2
0
 /**
  * @param Controller $controller
  *
  * @return array
  */
 public function getControllerActions(Controller $controller)
 {
     $actions = array_keys($controller->actions());
     $class = new \ReflectionClass($controller);
     foreach ($class->getMethods() as $method) {
         $name = $method->getName();
         if ($method->isPublic() && !$method->isStatic() && mb_strpos($name, self::ACTION_METHOD) === 0 && $name !== 'actions') {
             if (\Yii::$app->id == $controller->module->id) {
                 continue;
             }
             $action = Inflector::camel2id(mb_substr($name, mb_strlen(self::ACTION_METHOD)));
             $actions[] = $action;
         }
     }
     asort($actions);
     return $actions;
 }
Beispiel #3
0
 /**
  * Get route of action
  * @param \yii\base\Controller $controller
  * @param array $result all controller action.
  */
 private function getActionRoutes($controller, &$result)
 {
     $token = "Get actions of controller '" . $controller->uniqueId . "'";
     Yii::beginProfile($token, __METHOD__);
     try {
         $prefix = '/' . $controller->uniqueId . '/';
         foreach ($controller->actions() as $id => $value) {
             $result[] = $prefix . $id;
         }
         $class = new \ReflectionClass($controller);
         foreach ($class->getMethods() as $method) {
             $name = $method->getName();
             if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') {
                 $result[] = $prefix . Inflector::camel2id(substr($name, 6));
             }
         }
     } catch (\Exception $exc) {
         Yii::error($exc->getMessage(), __METHOD__);
     }
     Yii::endProfile($token, __METHOD__);
 }
 /**
  * Get route of action
  * @param \yii\base\Controller $controller
  * @param array $result all controller action.
  */
 protected function getActionRoutes($controller, &$result)
 {
     $token = "Get actions of controller '" . $controller->uniqueId . "'";
     Yii::beginProfile($token, __METHOD__);
     try {
         $prefix = '/' . $controller->uniqueId . '/';
         foreach ($controller->actions() as $id => $value) {
             $result[$prefix . $id] = $prefix . $id;
         }
         $class = new \ReflectionClass($controller);
         foreach ($class->getMethods() as $method) {
             $name = $method->getName();
             if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') {
                 $name = strtolower(preg_replace('/(?<![A-Z])[A-Z]/', ' \\0', substr($name, 6)));
                 $id = $prefix . ltrim(str_replace(' ', '-', $name), '-');
                 $result[$id] = $id;
             }
         }
     } catch (\Exception $exc) {
         Yii::error($exc->getMessage(), __METHOD__);
     }
     Yii::endProfile($token, __METHOD__);
 }
Beispiel #5
0
 /**
  * @param \yii\base\Controller $controller
  * @param Array                $result all controller action.
  */
 private static function getActionRoutes($controller, &$result)
 {
     $prefix = '/' . $controller->uniqueId . '/';
     foreach ($controller->actions() as $id => $value) {
         $result[] = $prefix . $id;
     }
     $class = new \ReflectionClass($controller);
     foreach ($class->getMethods() as $method) {
         $name = $method->getName();
         if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') {
             $result[] = $prefix . Inflector::camel2id(substr($name, 6));
         }
     }
 }
 /**
  * @param \yii\base\Controller $controller
  * @return array
  */
 protected function getActions(\yii\base\Controller $controller)
 {
     $actions = [];
     // inline actions
     $reflection = new \ReflectionObject($controller);
     $methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
     $methods = array_filter($methods, function ($method) {
         return strpos($method->name, 'action') === 0 && $method->name != 'actions';
     });
     foreach ($methods as $method) {
         $actionId = strtolower(preg_replace('/([A-Z]){1}/', '-$1', lcfirst(substr($method->name, 6))));
         $dockBlock = null;
         try {
             $dockBlock = new DocBlockReflection($method);
         } catch (\Exception $e) {
         }
         $action = new ActionAdapter($controller->createAction($actionId), $dockBlock);
         $actions[$actionId] = $action;
     }
     // external actions
     foreach ($controller->actions() as $actionId => $alias) {
         $actions[$actionId] = new ActionAdapter($controller->createAction($actionId));
     }
     return $actions;
 }
 /**
  * 
  * @param \yii\base\Controller $controller
  * @param Array $result all controller action.
  */
 private static function getActionRoutes($controller, &$result)
 {
     $prefix = '/' . $controller->uniqueId . '/';
     //print_r(['controllerId'=>$controller->id,'moduleId'=>$controller->module->id]);
     foreach ($controller->actions() as $id => $value) {
         //$result[$controller->module->id][$controller->id][] = $id;
         if (Yii::$app->id == $controller->module->id) {
             continue;
         }
         self::setActionList($id, $result);
         self::setControllerList($controller, $result);
         self::setModuleList($controller->module, $result);
         $result['map'][$controller->module->id][$controller->id][] = $id;
         /*
                     $result['model'][] = [
                                     'module' => $controller->module->id,
                                     'controller' => $controller->id,
                                     'action'    =>  $id,
                                 ];
                     //*/
     }
     $class = new \ReflectionClass($controller);
     foreach ($class->getMethods() as $method) {
         $name = $method->getName();
         if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') {
             //$result[$controller->module->id][$controller->id][] = Inflector::camel2id(substr($name, 6));
             if (Yii::$app->id == $controller->module->id) {
                 continue;
             }
             $action = Inflector::camel2id(substr($name, 6));
             self::setActionList($action, $result);
             self::setControllerList($controller, $result);
             self::setModuleList($controller->module, $result);
             $result['map'][$controller->module->id][$controller->id][] = $action;
             /*
                             $result['model'][] = [
                                         'module' => $controller->module->id,
                                         'controller' => $controller->id,
                                         'action'    =>  $action,
                                     ];
                             //*/
         }
     }
 }