예제 #1
0
파일: Man.php 프로젝트: tokushima/ebi
 /**
  * クラスドメソッドのキュメント
  * @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();
 }
예제 #2
0
파일: Dt.php 프로젝트: tokushima/ebi
 /**
  * @automap
  * @throws \ebi\exception\NotFoundException
  */
 public function test_view()
 {
     $req = new \ebi\Request();
     $testdir = $this->test_path();
     $req_path = $req->in_vars('path');
     $path = \ebi\Util::path_absolute($testdir, $req_path);
     if (strpos($path, $testdir) === false) {
         throw new \ebi\exception\NotFoundException($req->in_vars('path') . ' not found');
     }
     $src = str_replace('<?php', '', file_get_contents($path));
     $pos = strpos($src, '*/');
     if ($pos === false) {
         $info = new \ebi\Dt\DocInfo();
         $info->name($req_path);
     } else {
         $info = \ebi\Dt\DocInfo::parse($req_path, $src, $pos + 2);
     }
     while ($path != $testdir) {
         $path = dirname($path) . '/';
         if (is_file($f = $path . '__setup__.php')) {
             $src = str_replace('<?php', '', file_get_contents($f)) . PHP_EOL . '// ' . str_repeat('-', 80) . PHP_EOL . $src;
         }
     }
     return ['info' => $info, 'src' => '<?php' . PHP_EOL . $src];
 }