PicoraDocumentation
Provides support methods for other PicoraDocumentation* classes.
Method Overview
Return | Visibility | Name | Parameters |
array | static public | arrayFromDocComment | (string $comment) |
array | static public | codeArrayFromReflectionObject | (object $r) |
unknown | static public | getClassParentList | (ReflectionClass $class) |
unknown | static public | getImplementedClassInterfaceList | (ReflectionClass $class) |
array | static public | getFunctionList | () |
array | static public | getClassList | () |
bool | static public | match | (object $object, string $search_terms) |
Method Detail
static public arrayFromDocComment()
Parameter Type | Name | Description |
string | $comment | in PHP/JavaDoc format |
Parses a doc comment string into an array of tokens (any comment line beginning with @), and a description.
static public codeArrayFromReflectionObject()
Parameter Type | Name | Description |
object | $r | any Reflection class or PicoraDocumentation class |
static public getClassParentList()
Parameter Type | Name | Description |
ReflectionClass | $class |
static public getImplementedClassInterfaceList()
Parameter Type | Name | Description |
ReflectionClass | $class |
static public getFunctionList()
Only functions that have a valid doc comment will be included in the list.
static public getClassList()
Only classes that have a valid doc comment will be included in the list.
static public match()
Parameter Type | Name | Description |
object | $object | |
string | $search_terms |
Match a PicoraDocumentationFunction, PicoraDocumentaitonClass or PicoraDocumentationMethod against a query string.
Declared in: PicoraDocumentation.php
class PicoraDocumentation {
/**
* Only functions that have a valid doc comment will be included in the list.
* @return array of PicoraDocumentationFunction objects for user defined functions
*/
static public function getFunctionList(){
$functions = get_defined_functions();
$list = array();
foreach($functions['user'] as $name){
$function = new PicoraDocumentationFunction($name);
if($function['description'] == '' && !isset($function['introduction']) && !count($function['params']))
continue;
$list[$name] = $function;
}
ksort($list);
return $list;
}
/**
* Only classes that have a valid doc comment will be included in the list.
* @return array of PicoraDocumentationClass objects for user defined classes
*/
static public function getClassList(){
$list = array();
foreach(get_declared_classes() as $name){
$class = new PicoraDocumentationClass($name);
if($class->isInternal())
continue;
if($class['description'] == '' && !isset($class['introduction']) && !count($class['params']))
continue;
$list[$name] = $class;
}
ksort($list);
return $list;
}
/**
* Parses a doc comment string into an array of tokens (any comment line beginning with @), and a description.
* @param string $comment in PHP/JavaDoc format
* @return array tokens, array 'params' and string 'description' are always present
*/
static public function arrayFromDocComment($comment){
$tolkens = array(
'params' => array(),
'description' => array(),
'events' => array()
);
foreach(explode(chr(10),$comment) as $line){
$line = preg_replace('/^\s+/','',$line);
$line = preg_replace('/^\* /','',$line);
if($line == '/**' || $line == '*/' || $line == '*' || preg_match('/^\*\s*$/',$line))
continue;
if(strpos($line,'@') === 0){
if(preg_match('/^\@([^\s]+)\s+(.+)$/',$line,$matches)){
if($matches[1] == 'param')
$tolkens['params'][] = $matches[2];
elseif($matches[1] == 'event')
$tolkens['events'][] = $matches[2];
else
$tolkens[$matches[1]] = $matches[2];
}
}else
$tolkens['description'][] = $line;
}
$tolkens['description'] = implode(chr(10),$tolkens['description']);
return $tolkens;
}
/**
* @param ReflectionClass $class
*/
static public function getImplementedClassInterfaceList(ReflectionClass $class){
$implements = array();
foreach(get_declared_interfaces() as $interface)
if($class->implementsInterface($interface))
$implements[] = $interface;
return $implements;
}
/**
* @param ReflectionClass $class
*/
static public function getClassParentList(ReflectionClass $class){
$parents = array();
while($parent = $class->getParentClass()){
$parents[] = $parent->getName();
$class = $parent;
}
return $parents;
}
/**
* @param object $r any Reflection class or PicoraDocumentation class
* @return array declaring lines of the given class, method or function
*/
static public function codeArrayFromReflectionObject($r){
return array_slice(file($r->getFileName()),($r->getStartLine() - 1),(($r->getEndLine() - $r->getStartLine()) + 1),true);
}
/**
* Match a PicoraDocumentationFunction, PicoraDocumentaitonClass or PicoraDocumentationMethod against a query string.
* @param object $object
* @param string $search_terms
* @return bool
*/
static public function match($object,$search_terms){
if(strlen($search_terms) <= 2)
return false;
$score = 0;
if(strcasecmp($object->name,$search_terms) == 0 || stripos($object->name,$search_terms) !== false)
$score += 1000;
if(isset($object['introduction']) && stripos($object['introduction'],$search_terms) !== false)
$score += 100;
$params = $object['params'];
foreach($params as $param)
if(stripos($param,'$'.$search_terms) !== false || stripos($param,$search_terms) !== false)
$score += 100;
if(isset($object['description']) && stripos($object['description'],$search_terms) !== false)
$score += 25;
return $score;
/*
return true;
if($object->name == $search_terms)
return true;
if(strpos(strtolower($object->name),$search_terms) !== false)
return true;
if(strlen($search_terms) <= 3)
return false;
foreach($object['params'] as $param)
if(strpos(strtolower($param),'$'.$search_terms) !== false || strpos(strtolower($param),$search_terms) !== false)
return true;
//if(strpos(strtolower(array_pop(explode('/',$object['file']))),$search_terms) !== false)
// return true;
return false;
*/
}
}