Esempio n. 1
0
 public static function parse($name, $src, $docendpos = 0)
 {
     $info = new static();
     $info->name($name);
     if ($docendpos > 0) {
         $doc = trim(substr($src, 0, $docendpos));
         $startpos = strrpos($doc, '/**');
         if ($startpos !== false) {
             $doc = substr($doc, $startpos);
             if (preg_match('/\\/\\*\\*(.+?)\\*\\//s', $doc, $m)) {
                 $doc = preg_replace('/^[\\s]*\\*[\\s]{0,1}/m', '', $m[1]);
             } else {
                 $doc = '';
             }
         } else {
             $doc = '';
         }
     } else {
         $doc = $src;
     }
     $params = \ebi\Dt\DocParam::parse('param', $doc);
     if (!empty($params)) {
         $info->params($params);
     }
     if (preg_match("/@return\\s+([^\\s]+)(.*)/", $doc, $m)) {
         $info->return(new \ebi\Dt\DocParam('return', $m[1], $m[2]));
     }
     $info->document(trim(preg_replace('/@.+/', '', preg_replace("/^[\\s]*\\*[\\s]{0,1}/m", '', str_replace('*' . '/', '', $doc)))));
     return $info;
 }
Esempio n. 2
0
 /**
  * クラスドメソッドのキュメント
  * @param string $class
  * @param string $method
  */
 public static function method_info($class, $method, $deep = true)
 {
     $ref = new \ReflectionMethod(self::get_class_name($class), $method);
     $is_request_flow = $ref->getDeclaringClass()->isSubclassOf('\\ebi\\flow\\Request');
     $method_fullname = $ref->getDeclaringClass()->getName() . '::' . $ref->getName();
     if (is_file($ref->getDeclaringClass()->getFileName())) {
         $document = '';
         if ($is_request_flow) {
             try {
                 $ref = new \ReflectionMethod(self::get_class_name($class), '__before__');
                 if (preg_match_all('/@.+$/', self::get_method_document($ref), $m)) {
                     foreach ($m[0] as $a) {
                         $document = $a . PHP_EOL . $document;
                     }
                 }
             } catch (\ReflectionException $e) {
             }
         }
         $document = $document . self::get_method_document($ref);
         $src = self::method_src($ref);
         $info = \ebi\Dt\DocInfo::parse($method_fullname, $document);
         $info->set_opt('deprecated', strpos($document, '@deprecated') !== false);
         if (preg_match("/@http_method\\s+([^\\s]+)/", $document, $match)) {
             $info->set_opt('http_method', strtoupper(trim($match[1])));
         } else {
             $info->set_opt('http_method', strpos($src, '$this->is_post()') !== false && strpos($src, '!$this->is_post()') === false ? ' POST' : null);
         }
         $info->set_opt('class', $ref->getDeclaringClass()->getName());
         $info->set_opt('method', $ref->getName());
         $info->set_opt('requests', \ebi\Dt\DocParam::parse('request', $document));
         $info->set_opt('contexts', \ebi\Dt\DocParam::parse('context', $document));
         $info->set_opt('args', \ebi\Dt\DocParam::parse('arg', $document));
         if (!$info->is_return() && $info->has_opt('contexts')) {
             $info->return(new \ebi\Dt\DocParam('return', 'mixed{}'));
         }
         if ($deep) {
             $call_plugins = [];
             $plugins = [];
             foreach (["/->get_object_plugin_funcs\\(([\"\\'])(.+?)\\1/", "/->call_object_plugin_funcs\\(([\"\\'])(.+?)\\1/", "/::call_class_plugin_funcs\\(([\"\\'])(.+?)\\1/", "/->call_object_plugin_func\\(([\"\\'])(.+?)\\1/", "/::call_class_plugin_func\\(([\"\\'])(.+?)\\1/"] as $preg) {
                 if (preg_match_all($preg, $src, $m, PREG_OFFSET_CAPTURE)) {
                     foreach ($m[2] as $k => $v) {
                         $plugins[$v[0]] = true;
                     }
                 }
             }
             $class_info = self::class_info($ref->getDeclaringClass()->getName());
             $class_plugins = $class_info->opt('plugins');
             foreach (array_keys($plugins) as $plugin_method_name) {
                 if (array_key_exists($plugin_method_name, $class_plugins)) {
                     $call_plugins[$class_plugins[$plugin_method_name]->opt('class') . '::' . $plugin_method_name] = $class_plugins[$plugin_method_name];
                 }
             }
             $info->set_opt('plugins', $call_plugins);
             $use_method_list = self::use_method_list($ref->getDeclaringClass()->getName(), $ref->getName());
             $use_method_list = array_merge($use_method_list, [$method_fullname]);
             foreach ($call_plugins as $plugin_info) {
                 foreach ($plugin_info->opt('added') as $class_name) {
                     $use_method_list[] = $class_name . '::' . $plugin_info->name();
                 }
             }
             $mail_template_list = self::mail_template_list();
             $throws = $throw_param = $mail_list = [];
             foreach ($use_method_list as $class_method) {
                 list($uclass, $umethod) = explode('::', $class_method);
                 try {
                     $ref = new \ReflectionMethod($uclass, $umethod);
                     $use_method_src = self::method_src($ref);
                     $use_method_doc = self::trim_doc($ref->getDocComment());
                     if (preg_match_all("/@throws\\s+([^\\s]+)(.*)/", $use_method_doc, $m)) {
                         foreach ($m[1] as $k => $n) {
                             $throws[$n] = [$n, $m[2][$k]];
                         }
                     }
                     foreach ($mail_template_list as $k => $mail_info) {
                         if (preg_match('/[^\\w\\/]' . preg_quote($mail_info->name(), '/') . '/', $use_method_src)) {
                             $mail_template_list[$k]->set_opt('use', true);
                         }
                     }
                 } catch (\ReflectionException $e) {
                 }
             }
             foreach ($throws as $n => $t) {
                 try {
                     $ref = new \ReflectionClass($n);
                     $doc = empty($t[1]) ? trim(preg_replace('/@.+/', '', self::trim_doc($ref->getDocComment()))) : $t[1];
                     $throw_param[$n] = new \ebi\Dt\DocParam($ref->getName(), $ref->getName(), $doc);
                 } catch (\ReflectionException $e) {
                 }
             }
             $info->set_opt('throws', $throw_param);
             foreach ($mail_template_list as $mail_info) {
                 if ($mail_info->opt('use') === true) {
                     $mail_list[] = $mail_info;
                 }
             }
             $info->set_opt('mail_list', $mail_list);
         }
         return $info;
     }
     throw new \ebi\exception\NotFoundException();
 }