/**
  * Returns a list of behaviors that this component should behave as.
  *
  * Child classes may override this method to specify the behaviors they want to behave as.
  *
  * The return value of this method should be an array of behavior objects or configurations
  * indexed by behavior names. A behavior configuration can be either a string specifying
  * the behavior class or an array of the following structure:
  *
  * ```php
  * 'behaviorName' => [
  *     'class' => 'BehaviorClass',
  *     'property1' => 'value1',
  *     'property2' => 'value2',
  * ]
  * ```
  *
  * Note that a behavior class must extend from [[Behavior]]. Behavior names can be strings
  * or integers. If the former, they uniquely identify the behaviors. If the latter, the corresponding
  * behaviors are anonymous and their properties and methods will NOT be made available via the component
  * (however, the behaviors can still respond to the component's events).
  *
  * Behaviors declared in this method will be attached to the component automatically (on demand).
  *
  * @return array the behavior configurations.
  */
 public function behaviors()
 {
     $behaviors = ['verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['post']]]];
     if (Module::hasUserRole()) {
         $behaviors['role'] = ['class' => \navatech\role\filters\RoleFilter::className(), 'name' => Translate::x_management([Translate::language()]), 'actions' => ['index' => Translate::lists(), 'delete' => Translate::delete()]];
     }
     return $behaviors;
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public function behaviors()
 {
     $behaviors = ['verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['post']]], 'access' => ['class' => AccessControl::className(), 'rules' => [['allow' => true, 'roles' => ['@']]]]];
     if (Module::hasUserRole()) {
         if (Module::hasMultiLanguage()) {
             return ArrayHelper::merge($behaviors, ['role' => ['class' => RoleFilter::className(), 'name' => Translate::setting(), 'actions' => ['index' => Translate::index()]]]);
         } else {
             return ArrayHelper::merge($behaviors, ['role' => ['class' => RoleFilter::className(), 'name' => 'Setting', 'actions' => ['index' => Yii::t('setting', 'List')]]]);
         }
     } else {
         return $behaviors;
     }
 }
예제 #3
0
 /**
  * @param $namespaces
  *
  * @return array
  */
 public static function getActions($namespaces)
 {
     error_reporting(E_ALL & ~E_STRICT);
     if (!is_array($namespaces)) {
         $namespaces = [$namespaces];
     }
     $response = [];
     foreach ($namespaces as $namespace) {
         $class = new ReflectionClass($namespace);
         $methods = $class->getMethods(ReflectionMethod::IS_PUBLIC);
         $behaviors = $namespace::behaviors();
         foreach ($methods as $method) {
             if ($method->class === $namespace && strpos($method->name, 'action') === 0) {
                 if (isset($behaviors['role']) && $behaviors['role']['class'] === RoleFilter::className()) {
                     $actions = [];
                     foreach ($behaviors['role']['actions'] as $key => $action) {
                         if (is_int($key)) {
                             $actions[$action] = Yii::t('app', ucfirst($action));
                         } else {
                             $actions[$key] = $action;
                         }
                     }
                     $response['name'] = isset($behaviors['role']['name']) ? $behaviors['role']['name'] : end(explode('\\', $namespace));
                     $response['actions'] = $actions;
                     break;
                 }
             }
         }
     }
     return $response;
 }
예제 #4
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['POST']]], 'role' => ['class' => RoleFilter::className(), 'name' => Module::hasMultiLanguage() ? RoleHelper::translate('role') : Yii::t('role', 'Role'), 'actions' => ['index' => Module::hasMultiLanguage() ? RoleHelper::translate('index') : Yii::t('role', 'List'), 'create' => Module::hasMultiLanguage() ? RoleHelper::translate('create') : Yii::t('role', 'Create'), 'update' => Module::hasMultiLanguage() ? RoleHelper::translate('update') : Yii::t('role', 'Update'), 'delete' => Module::hasMultiLanguage() ? RoleHelper::translate('delete') : Yii::t('role', 'Delete'), 'view' => Module::hasMultiLanguage() ? RoleHelper::translate('view') : Yii::t('role', 'View')]]];
 }