/** * 前処理、入力値のバリデーションやログイン処理を行う * __before__メソッドを定義することで拡張する */ public function before() { list(, $method) = explode('::', $this->get_selected_pattern()['action']); $annon = \ebi\Annotation::get_method(get_class($this), $method, ['http_method', 'request', 'user_role']); if (isset($annon['http_method']['value']) && strtoupper($annon['http_method']['value']) != \ebi\Request::method()) { throw new \ebi\exception\BadMethodCallException('Method Not Allowed'); } if (isset($annon['request'])) { foreach ($annon['request'] as $k => $an) { if (isset($an['type'])) { try { \ebi\Validator::type($k, $this->in_vars($k), $an); } catch (\ebi\exception\InvalidArgumentException $e) { \ebi\Exceptions::add($e, $k); } \ebi\Validator::value($k, $this->in_vars($k), $an); } } } \ebi\Exceptions::throw_over(); if (method_exists($this, '__before__')) { $this->__before__(); } if ($this->has_object_plugin('before_flow_action_request')) { /** * 前処理 * @param \ebi\flow\Request $arg1 */ $this->call_object_plugin_funcs('before_flow_action_request', $this); } if (!$this->is_user_logged_in() && (isset($this->login_anon) || $this->has_object_plugin('login_condition'))) { $this->login_required(); } if ($this->is_user_logged_in() && (isset($annon['user_role']) || isset($this->login_anon['user_role']))) { if (!in_array(\ebi\UserRole::class, \ebi\Util::get_class_traits(get_class($this->user()))) || isset($this->login_anon['user_role']) && !in_array($this->login_anon['user_role'], $this->user()->get_role()) || isset($annon['user_role']['value']) && !in_array($annon['user_role']['value'], $this->user()->get_role())) { throw new \ebi\exception\NotPermittedException(); } } }
private function ___set___($v) { if ($this->prop_anon($this->_, 'set') === false) { throw new \ebi\exception\InvalidArgumentException('not permitted'); } $anon = $this->prop_anon($this->_); switch ($this->prop_anon($this->_, 'attr')) { case 'a': $v = func_num_args() > 1 ? func_get_args() : (is_array($v) ? $v : [$v]); foreach ($v as $a) { $this->{$this->_}[] = \ebi\Validator::type($this->_, $a, $anon); } break; case 'h': $v = func_num_args() === 2 ? [func_get_arg(0) => func_get_arg(1)] : (is_array($v) ? $v : [(string) $v => $v]); foreach ($v as $k => $a) { $this->{$this->_}[$k] = \ebi\Validator::type($this->_, $a, $anon); } break; default: $this->{$this->_} = \ebi\Validator::type($this->_, $v, $anon); } return $this; }