public static function parse($class) { $rc = new Reflection\ReflectionClass($class); $file = $rc->getFileName(); $func = function (&$success) use($class) { $rc = new Reflection\ReflectionClass($class); $class = $rc->DocComment(); $methods = []; foreach ($rc->getMethods() as $m) { $methods[$m->getName()] = $m->DocComment(); } $annotation = new Annotation(['class' => $class, 'methods' => $methods]); $success = true; return $annotation; }; return $func($success); /* return Nora::Cache()->useCache( $file, $func, -1, false ); */ }
/** * パブリックメソッドだけを取得する */ public function getPublicMethods() { $methods = []; foreach (parent::getMethods() as $m) { if ($m->isPublic()) { $methods[] = new ReflectionMethod($this->getName(), $m->getName()); } } return $methods; }
/** * DocCommentを取得する * * @param mixed $object * @return string */ public static function getDocCommentRaw($object) { if ($object instanceof ReflectionMethod || $object instanceof ReflectionClass || $object instanceof ReflectionFunction || $object instanceof Injection\Spec) { return $object->getDocComment(); } // オブジェクトを判定 if (is_callable($object) && is_array($object)) { $rs = new ReflectionMethod($object[0], $object[1]); return $rs->getDocComment(); } if ($object instanceof Closure) { $rs = new ReflectionFunction($object); return $rs->getDocComment(); } if (is_array($object) && is_callable($object[count($object) - 1])) { return self::getDocCommentRaw($object[count($object) - 1]); } if (is_object($object)) { $rs = new ReflectionClass($object); return $rs->getDocComment(); } throw new Exception\CantRetriveDocComment($object); }
public function __invoke($var) { if (is_string($var) && !class_exists($var) || is_array($var) || is_numeric($var)) { $this->_debugger->debug($var); return; } $rc = new Reflection\ReflectionClass($var); $out = $this->_output; $out->head('<link rel="stylesheet" href="/share/markdown/markdown.css">'); // クラス参照を作成 $rc = new Reflection\ReflectionClass($var); // クラス名 $out->writeTitle("クラス名: " . $rc->getName()); // 情報テーブル $info = $out->table('INFO'); $tmp = $rc->getParentClass(); while ($tmp) { $info->add("継承", $tmp->getName()); $tmp = $tmp->getParentClass(); } $info->add("ファイル", $rc->getFileName()); foreach ($rc->getInterfaces() as $if) { $info->add("インターフェイス", $if->getName()); } foreach ($rc->getTraits() as $tr) { $info->add("トレイト", $tr->getName()); } // リードミーが設定されていた場合それを表示する if ($rc->hasAttr('readme')) { foreach ($rc->getAttr('readme') as $path) { if ($path[0] !== '.') { $path = '/./' . $path; } else { $path = '/' . $path; } $file = realpath(dirname($rc->getFileName()) . $path); $out->markdown(file_get_contents($file)); } } // メソッドリストを作成 $methods = $out->table('METHODS'); $methods->add('メッソド名', 'コメント', '引数'); // Public Methodを取得する foreach ($rc->getPublicMethods() as $m) { if (substr($m->getName(), 0, 1) === '_') { continue; } $methods->add($m->getName(), $m->comment(), $m->toStringParams(), $m->getDeclaringClass()->getShortName()); } $out->writeSource($rc->getFileName()); $out->send(); }