Esempio n. 1
0
 /**
  * クラスのドキュメント
  * @param string $class
  */
 public static function class_info($class)
 {
     $info = new \ebi\Dt\DocInfo();
     $r = new \ReflectionClass(self::get_class_name($class));
     if ($r->getFilename() === false || !is_file($r->getFileName())) {
         throw new \ebi\exception\InvalidArgumentException('`' . $class . '` file not found.');
     }
     $src = self::get_reflection_source($r);
     $document = self::trim_doc($r->getDocComment());
     $info->name($r->getName());
     $info->document(trim(preg_replace('/@.+/', '', $document)));
     $info->set_opt('filename', $r->getFileName());
     $info->set_opt('extends', $r->getParentClass() === false ? null : $r->getParentClass()->getName());
     $info->set_opt('abstract', $r->isAbstract());
     $see = [];
     if (preg_match_all("/@see\\s+([\\w\\.\\:\\\\]+)/", $document, $m)) {
         foreach ($m[1] as $v) {
             $v = trim($v);
             if (strpos($v, '://') !== false) {
                 $see[$v] = ['type' => 'url', 'url' => $v];
             } else {
                 if (strpos($v, '::') !== false) {
                     list($class, $method) = explode('::', 2);
                     $see[$v] = ['type' => 'method', 'class' => $class, 'method' => $method];
                 } else {
                     if (substr($v, -1) != ':') {
                         $see[$v] = ['type' => 'class', 'class' => $class];
                     }
                 }
             }
         }
     }
     $methods = [];
     foreach ($r->getMethods() as $method) {
         if (substr($method->getName(), 0, 1) != '_' && $method->isPublic() && !$method->isStatic()) {
             $ignore = ['getIterator'];
             if (!in_array($method->getName(), $ignore)) {
                 $method_document = self::get_method_document($method);
                 list($desc) = explode(PHP_EOL, trim(preg_replace('/@.+/', '', $method_document)));
                 $method_info = new \ebi\Dt\DocInfo();
                 $method_info->name($method->getName());
                 $method_info->document($desc);
                 $methods[] = $method_info;
             }
         }
     }
     $info->set_opt('methods', $methods);
     $properties = [];
     $anon = \ebi\Annotation::get_class(self::get_class_name($class), 'var', 'summary');
     $is_obj = $r->isSubclassOf(\ebi\Object::class);
     foreach ($r->getProperties() as $prop) {
         if ($prop->isPublic() || $is_obj && $prop->isProtected()) {
             $name = $prop->getName();
             if ($name[0] != '_' && !$prop->isStatic()) {
                 $properties[$name] = new \ebi\Dt\DocParam($name, isset($anon[$name]['type']) ? $anon[$name]['type'] : 'mixed', isset($anon[$name]['summary']) ? $anon[$name]['summary'] : null, ['hash' => $prop->isPublic() || !(isset($anon[$name]['hash']) && $anon[$name]['hash'] === false)]);
             }
         }
     }
     $info->set_opt('properties', $properties);
     $config_list = [];
     foreach (["/Conf::gets\\(([\"\\'])(.+?)\\1/" => 'mixed[]', "/Conf::get\\(([\"\\'])(.+?)\\1/" => 'mixed', "/self::get_self_conf_get\\(([\"\\'])(.+?)\\1/" => 'mixed'] as $preg => $default_type) {
         if (preg_match_all($preg, $src, $m, PREG_OFFSET_CAPTURE)) {
             foreach ($m[2] as $k => $v) {
                 // 呼び出しが重複したら先にドキュメントがあった方
                 if (!array_key_exists($v[0], $config_list) || !$config_list[$v[0]]->has_params()) {
                     $conf_info = \ebi\Dt\DocInfo::parse($v[0], $src, $m[0][$k][1]);
                     $conf_info->set_opt('def', \ebi\Conf::exists($r->getName(), $v[0]));
                     if (!$conf_info->has_params()) {
                         $conf_info->add_params(new \ebi\Dt\DocParam('val', $default_type));
                     }
                     $config_list[$v[0]] = $conf_info;
                 }
             }
         }
     }
     ksort($config_list);
     $info->set_opt('config_list', $config_list);
     $call_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) {
                 $call_plugins[$v[0]] = \ebi\Dt\DocInfo::parse($v[0], $src, $m[0][$k][1]);
                 $call_plugins[$v[0]]->set_opt('added', []);
             }
         }
     }
     $traits = [];
     $parent = new \ReflectionClass($r->getName());
     do {
         $traits = array_merge($traits, $parent->getTraitNames());
         if (($parent = $parent->getParentClass()) === false) {
             break;
         }
     } while (true);
     if (in_array('ebi\\Plugin', $traits)) {
         foreach (\ebi\Conf::get_class_plugin($r->getName()) as $o) {
             $pr = new \ReflectionClass(is_object($o) ? get_class($o) : $o);
             foreach ($pr->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) {
                 foreach (array_keys($call_plugins) as $method_name) {
                     if ($m->getName() == $method_name) {
                         $added = $call_plugins[$method_name]->opt('added');
                         $added[] = $pr->getName();
                         $call_plugins[$method_name]->set_opt('added', $added);
                     }
                 }
             }
         }
     }
     $info->set_opt('plugins', $call_plugins);
     return $info;
 }
Esempio n. 2
0
 /**
  * クラスのプラグインを取得
  * @param string $n
  * @return array
  */
 protected static function get_class_plugin_funcs($n)
 {
     $rtn = [];
     $g = get_called_class();
     foreach (\ebi\Conf::get_class_plugin($g) as $o) {
         static::set_class_plugin($o);
     }
     if (isset(self::$_plug_funcs[$g])) {
         foreach (self::$_plug_funcs[$g] as $o) {
             if (is_array($o)) {
                 if ($n == $o[1]) {
                     $rtn[] = $o[0];
                 }
             } else {
                 if (method_exists($o, $n)) {
                     $rtn[] = [$o, $n];
                 }
             }
         }
     }
     return $rtn;
 }