PHP Classes
Icontem

File: class/odocclass.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/odocclass.cls.php  
File: class/odocclass.cls.php
Role: Class source
Content type: text/plain
Description: classes documentation
Class: Class Doc
Generate PHP code documentation in multiple idioms
 

Contents

Class file image Download
<?php
/**
* CLASS odocclass
* classe de documentation de classes
* @auteur : johan <barbier_johan@hotmail.com>
* @version : 2.4
* @date : 2006/02/10
*
* free to use, modify, please just tell me if you make any changes :-)
*/
class odocclass extends ReflectionClass {

	/**
	* propriété qui contiendra l'objet olocale pour la localisation
	*/
	private $oloc;
	/**
	* tableau des propriétés générales
	*/
	private $aGeneral = array ();
	/**
	* tableau des propriétés des méthodes
	*/
	private $aMethods = array ();
	/**
	* tableau des propriétés des propriétés
	*/
	private $aProperties = array ();
	/**

	/**
	* tableau buffer des lignes des fichiers codes
	*/
	private $fileBuf = array ();

	/**
	* tableau des classes et de leurs enfants d'un package
	*/
	private $aChild = array ();

	/**
	* chaîne qui contiendra le nom du package
	*/
	private $package = '';

	/**
	* constructeur
	* @Params string className : nom de la classe à analyser
	* @Params string child : nom de la classe fille appelante, héritant de la classe courante
	*/
	public function __construct ($package, array $aArbo) {
		$this -> oloc = new olocale ($_SESSION['locale']);
		$this -> package = $package;
		$this -> aArbo = $aArbo;
		foreach ($this -> aArbo as $className => $dump) {
			$this -> aChild[$className]['children'] = array ();
			foreach ($aArbo as $clef => $val) {
				if ($className === $val['parent']) {
					$this -> aChild[$className]['children'][] = $clef;
				}
			}
			parent::__construct ($className);
			$this -> aGeneral = $this -> getGeneral ();
			$this -> aMethods = $this -> getaMethods ();
			$this -> aProperties = $this -> getaProperties ();
			if (empty ($this -> aGeneral['classe'])) {
				if (empty ($this -> aArbo[$className]['parent'])) {
					$parent = '';
				} else {
					$parent = $this -> aGeneral['classe'] = $this -> aArbo[$className]['parent'];
					$this -> aGeneral['classeType'] = 'interface';
				}
			} else {
				$parent = $this -> aGeneral['classe'];
			}
			$this -> aChild[$className]['parent'] = $parent;
			$this -> buildHtmlClass ();
		}
		$ohtml = new ohtml ($this -> package);
		$ohtml -> setIndexPack ($this -> aChild);
	}

