PHP Classes
Icontem

File: class/odocfunc.cls.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Johan Barbier  >  Class Doc  >  class/odocfunc.cls.php  
File: class/odocfunc.cls.php
Role: Class source
Content type: text/plain
Description: Functions documentation class
Class: Class Doc
Generate PHP code documentation in multiple idioms
 

Contents

Class file image Download
<?php
/**
* CLASS odocfunc
* classe de documentation de fonctions
* auteur : johan <barbier_johan@hotmail.com>
* 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;
    }
}
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products