Esempio n. 1
0
 /**
  * 前処理、入力値のバリデーションやログイン処理を行う
  * __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();
         }
     }
 }
Esempio n. 2
0
 private static function automap($url, $class, $name, $idx)
 {
     $result = [];
     try {
         $r = new \ReflectionClass(str_replace('.', '\\', $class));
         $d = substr($r->getFilename(), 0, -4);
         foreach ($r->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) {
             if (!$m->isStatic() && substr($m->getName(), 0, 1) != '_') {
                 $suffix = '';
                 $auto_anon = \ebi\Annotation::get_method($r->getName(), $m->getName(), 'automap');
                 if (is_array($auto_anon)) {
                     $base_name = $m->getName();
                     if (isset($auto_anon['suffix'])) {
                         $suffix = $auto_anon['suffix'];
                         unset($auto_anon['suffix']);
                     }
                     if (isset($auto_anon['name'])) {
                         $base_name = $auto_anon['name'];
                         unset($auto_anon['name']);
                     }
                     $murl = $url . ($m->getName() == 'index' ? '' : ($url == '' ? '' : '/') . $base_name) . str_repeat('/(.+)', $m->getNumberOfRequiredParameters());
                     $result[$murl . $suffix] = ['name' => $name . '/' . $base_name, 'action' => $class . '::' . $m->getName(), '@' => $d, 'idx' => $idx];
                     if (!empty($auto_anon)) {
                         $result[$murl . $suffix] = array_merge($result[$murl . $suffix], $auto_anon);
                     }
                 }
             }
         }
     } catch (\ReflectionException $e) {
         throw new \ebi\exception\InvalidArgumentException($class . ' not found');
     }
     return $result;
 }