* version 10/02/2006 * * free to use, modify, please just tell me if you make any changes :-) */ class odocfunc { private $oloc; /** * tableau des fonctions */ private $aFunctions = array (); /** * chaine contenant le nom du fichier de fonctions */ private $sFileName = ''; /** * tableau buffer des lignes des fichiers codes */ private $fileBuf = array (); /** * constructeur * @Params string fileName : nom du fichier à analyser * @Params array aFuncs : tableau contenant le nom des fonctions à analyser */ public function __construct (array $aFuncs, $fileName) { $this -> oloc = new olocale ($_SESSION['locale']); if (empty ($aFuncs)) { trigger_error ($this -> oloc -> getMsg ('errors', 'no_function'), E_USER_ERROR); } $this -> sFileName = $fileName; foreach ($aFuncs as $func) { $this -> aFunctions[$func] = $this -> getaFunctions ($func); } $this -> buildHtmlFunc (); } /** * méthode privée buildHtmlFunc * appelle l'objet ohtml pour construire effectivement la doc pour les fonctions */ private function buildHtmlFunc () { $ohtml = new ohtml (); $ohtml -> headerFunc (); $ohtml -> setMenuFunc ($this -> sFileName, $this -> aFunctions); $ohtml -> setContentGeneralFunc ($this -> sFileName, $this -> aFunctions); $ohtml -> footer (); $ohtml -> toFileFunc ($this -> sFileName, $this -> sFileName); $ohtml -> freeHtml (); foreach ($this -> aFunctions as $val) { $ohtml -> headerFunc (); $ohtml -> setMenuFunc ($this -> sFileName, $this -> aFunctions); $ohtml -> setContentFunctions ($val); $ohtml -> footer (); $ohtml -> toFileFunc ($val['name'], $this -> sFileName); $ohtml -> freeHtml (); } $ohtml -> setIndex (); } /** * méthode privée getCode * sert à récupérer le code dans un fichier, d'une ligne de départ jusqu'à 1 ligne d'arrivée * @Return : string code */ private function getCode ($filename, $start, $end) { $code = ''; if (!array_key_exists ($filename, $this -> fileBuf)) { $this -> fileBuf[$filename] = file ($filename); } for ($i = $start - 1; $i <= $end; $i++) { $code .= $this -> fileBuf[$filename][$i]; } return $code; } /** * méthode privée getaFucntion * sert à remplir le tableau des propriétés des méthodes de la classe à analyser * @Return : array aTmp */ private function getaFunctions ($func) { $oFunc = new ReflectionFunction ($func); $aTmp = array ( 'name' => $oFunc -> getName (), 'type' => $oFunc -> isInternal() ? 'internal' : 'user-defined', 'file' => $oFunc -> getFileName (), 'startline' => $oFunc->getStartLine(), 'endline' => $oFunc->getEndline(), 'comments' => method_exists ($oFunc, 'getDocComment')?utf8_encode (htmlentities($oFunc -> getDocComment ())):$this -> oloc -> getMsg ('errors', 'php_bad_version'), 'statics' => $oFunc -> getStaticVariables(), 'returnsref' => $oFunc -> returnsReference()?$this -> oloc -> getMsg ('doc', 'doc_yes'):$this -> oloc -> getMsg ('doc', 'doc_no'), 'parameters' => $this -> getaParameters ($oFunc -> getParameters()) ); $aTmp['code'] = utf8_encode ($this -> getCode ($aTmp['file'], $aTmp['startline'], $aTmp['endline'])); $aTmp['returns'] = $this -> getReturns ($aTmp['comments']); $aTmp['params'] = $this -> getParams ($aTmp['comments']); return $aTmp; } /** * méthode privée getReturns * sert à récupérer le code pour la/les valeur/s de retour de la fonction, si elle est documentée * @Param string comments : contient une chaîne avec les commentaires de la méthode * @Return array aTmp : contient un tableau avec les retours possibles */ private function getReturns ($comments) { preg_match_all ('@\@return[s]?+(.+)@im', $comments, $res); $aTmp = $res[1]; return (array)$aTmp; } /** * méthode privée getParams * sert à récupérer le code pour le/les paramètre/s de la fonction, si elle est documentée * @Param string comments : contient une chaîne avec les commentaires de la méthode * @Return array aTmp : contient un tableau avec les paramètres possibles */ private function getParams ($comments) { preg_match_all ('@\@param[s]?+(.+)@im', $comments, $res); $aTmp = $res[1]; return (array)$aTmp; } /** * méthode privée getaParameters * sert à remplir le tableau des paramètres des fonctions * @Return : array aTmp */ private function getaParameters ($aArgs) { $aTmp = array (); if (!empty ($aArgs)) { foreach ($aArgs as $val) { $isArray = true === method_exists ($val, 'isArray')?$val -> isArray():false; $aTmp[$val -> getName ()] = array ( 'name' => $val -> getName (), 'reference' => $val -> isPassedByReference()?'&':'', 'array' => (true === $isArray)?'array':'', 'optional' => $val -> isOptional()?$this -> oloc -> getMsg ('doc', 'doc_optional'):$this -> oloc -> getMsg ('doc', 'doc_mandatory'), 'default' => (true === $val -> isDefaultValueAvailable())?$val -> getDefaultValue():'' ); } } return $aTmp; } } ?>