Beispiel #1
0
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($this->enableCsrfValidation && Leaps::$app->getErrorHandler()->exception === null && !Leaps::$app->getRequest()->validateCsrfToken()) {
             throw new BadRequestHttpException(Leaps::t('leaps', 'Unable to verify your data submission.'));
         }
         return true;
     }
     return false;
 }
Beispiel #2
0
 /**
  * Runs an action with the specified action ID and parameters.
  * If the action ID is empty, the method will use [[defaultAction]].
  *
  * @param string $id the ID of the action to be executed.
  * @param array $params the parameters (name-value pairs) to be passed to the action.
  * @return integer the status of the action execution. 0 means normal, other values mean abnormal.
  * @throws InvalidRouteException if the requested action ID cannot be resolved into an action successfully.
  * @throws Exception if there are unknown options or missing arguments
  * @see createAction
  */
 public function runAction($id, $params = [])
 {
     if (!empty($params)) {
         // populate options here so that they are available in beforeAction().
         $options = $this->options($id === '' ? $this->defaultAction : $id);
         foreach ($params as $name => $value) {
             if (in_array($name, $options, true)) {
                 $default = $this->{$name};
                 $this->{$name} = is_array($default) ? preg_split('/\\s*,\\s*/', $value) : $value;
                 unset($params[$name]);
             } elseif (!is_int($name)) {
                 throw new Exception(Leaps::t('Leaps', 'Unknown option: --{name}', ['name' => $name]));
             }
         }
     }
     return parent::runAction($id, $params);
 }