PicoraDocumentationClass
Superset of ReflectionClass
extends ReflectionClass implements ArrayAccess , Reflector
Similar to a ReflectionClass object, except that when used as an array, you can access all of the comment information, and when calling getMethods() and getMethod() you get PicoraDocumentationMethod objects back instead of ReflectionMethod objects.
$c = new PicoraDocumentationClass('MyDocumentedClass');
$c->name; //MyDocumentedClass
$c['description']; //string description in doc comment
You also get the following extra properties:
- string file
- string visibility
- array extends
- array implements
Methods are sorted by the following scoring order:
- is static
- visibility
- alphabetical
Declared in: PicoraDocumentation.php
class PicoraDocumentationClass extends ReflectionClass implements ArrayAccess {
protected $comments = array();
public function __construct($name){
parent::__construct($name);
$this->comments = PicoraDocumentation::arrayFromDocComment($this->getDocComment());
$this->comments['file'] = $this->getFileName();
$this->comments['visibility'] = '';
if($this->isAbstract())
$this->comments['visibility'] .= 'abstract ';
if($this->isFinal())
$this->comments['visibility'] .= 'final ';
$this->comments['extends'] = PicoraDocumentation::getClassParentList($this);
$this->comments['implements'] = PicoraDocumentation::getImplementedClassInterfaceList($this);
$this->comments['name'] = $name;
}
public function getMethods(){
$methods = array();
foreach(parent::getMethods() as $method){
$m = $this->getMethod($method->name);
if($m->getDeclaringClass()->name == $this->name && (isset($m['return']) || count($m['params']) || $m['description'] != ''))
$methods[] = $m;
}
usort($methods,array('PicoraDocumentationClass','sort'));
return $methods;
}
static public function sort($a,$b){
$a_score = self::scoreFromMethod($a);
$b_score = self::scoreFromMethod($b);
return ($a_score == $b_score) ? 0 : ($a_score < $b_score ? -1 : 1);
}
static protected function scoreFromMethod(PicoraDocumentationMethod $m){
return array_sum(array(
($m->isStatic() ? -100000 : 0),
($m->isPublic() ? -10000 : 0),
($m->isProtected() ? -1000 : 0),
($m->isPrivate() ? -100 : 0),
ord(substr($m->name,0,1))
));
}
public function getMethod($name){
return new PicoraDocumentationMethod($this->name,$name);
}
public function offsetExists($key){return isset($this->comments[$key]);}
public function offsetSet($key,$value){$this->comments[$key] = $value;}
public function offsetGet($key){return $this->comments[$key];}
public function offsetUnset($key){unset($this->comments[$key]);}
}