	/**
	* méthode privée buildHtmlClass
	* appelle l'objet ohtml pour construire effectivement la doc pour les classes
	*/
	private function buildHtmlClass () {
		$ohtml = new ohtml ($this -> package);
		$ohtml -> header ();
		$ohtml -> setMenu ($this -> aGeneral['name'], $this -> aGeneral['classe'], $this -> aChild[$this -> aGeneral['name']]['children'], $this -> aMethods, $this -> aProperties);
		$ohtml -> setContentGeneral ($this -> aGeneral);
		$ohtml -> footer ();
		$ohtml -> toFileClass ($this -> aGeneral['name'], $this -> aGeneral['name']);
		$ohtml -> freeHtml ();
		foreach ($this -> aMethods as $clef => $val) {
			$ohtml -> header ();
			$ohtml -> setMenu ($this -> aGeneral['name'], $this -> aGeneral['classe'], $this -> aChild[$this -> aGeneral['name']]['children'], $this -> aMethods, $this -> aProperties, $clef);
			$ohtml -> setContentMethods ($val);
			$ohtml -> footer ();
			$ohtml -> toFileMethProps ($this -> aGeneral['name'], $clef);
			$ohtml -> freeHtml ();
		}
		foreach ($this -> aProperties as $clef => $val) {
			$ohtml -> header ();
			$ohtml -> setMenu ($this -> aGeneral['name'], $this -> aGeneral['classe'], $this -> aChild[$this -> aGeneral['name']]['children'], $this -> aMethods, $this -> aProperties, $clef);
			$ohtml -> setContentProperties ($val);
			$ohtml -> footer ();
			$ohtml -> toFileMethProps ($this -> aGeneral['name'], $clef);
			$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 (!empty ($filename)) {
			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 getGeneral
	* sert à remplir le tableau des propriétés générales de la classe à analyser
	* @Return : array aTmp
	*/
	private function getGeneral () {
		$aTmp['name'] = $this -> getName ();
		$aTmp['type'] = $this ->  isInternal () ? 'internal' : 'user-defined';
		$aTmp['abstract'] = $this -> isAbstract () ? 'abstract' : '';
		$aTmp['interface'] = $this -> isInterface () ? 'interface' : 'class';
		$aTmp['file'] = $this -> getFileName();
		$aTmp['startline'] = $this -> getStartLine();
		$aTmp['endline'] = $this -> getEndLine();
		$aTmp['code'] = utf8_encode ($this -> getCode ($aTmp['file'], $aTmp['startline'], $aTmp['endline']));
		$aTmp['final'] =  $this -> isFinal () ? ' final' : '';
		$aTmp['comments'] = method_exists ($this, 'getDocComment')?utf8_encode (htmlentities($this -> getDocComment ())):$this -> oloc -> getMsg ('errors', 'php_bad_version');
		$aTmp['total methods'] = count ($this -> getMethods ());
		$aTmp['total properties'] = count ($this -> getProperties ());
		$parent = $this -> getParentClass();
		if (is_object ($parent)) {
			$name = $parent -> getName ();
			$parentType = $parent -> isInterface ()?'interface':'class';
		} else {
			$name = '';
			$parentType = '';
		}
		$aTmp['classe'] = $name;
		$aTmp['classeType'] = $parentType;

		if (!empty ($aTmp)) {
			return $aTmp;
		} else {
			return array ();
		}
	}

	/**
	* méthode privée getMethods
	* sert à remplir le tableau des propriétés des méthodes de la classe à analyser
	* @Return : array aTmp
	*/
	private function getaMethods () {
		foreach ($this -> getMethods () as $val) {
			$aTmp[$val -> getName ()] = array (
				  'name' =>  $val->getName (),
				  'type' =>  $val->isInternal() ? 'internal' : 'user-defined',
				   'abstract' => $val->isAbstract() ? ' abstract' : '',
				   'final' => $val->isFinal() ? ' final' : '',
				   'public' => $val->isPublic() ? ' public' : '',
				   'private' => $val->isPrivate() ? ' private' : '',
				   'protected' => $val->isProtected() ? ' protected' : '',
				   'static' => $val->isStatic() ? ' static' : '',
				   'constructor' => $val->isConstructor()?'constructor':($val -> isDestructor()?'destructor':'regular method'),
				   'file' => $val->getFileName(),
				   'startline' => $val->getStartLine(),
				   'endline' => $val->getEndline(),
				   'code' => utf8_encode ($this -> getCode ($val->getFileName(), $val->getStartLine(), $val->getEndline())),
 				   'modifiers' => $val->getModifiers(). ' => '.implode(' ', Reflection::getModifierNames($val->getModifiers())),
 				   'comments' => method_exists ($val, 'getDocComment')?utf8_encode (htmlentities($val -> getDocComment ())):$this -> oloc -> getMsg ('errors', 'php_bad_version'),
 				   'statics' => $val->getStaticVariables(),
 				   'classe' => $val -> getDeclaringClass() -> getName (),
 				   'parameters' => $this -> getaParameters ($val -> getParameters())
				);
			$aTmp[$val -> getName ()]['returns'] = $this -> getReturns ($aTmp[$val -> getName ()]['comments']);
			$aTmp[$val -> getName ()]['params'] = $this -> getParams ($aTmp[$val -> getName ()]['comments']);
		}
		if (!empty ($aTmp)) {
			return $aTmp;
		} else {
			return array ();
		}
	}

	/**
	* méthode privée getReturns
	* sert à récupérer le code pour la/les valeur/s de retour de la méthode, 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 méthode, 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 méthodes
	* @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' => ($isArray)?'array':'',
					'optional' => $val -> isOptional()?$this -> oloc -> getMsg ('doc', 'doc_optional'):$this -> oloc -> getMsg ('doc', 'doc_mandatory'),
					'default' => ($val -> isDefaultValueAvailable())?$val -> getDefaultValue():''
					);
			}
		}
		if (!empty ($aTmp)) {
			return $aTmp;
		} else {
			return array ();
		}
	}

	/**
	* méthode privée getGeneral
	* sert à remplir le tableau des propriétés des propriétés de la classe à analyser
	* @Return : array aTmp
	*/
	private function getaProperties () {
		foreach ($this -> getProperties () as $val) {
			$aTmp[$val -> getName ()] = array (
				  'name' =>  $val->getName (),
				   'public' => $val -> isPublic()?'public':'',
				   'private' => $val -> isPrivate()?'private':'',
				   'protected' => $val -> isProtected()?'protected':'',
				   'static' => $val -> isStatic()?'static':'',
				   'default' => $val -> isDefault()?$this -> oloc -> getMsg ('doc', 'doc_yes'):$this -> oloc -> getMsg ('doc', 'doc_no'),
				   'modifiers' => $val->getModifiers(). ' => '.implode(' ', Reflection::getModifierNames($val->getModifiers())),
				   'comments' => method_exists ($val, 'getDocComment')?utf8_encode (htmlentities  ($val -> getDocComment ())):$this -> oloc -> getMsg ('errors', 'php_bad_version'),
				   'classe' => $val -> getDeclaringClass() -> getName (),
				   'code' => utf8_encode ($this -> getPropsCode ($val -> getDeclaringClass() -> getFileName (), $val -> getName())),
				);
			$aTmp[$val -> getName ()]['defaultvalue'] = ltrim (strstr ($aTmp[$val -> getName ()]['code'], '='), '=');
		}
		if (!empty ($aTmp)) {
			return $aTmp;
		} else {
			return array ();
		}
	}

	/**
	* méthode privée getPropsCode
	* sert à récupérer la portin de code où est définie une propriété donnée
	* @Params string fileName : nom du fichier où est définie la propriété
	* @Params string name : nom de la propriété
	* @Return : string code en cas de succès, false en cas d'échec
	*/
	private function getPropsCode ($fileName, $name) {
		if (!empty ($fileName)) {
			if (!array_key_exists ($fileName, $this -> fileBuf)) {
				$this -> fileBuf[$fileName] = file ($fileName);
			}
			$cpt = count ($this -> fileBuf[$fileName]);
			for ($i = 0; $i < $cpt; $i++) {
				if (false !== strpos ($this -> fileBuf[$fileName][$i], $name)) {
					$start = $i;
					break;
				}
			}
			if (isset ($start)) {
				for ($i = $start; $i < $cpt; $i++) {
					if (false !== strpos ($this -> fileBuf[$fileName][$i], ';')) {
						$end = $i;
						break;
					}
				}
			}
			if (isset ($end) && isset ($start)) {
				$code = '';
				for ($i = $start; $i <= $end; $i++) {
					$code .= $this -> fileBuf[$fileName][$i];
				}
				return $code;
			}
		}
		return false;
	}

}
?>

 
  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