Générateur de doc XML pour classes
Créé la documentation d'une classe au format XML.
XMLClassDoc permet de générer de la documentation XML pour des classes PHP5.
Elle utilise l'API de réflection présentée dans cet article ainsi que l'extension xmlWriter décrite dans cet autre article.
le format de sortie est parametrable et permet soit de générer une doc complète soit un document conforme à la DTD de la documentation des classes utilisé ici même.
Il est possible de choisir l'encodage du fichier de sortie et d'ajouter une ou plusieurs feuilles de style.
Une méthode permet de forcer ou d'empècher l'annalyse des classes parentes et une autre permet de choisir de ne parser
que les membres publics.
Enfin on peux importer la description détaillée de la classe depuis un fichier texte.
Pour que la documentation soit générée correctement, les codes sources des classes doivent être
parfaitement commentés en utilisant les tags bien connus de
phpDocumentor.
Soit :
/**
* @tag xxxx
*/
Ci-dessous la liste des tags reconnus :
- @author
- @category
- @copyright
- @deprecated
- @desc
- @example
- @filesource
- @license
- @link
- @name
- @package
- @param
- @return
- @see
- @since
- @subpackage
- @todo
- @tutorial
- @var
- @version
Lors d'une génération pour une utilisation ici, les tags manquants seront signalés.
Bien que le générateur accepte aussi bien les sources encodés en UTF-8 ou ISO-8859-1 il est préférable pour CSP d'utiliser ISO-8859-1.
Les Méthodes
- void XMLClassDoc::setXML - Initialise le document XML
- void XMLClassDoc::setStyleSheet - Initialise la Feuille de style
- void XMLClassDoc::setlongdescFile - Chargement fichier longdesc
- void XMLClassDoc::setParseParent - setParseParent
- void XMLClassDoc::parseOnlyPublic - parseOnlyPublic
- void XMLClassDoc::toXMLFile - Générateur de fichier
- string XMLClassDoc::toXMLStr - Générateur de Chaine
- void XMLClassDoc::__construct - Constructeur
Exemples
La Source
/**
*
* @name docGen
* @desc Parse une classe PHP5 avec l'API de reflection.
*
* @package CSP doc
* @since 10-02-2007
* @author Fab - mcAllan
* @version 0.2
*
*
*/
abstract class docGen {
/**
* @desc Tableau des objets méthodes
* @var array method
*/
protected $method = array();
/**
* @desc Tableau des méthodes
* @var array methods
*/
protected $methods = array();
/**
* @desc Tableau des constantes
* @var array constant
*/
protected $constants = array();
/**
* @desc Tableau des propriétés
* @var array properties
*/
protected $properties = array();
/**
* @desc Tableau des tags reconnus
* @var array tags
*/
protected $tags = array(#'abstract', // class (?)
#'access', // property method (?)
'author', // class (*)
'category', // class (*)
'copyright', // class (*)
'deprecated', // class method (?)
'desc', // class property method (?)
'example', // method (*)
#'final', // class method (?)
'filesource', // class (?)
#'global', // ??
#'ignore', // ??
#'internal', // ??
'license', // class (*)
'link', // class property method (*)
'name', // class property method (?)
'package', // class (*)
'param', // method (*)
'return', // method (1)
'see', // class property method (*)
'since', // class property method (*)
#'static', // property method (?)
#'staticvar', // ??
'subpackage', // class (*)
'todo', // class (*)
'tutorial', // class (*)
#'uses', // class property method (*)
'var', // property (?)
'version'); // class (?)
/**
* @desc Tableau des tags multiples
* @var array multipleTags
*/
protected $multipleTags = array(
'author', // class (*)
'category', // class (*)
'copyright', // class (*)
'example', // method (*)
'license', // class (*)
'link', // class property method (*)
'package', // class (*)
'param', // method (*)
'see', // class property method (*)
'since', // class property method (*)
'subpackage', // class (*)
'todo', // class (*)
'tutorial'); // class (*)
/**
* @desc Tableau des types
* @var array type
*/
protected $type = array('int',
'string',
'float',
'boolean',
'object',
'array',
'resource',
'mixed');
/**
* @name Constructeur
* @desc Constructeur de la classe
* @example $docXML = new docGen('myClass')
*
* @param string $class classe à analyser
*
* @return void
*
*/
public function __construct($class) {
$this->className = $class;
$this->class = new ReflectionClass($class);
}
/**
* @name getClassName
* @desc Retourne le nom de la classe
*
* @return string
*
*/
protected function getClassName() {
return $this->className;
}
/**
* @name getClassComment
* @desc Retourne les commentaires sur la classe
* @since V0.1
*
* @return string
*
*/
protected function getClassComment() {
return $this->class->getDocComment();
}
/**
* @name getClassDefinition
* @desc Retourne la définition de la classe
*
* @return array
*
*/
protected function getClassDefinition() {
$T = array();
if($this->class->isInterface()) {
$T['interface'] = 'interface';
}
if($this->class->isAbstract()) {
$T['abstract'] = 'abstract';
}
if($this->class->isFinal()) {
$T['final'] = 'final';
}
return $T;
}
/**
* @name getProperties
* @desc Retourne les propriétés de la classe
*
* @return array
*
*/
protected function getProperties() {
if(empty($this->properties)) {
foreach($this->class->getProperties() as $prop) {
$this->properties[] = $prop;
$this->property[$prop->name] = new ReflectionProperty($this->className, $prop->name);
}
}
return $this->properties;
}
/**
* @name getPropertyValues
* @desc Retourne les types des propriétés de la classe
*
* @param string name le nom de la propriété
* @return array
*
*/
protected function getPropertyValues($name) {
$T = array();
if($this->property[$name]->isPublic()) {
$T['visibility'] = 'public';
}elseif($this->property[$name]->isPrivate()) {
$T['visibility'] = 'private';
}elseif($this->property[$name]->isProtected()) {
$T['visibility'] = 'protected';
}
else {
$T['visibility'] = '';
}
if($this->property[$name]->isStatic()) {
$T['static'] = 'static';
}
return $T;
}
/**
* @name getPropertyComment
* @desc Retourne les commentaires des propriétés de la classe
* @since V0.1
*
* @param string name le nom de la propriété
* @return string
*
*/
protected function getPropertyComment($name) {
return $this->property[$name]->getDocComment();
}
/**
* @name getConstants
* @desc Retourne les constantes de la classe
*
* @return array
*
*/
protected function getConstants() {
if(empty($this->constants)) {
$this->constants = $this->class->getConstants();
}
return $this->constants;
}
/**
* @name getMethods
* @desc Retourne les methodes de la classe
*
* @return array
*
*/
protected function getMethods() {
if(empty($this->methods)) {
foreach($this->class->getMethods() as $method) {
$this->method[$method->name] = new reflectionMethod($method->class, $method->name);
$this->methods[] = $method;
}
}
return $this->methods;
}
/**
* @name getMethodProperties
* @desc Retourne les propriétés d'une methode
*
* @param string methodName le nom de la méthode
* @return array
*
*/
protected function getMethodProperties($methodName) {
$T = array();
if($this->method[$methodName]->isConstructor()) {
$T['constructor'] = 'Constructeur de la classe';
}
// http://bugs.php.net/bug.php?id=32076
if($this->method[$methodName]->isDestructor()) {
//$T[] = 'Destructeur de la classe';
}
if($v = $this->getMethodVisibility($methodName)) {
$T['visibility'] = $v;
}
if($this->method[$methodName]->isFinal()) {
$T['final'] = 'final';
}
if($this->method[$methodName]->isAbstract()) {
$T['abstract'] = 'abstract';
}
if($this->method[$methodName]->isStatic()) {
$T['static'] = 'static';
}
return $T;
}
/**
* @name getMethodParameters
* @desc Retourne les paramètres d'une methode
*
* @param string methodName le nom de la méthode
* @return object ReflectionParameter
*
*/
protected function getMethodParameters($methodName) {
return $this->method[$methodName]->getParameters();
}
/**
* @name getMethodParametersValues
* @desc Retourne les valeurs des paramètres d'une methode
*
* @param object Parameters le paramètre
* @return array
*
*/
protected function getMethodParametersValues($parameter) {
$T = array();
if($parameter->isOptional()){
$T['optional'] = 'optional';
$T['value'] = $parameter->getDefaultValue();
}
return $T;
}
/**
* @name getMethodComment
* @desc Retourne les commentaires d'une methode
* @since V0.1
*
* @param string $methodName le nom de la methode
* @return string
*
*/
protected function getMethodComment($methodName) {
return $this->method[$methodName]->getDocComment();
}
/**
* @name getMethodVisibility
* @desc Retourne la visibilité d'une methode
*
* @param string $methodName le nom de la methode
* @return string
*
*/
protected function getMethodVisibility($methodName) {
if($this->method[$methodName]->isPublic()) {
return 'public';
}elseif($this->method[$methodName]->isPrivate()) {
return 'private';
}elseif($this->method[$methodName]->isProtected()) {
return 'protected';
}
return false;
}
/**
* @name getDeclaringClassName
* @desc Retourne le nom de la classe déclarant la méthode ou la prop.
* @since V0.2
*
* @param object $object méthode ou property.
* @return string
*
*/
protected function getDeclaringClassName($object){
$a = $object -> getDeclaringClass();
return $a -> name;
}
/**
* @name parseClassComment
* @desc Analyse les commentaires d'une classe
* @since V0.2
*
* @return array
*
*/
protected function parseClassComment(){
$T = array();
$C = $this->getClassComment();
if(!empty($C)){
$T= $this->parseComment($C);
}
return $T;
}
/**
* @name parseMethodComment
* @desc Analyse les commentaires d'une methode
* @since V0.2
*
* @param string name nom de la méthode
* @return array
*
*/
protected function parseMethodComment($name){
$T = array();
$C = $this->getMethodComment($name);
if(!empty($C)){
$T= $this->parseComment($C);
}
return $T;
}
/**
* @name parsePropertyComment
* @desc Analyse les commentaires d'une methode
* @since V0.2
*
* @param string name nom de la propriété
* @return array
*
*/
protected function parsePropertyComment($name){
$T = array();
$C = $this->getPropertyComment($name);
if(!empty($C)){
$T= $this->parseComment($C);
}
return $T;
}
/**
* @name parseComment
* @desc Analyseur d commentaires
* @since V0.2
*
* @param string C commentaire à analyser
* @return array
*
*/
protected function parseComment($C){
$T = array();
if(preg_match_all('`\* @('. implode( "|" , $this ->tags) . ')( .*)?$`Ums',trim($C),$comment)){
foreach($comment[1] as $key => $value){
if($value=='var'){
if(preg_match('`^('. implode( "|" , $this->type) . ') ([a-zA-Z0-9_\$]*)( .*)?`is',trim($comment[2][$key]),$V)){
$pname = trim(str_replace('$','',$V[2]));
$T['var'][$pname]['type'] = trim($V[1]);
$T['var'][$pname]['comment'] = (isset($V[3])) ? trim($V[3]): '';
}else{
$T['var'][] = 'Syntax error : @var '.$comment[2][$key];
}
}elseif($value=='param'){
if(preg_match('`^('. implode( "|" , $this->type) . ') ([a-zA-Z0-9_\$]*)( .*)?`is',trim($comment[2][$key]),$V)){
$pname = trim(str_replace('$','',$V[2]));
$T['param'][$pname]['type'] = trim($V[1]);
$T['param'][$pname]['comment'] = (isset($V[3])) ? trim($V[3]): '? NO_COMMENT ?';
}else{
$T['param'][] = 'Syntax error : @param '.$comment[2][$key];
}
}elseif(in_array($value,$this->multipleTags)){
$T[$value][] = trim($comment[2][$key]);
}else{
$T[$value] = trim($comment[2][$key]);
}
}
}
return $T;
}
}
#=====================================================================
/**
*
* @name Générateur de doc XML pour classes
* @desc Créé la documentation d'une classe au format XML.
*
* @package CSP doc
* @since 10-02-2007
* @author mcAllan
* @copyright http://classes.scriptsphp.org/
* @license GPL
* @version 0.2
*
* @example Utilisation pour afficher
* @example Utilisation pour un fichier
*
*/
class XMLClassDoc extends docGen {
/**
* @desc Nom du type de DTD
* @var string DTDTypeName (ie class)
* @since V 0.2
*/
private $DTDTypeName = 'root';
/**
* @desc Identification de la DTD
* @var string DTDIdent
* @since V 0.2
*/
private $DTDIdent = '-//NTE//XMLClasssDoc//FR';
/**
* @desc URL de la DTD
* @var string DTDUrl
* @since V 0.2
*/
private $DTDUrl = 'http://classes.scriptsphp.org/style/XMLClassDoc.dtd';
/**
* @desc Indique si on doit écrire le doctype
* @var boolean setDTD
* @since V 0.2
*/
private $setDTD = true;
/**
* @desc array des feuilles de style
* @var array styleSheets
* @since V 0.2
*/
private $styleSheets = array();
/**
* @desc Nombre de feuilles de style
* @var int styleSheetsCount
*/
private $styleSheetsCount = 0;
/**
* @desc Version XML du document généré.
* @var string XMLVersion
* @since V 0.2
*/
private $XMLVersion = '1.0';
/**
* @desc Encodage du fichier généré.
* @var int XMLEncoding
* @since V 0.2
*/
private $XMLEncoding = 'UTF-8';
/**
* @desc Objet XMLWriter
* @var object XML
* @since V 0.2
*/
private $XML;
/**
* @desc Indique si l'on doit documenter les classes parentes
* @var boolean parseParent
*/
private $parseParent = false;
/**
* @desc Signature générateur
* @var string parserComment
* @since V 0.2
*/
private $parserComment = 'Fichier généré par XMLClassDoc V0.2 - http://classes.scriptsphp.org/ - mcAllan 2007';
/**
* @desc Fichier texte de description longue
* @var string longDesc
* @since V 0.2
*/
private $longDesc = '';
/**
* @desc Indique si l'on parse tout ou seulement les membres publics
* @var boolean parseAll
* @since V 0.2
*/
private $parseAll = true;
/**
* @name Initialise le document XML
* @desc Initialise l'entête XML
* @since V 0.2
* @example $docXml -> setXML($version, $encoding)
*
* @param string version XML version (ie '1.0')
* @param string encoding encodage de sortie (ie 'UTF-8')
* @return void
*
*/
public function setXML($version = '1.0', $encoding = 'UTF-8'){
$this -> XMLVersion = $version;
$this -> XMLEncoding = $encoding;
}
/**
* @name Initialise la Feuille de style
* @desc Initialise les éléments de la Feuille de style
* @since V 0.2
* @example $docXml -> setStyleSheet($type, $url)
*
* @param string type de la CSS (ie 'text/css')
* @param string url URL de la CSS (ie 'http://classes.scriptsphp.org/style/MyCSS.css')
* @return void
*
*/
public function setStyleSheet($type, $url){
$this -> styleSheets[$this->styleSheetsCount]['type'] = $type;
$this -> styleSheets[$this->styleSheetsCount]['url'] = $url;
$this->styleSheetsCount ++;
}
/**
* @name Chargement fichier longdesc
* @desc Charge le fichier de description
* @since V 0.2
* @example $docXml -> setlongdescFile($file)
*
* @param string file nom du fichier
* @return void
*
*/
public function setlongdescFile($file = ''){
$this -> longDesc = file_get_contents($file);
}
/**
* @name setParseParent
* @desc Indique si on doit parcourir les classes parentes
* @example $docXml -> setParseParent(true)
* @since V 0.2
*
* @param boolean set vrai ou faux
* @return void
*
*/
public function setParseParent($set){
$this->parseParent = $set;
}
/**
* @name parseOnlyPublic
* @desc Indique si on doit parcourir seulement les membres Public
* @example $docXml -> parseOnlyPublic(true)
* @since V 0.2
*
* @param boolean set vrai ou faux
* @return void
*
*/
public function parseOnlyPublic($set){
$this->parseAll = !$set;
}
/**
* @name Générateur de fichier
* @desc Créé le fichier XML de la documentation
* @example $docXml -> toXMLFile('doc.xml')
*
* @param string format format de la sortie (CSP ou ALL)
* @param string file nom du fichier complet (par défaut : classeName.xml)
* @return void
*
*/
public function toXMLFile( $file='', $format='CSP' ) {
if(empty($file)) $file = $this->getClassName().'.xml';
// Init de XMLWriter
$this -> XML = new XMLWriter;
$this -> XML -> openUri($file);
$this -> XML->setIndent(true);
$this->generate($format);
$this -> XML -> flush();
}
/**
* @name Générateur de Chaine
* @desc Créé une chaine XML de la documentation
* @example $docXml -> toXMLStr('CSP')
*
* @param string format format de la sortie (CSP ou ALL)
* @return string
*
*/
public function toXMLStr( $format='CSP' ) {
// Init de XMLWriter
$this -> XML = new XMLWriter;
$this -> XML -> openMemory();
$this -> XML->setIndent(true);
$this->generate($format);
return $this -> XML -> flush();
}
/**
* @name Appel des générateurs en fonction du format
* @desc appelle le générateur qui va bien...
* @since V 0.2
* @example $docXML -> generate($format)
*
* @param string format format de la sortie (CSP ou ALL)
* @return void
*
*/
private function generate($format) {
switch($format){
case 'CSP' :
$this -> toXML4CSP();
break;
case 'ALL' :
$this -> toXMLAll();
break;
default :
$this -> toXML4CSP();
}
}
/**
* @name Générateur pour CSP
* @desc Créé la chaine XML de la documentation format CSP
* @example $docXml -> toXML4CSP
*
* @return void
*
*/
private function toXML4CSP() {
$C = $this->parseClassComment();
// Ecriture entête
$this -> XML -> startDocument('1.0', 'ISO-8859-1');
$this -> XML -> writePi('xml-stylesheet' , 'type="text/css" href="http://classes.scriptsphp.org/style/MyDoc.css"');
$this -> XML -> startDtd('class','-//NTE//MyDoc//FR', 'http://classes.scriptsphp.org/style/MyDoc.dtd');
$this -> XML -> endDtd();
$val = $this -> parserComment;
$this -> XML -> writeComment(mb_convert_encoding($val, "UTF-8", "UTF-8, ISO-8859-1"));
$this -> XML -> startElement ('class');
// Ecriture généralités classe
// Nom réel
$this -> XML -> writeElement('Class_real_name' , $this->getClassName());
// Nom @name
$val = (isset($C['name'])) ? $C['name'] : '? NO_CLASS_NAME ?';
$this -> XML -> writeElement('Class_name' , mb_convert_encoding($val, "UTF-8", "UTF-8, ISO-8859-1"));
// @author
//$val = implode(' - ', $C['author']);
$val = (isset($C['author'])) ? implode(' - ', $C['author']) : '? NO_AUTHOR ?';
$this -> XML -> writeElement('Class_auteur' , mb_convert_encoding($val, "UTF-8", "UTF-8, ISO-8859-1"));
// @version
$val = (isset($C['version'])) ? $C['version'] : '? NO_VERSION ?';
$this -> XML -> writeElement('Class_version' , mb_convert_encoding($val, "UTF-8", "UTF-8, ISO-8859-1"));
// @since
$val = (isset($C['since'])) ? $C['since'][0] : '? NO_DATE ?';
$this -> XML -> writeElement('Class_last_modified' , mb_convert_encoding($val, "UTF-8", "UTF-8, ISO-8859-1"));
// @desc
$val = (isset($C['desc'])) ? $C['desc'] : '? NO_DESC ?';
$this -> XML -> writeElement('Short_desc' , mb_convert_encoding($val, "UTF-8", "UTF-8, ISO-8859-1"));
// Emplacement pour description détaillée
$this -> XML -> writeComment('description longue, syntaxe wiki ... (wiki2xhtml)');
if(!empty($this->longDesc)){
$this -> XML -> writeElement('Long_desc' ,mb_convert_encoding($this->longDesc, "UTF-8", "UTF-8, ISO-8859-1"));
}else{
$this -> XML -> writeElement('Long_desc' ,"Copier ici la description format wiki2xhtml....");
}
// Traitement des méthodes
$this -> XML -> writeComment(mb_convert_encoding('Liste des méthodes publiques', "UTF-8", "UTF-8, ISO-8859-1"));
$M = $this->getMethods();
if(!empty($M)) {
// Parcourt des méthodes
foreach($M as $method) {
$pValues = $this->getMethodProperties($method->name);
$Comment = $this->parseMethodComment($method->name);
if($pValues['visibility']=='public'){
// Traitement des paramètres
$Param = $this->getMethodParameters($method->name);
$paramStr = '';
if(!empty($Param)) {
$stringArg = '( ';
// Parcourt des parametres
foreach($Param as $parameter) {
$P = $this->getMethodParametersValues($parameter);
if(isset($Comment['param'][$parameter->name])){
$str = $Comment['param'][$parameter->name]['type'].' '.$parameter->name;
if(isset($P['value'])) {
$str = '[ '.$str .' ] ';
}
$stringArg .= $str;
}
}
$stringArg .= ' )';
}else{
$stringArg = '()';
}
// Ecriture entête des méthodes
$this -> XML -> startElement('Methods');
// @name
$val = (isset($Comment['name'])) ? $Comment['name'] : '? NO_METHOD_NAME ?';
$this -> XML -> writeAttribute('Name' , mb_convert_encoding($val, "UTF-8", "UTF-8, ISO-8859-1"));
// Appel méthode
$val = (isset($Comment['return'])) ? $Comment['return'] : '? TYPE ?';
$functCall = $val.' '.$this->getClassName().'::'.$method->name.$stringArg;
$this -> XML -> writeElement('Func_name' , mb_convert_encoding($functCall, "UTF-8", "UTF-8, ISO-8859-1"));
// @desc
$val = (isset($Comment['desc'])) ? $Comment['desc'] : '? NO_METHOD_DESC ?';
$this -> XML -> writeElement('Desc' , mb_convert_encoding($val, "UTF-8", "UTF-8, ISO-8859-1"));
// @exemple
if(!isset($Comment['example'])) $Comment['example'][] = '? NO_CODE ?';
foreach($Comment['example'] as $exemple){
$this -> XML -> writeElement('Code' , mb_convert_encoding($exemple, "UTF-8", "UTF-8, ISO-8859-1"));
}
// Ecriture des paramètres
if(!empty($Param)) {
foreach($Param as $parameter) {
$this -> XML -> startElement('Params');
// Nom
$this -> XML -> writeAttribute('name' , mb_convert_encoding($parameter->name, "UTF-8", "UTF-8, ISO-8859-1"));
// @param
$P = $this->getMethodParametersValues($parameter);
$val = (isset($Comment['param'][$parameter->name]['comment'])) ? $Comment['param'][$parameter->name]['comment'] : '? NO_COMMENT ?';
if(isset($P['value'])) {
$val .= ' default : '.$P['value'];
}
$this -> XML -> Text(mb_convert_encoding($val, "UTF-8", "UTF-8, ISO-8859-1"));
$this -> XML -> endElement();
}
}
$this -> XML -> endElement();
$this -> XML -> writeComment(' ... ');
}
}
}
// Ecriture des exemples
if(isset($C['example'])){
foreach($C['example'] as $k => $exemple){
$this -> XML -> startElement('Examples');
$this -> XML -> writeAttribute('Name' , mb_convert_encoding($exemple, "UTF-8", "UTF-8, ISO-8859-1"));
$this -> XML -> endElement();
}
}
$this -> XML -> endElement ();
}
/**
* @name Générateur complet
* @desc Créé le XML complet de la documentation
* @since V 0.2
* @example $docXml -> toXMLAll()
*
* @return void
*
*/
private function toXMLAll() {
$C = $this->parseClassComment();
$r = '';
//------------------
// Ecriture entête document
//------------------
$this -> XML -> startDocument($this -> XMLVersion, $this -> XMLEncoding);
if($this -> styleSheetsCount != 0){
foreach($this -> styleSheets as $sheet){
$type = $sheet['type'];
$url = $sheet['url'];
$this -> XML -> writePi('xml-stylesheet' , 'type="'.$type.'" href="'.$url.'"');
}
}
if($this -> setDTD){
$this -> XML -> startDtd($this -> DTDTypeName, $this -> DTDIdent, $this -> DTDUrl);
$this -> XML -> endDtd();
}
$this -> XML -> text ("\n");
$val = $this -> parserComment;
$this -> XML -> writeComment(mb_convert_encoding($val, "UTF-8", "UTF-8, ISO-8859-1"));
$this -> XML -> startElement ('root');
//------------------
// Ecriture entête classe
//------------------
$this -> XML -> startElement ('class');
$this -> XML -> writeAttribute('name' , $this->getClassName());
foreach($this->getClassDefinition() as $key => $v) {
$this -> XML -> writeAttribute($key , '1');
}
if(!empty($C)){
//$this -> XML -> startElement ('comments');
foreach($C as $name=>$comment){
if($name == 'name') $name = 'ctitle';
if(!is_array($comment)){
$this -> XML -> writeElement($name,mb_convert_encoding($comment, "UTF-8", "UTF-8, ISO-8859-1"));
}else{
foreach($comment as $example){
$this -> XML -> writeElement($name,mb_convert_encoding($example, "UTF-8", "UTF-8, ISO-8859-1"));
}
}
}
//$this -> XML -> endElement(); // comments
$this -> XML -> startElement ('longdesc');
if(!empty($this->longDesc)){
$this -> XML -> text(mb_convert_encoding($this->longDesc, "UTF-8", "UTF-8, ISO-8859-1"));
}else{
$this -> XML -> text("Copy here the long desc");
}
$this -> XML -> endElement(); //longdesc
}
$this -> XML -> endElement(); //class
//---------------------------
// Propriétés de la classe
//---------------------------
$P = $this->getProperties();
if(!empty($P)) {
$this -> XML -> startElement('properties');
foreach($P as $prop => $Pvalue) {
$C = $this -> parsePropertyComment($Pvalue->name);
$PV = $this->getPropertyValues($Pvalue->name);
if(($this->getDeclaringClassName($Pvalue) == $this->className || $this->parseParent) && ($PV['visibility'] == 'public' || $this->parseAll)) {
$Com = $this->getPropertyComment($Pvalue->name);
$this -> XML -> startElement('property');
$this -> XML -> writeAttribute('name', $Pvalue->name);
$this -> XML -> writeAttribute('visibility', $PV['visibility']);
if(isset($PV['static'])) {
$this -> XML -> writeAttribute('static', '1');
}
if(isset($C['var'][$Pvalue->name]['type'])){
$this -> XML -> writeAttribute('type', $C['var'][$Pvalue->name]['type']);
}
if(!empty($C)){
//$this -> XML -> startElement ('comments');
foreach($C as $name=>$comment){
if($name == 'name') $name = 'ctitle';
if($name != 'var' && !is_array($comment)){
$this -> XML -> writeElement($name,mb_convert_encoding($comment, "UTF-8", "UTF-8, ISO-8859-1"));
}elseif($name == 'var' && !empty($comment[$Pvalue->name]['comment'])){
$this -> XML -> writeElement('comment',mb_convert_encoding($comment[$Pvalue->name]['comment'], "UTF-8", "UTF-8, ISO-8859-1"));
}elseif($name != 'var'){
foreach($comment as $example){
$this -> XML -> writeElement($name,mb_convert_encoding($example, "UTF-8", "UTF-8, ISO-8859-1"));
}
}
}
//$this -> XML -> endElement(); // comments
}
$this -> XML -> endElement(); // property
}
}
$this -> XML -> endElement(); // properties
}
// Constantes de la classe
$C = $this->getConstants();
if(!empty($C)) {
$this -> XML -> startElement ('constants');
$r .= '<constants>';
foreach($C as $name => $value) {
$this -> XML -> startElement('constant');
$this -> XML -> writeAttribute('name',$name);
$this -> XML -> text(mb_convert_encoding($value, "UTF-8", "UTF-8, ISO-8859-1"));
$this -> XML -> endElement(); //constant
}
$this -> XML -> endElement(); //constants
}
// Méthodes de la classe
$M = $this->getMethods();
if(!empty($M)) {
$this -> XML -> startElement ('methods');
foreach($M as $method) {
$pValues = $this->getMethodProperties($method->name);
if(($this->getDeclaringClassName($method) == $this->className || $this->parseParent) && ($pValues['visibility'] == 'public' || $this->parseAll)) {
$C = $this -> parseMethodComment($method->name);
$this -> XML -> startElement ('method');
$this -> XML -> writeAttribute('name',$method->name);
$this -> XML -> writeAttribute('visibility',$pValues['visibility']);
if(isset($pValues['static'])) {
$this -> XML -> writeAttribute('static', '1');
}
if(isset($pValues['final'])) {
$this -> XML -> writeAttribute('final', '1');
}
if(isset($pValues['abstract'])) {
$this -> XML -> writeAttribute('abstract', '1');
}
if(isset($C['return'])) {
$this -> XML -> writeAttribute('return', mb_convert_encoding($C['return'], "UTF-8", "UTF-8, ISO-8859-1"));
}
#$this -> XML -> startElement ('comments');
foreach($C as $name=>$comment){
if($name != 'param' && $name != 'return'){
if($name == 'name') $name = 'ctitle';
if(!is_array($comment)){
$this -> XML -> writeElement($name,mb_convert_encoding($comment, "UTF-8", "UTF-8, ISO-8859-1"));
}else{
foreach($comment as $example){
$this -> XML -> writeElement($name,mb_convert_encoding($example, "UTF-8", "UTF-8, ISO-8859-1"));
}
}
}
}
#$this -> XML -> endElement(); //comments
$Param = $this->getMethodParameters($method->name);
if(!empty($Param)) {
foreach($Param as $parameter) {
$P = $this->getMethodParametersValues($parameter);
$this -> XML -> startElement ('parameter');
$this -> XML -> writeAttribute('name',$parameter->name);
if(isset($C['param'][$parameter->name]['type'])){
$this -> XML -> writeAttribute('type',$C['param'][$parameter->name]['type']);
}
if(isset($P['value'])) {
$this -> XML -> writeElement('default',mb_convert_encoding($P['value'], "UTF-8", "UTF-8, ISO-8859-1"));
}
if(isset($C['param'][$parameter->name]['comment'])){
$this -> XML -> writeElement('comment',mb_convert_encoding($C['param'][$parameter->name]['comment'], "UTF-8", "UTF-8, ISO-8859-1"));
}
$this -> XML -> endElement(); //parameter
}
}
$this -> XML -> endElement(); // method
}
}
$this -> XML -> endElement();// methods
}
$r .= '</root>';
$this -> XML -> endElement(); //root
}
}
?>