149 lines
4.6 KiB
PHP
149 lines
4.6 KiB
PHP
<?php
|
|
|
|
class WebClassDoc
|
|
{
|
|
private $serviceClass;
|
|
|
|
private $classmap = array();
|
|
|
|
private $serviceMethods = array();
|
|
|
|
private $serviceTypes = array();
|
|
|
|
public function __construct($serviceClass = null, $classmap = null)
|
|
{
|
|
$this->serviceClass = $serviceClass;
|
|
$this->classmap = $classmap;
|
|
require_once 'WsScore/' . $this->serviceClass . '.php';
|
|
$this->parseService();
|
|
$this->parseTypes();
|
|
}
|
|
|
|
/**
|
|
* Retourne la liste des services et leurs paramètres
|
|
* @return array
|
|
*/
|
|
public function getServiceMethods()
|
|
{
|
|
return $this->serviceMethods;
|
|
}
|
|
|
|
/**
|
|
* Retourne la liste des types de données et leurs paramètres
|
|
* @return array
|
|
*/
|
|
public function getServiceTypes()
|
|
{
|
|
return $this->serviceTypes;
|
|
}
|
|
|
|
private function parseService()
|
|
{
|
|
$class = new Zend_Server_Reflection();
|
|
$methods = $class->reflectClass($this->serviceClass)
|
|
->getMethods();
|
|
$methodsElement = array();
|
|
foreach ($methods as $method) {
|
|
|
|
$prototype = null;
|
|
$maxNumArgumentsOfPrototype = -1;
|
|
foreach ($method->getPrototypes() as $tmpPrototype) {
|
|
$numParams = count($tmpPrototype->getParameters());
|
|
if ($numParams > $maxNumArgumentsOfPrototype) {
|
|
$maxNumArgumentsOfPrototype = $numParams;
|
|
$prototype = $tmpPrototype;
|
|
}
|
|
}
|
|
|
|
$paramsElement = array();
|
|
foreach ($prototype->getParameters() as $param) {
|
|
$paramElement = array(
|
|
'type' => $param->getType(),
|
|
'name' => $param->getName(),
|
|
'description' => $param->getDescription(),
|
|
|
|
);
|
|
if ($param->isOptional()){
|
|
$paramElement['optional'] = $param->isOptional();
|
|
$paramElement['defaultValue'] = $param->getDefaultValue();
|
|
}
|
|
$paramsElement[] = $paramElement;
|
|
}
|
|
|
|
$methodElement = array(
|
|
'name' => $method->getName(),
|
|
'desc' => $method->getDescription(),
|
|
'params' => $paramsElement,
|
|
'return' => $prototype->getReturnType(),
|
|
);
|
|
|
|
$methodsElement[] = $methodElement;
|
|
}
|
|
$this->serviceMethods = $methodsElement;
|
|
}
|
|
|
|
private function parseTypes()
|
|
{
|
|
$typesElement = array();
|
|
foreach ($this->classmap as $className) {
|
|
$class = new ReflectionClass($className);
|
|
$paramsElement = array();
|
|
foreach ($class->getProperties() as $property) {
|
|
if ($property->isPublic() && preg_match_all('/@var\s+([^\s]+)/m', $property->getDocComment(), $matches)) {
|
|
|
|
$name = $property->getName();
|
|
$type = $matches[1][0];
|
|
|
|
/**
|
|
* Traitement éléments de documentation à placer dans le WSDL
|
|
* Supprime les retours chariots.
|
|
* Récupére les éléments de documentation
|
|
*/
|
|
$comment = '';
|
|
$docBlock = preg_replace('/\n/', '', $property->getDocComment() );
|
|
if (preg_match('/\/\*\*(.+) \* @var\s+[^\s]+\s+(?:\*|@)/m', $docBlock, $docBlockMatches)) {
|
|
$comment.= preg_replace(
|
|
array('/\r/', '/\t\s\*/'),
|
|
array('', ''), $docBlockMatches[1]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Traitement des références
|
|
* @ref fichier:titre:nom_du_fichier
|
|
* => http://vhost/ref/fichier/
|
|
* @ref mysql:titre:requete.sql
|
|
* => http://vhost/ref/table/
|
|
*/
|
|
if (preg_match_all('/@ref\s+(fichier|mysql):(.*):(.*)\.(?:csv|sql)\s+(?:\*|@)/m', $property->getDocComment(), $refMatches, PREG_SET_ORDER)){
|
|
$urlFichier = 'ref/fichier';
|
|
$urlMysql = 'ref/table';
|
|
$comment.= ', Référence(s) : ';
|
|
foreach ($refMatches as $ref){
|
|
switch ($ref[1]){
|
|
case 'fichier':
|
|
$comment.= '<a href="'.$urlFichier.'?q='.$ref[3].'">'.$ref[2].'</a>';
|
|
break;
|
|
case 'mysql':
|
|
$comment.= '<a href="'.$urlMysql.'?q='.$ref[3].'">'.$ref[2].'</a>';
|
|
break;
|
|
}
|
|
$comment.= ', ';
|
|
}
|
|
}
|
|
$paramElement = array(
|
|
'name' => $name,
|
|
'type' => $type,
|
|
'description' => trim($comment)
|
|
);
|
|
|
|
}
|
|
$paramsElement[] = $paramElement;
|
|
}
|
|
$typesElement[$className] = $paramsElement;
|
|
}
|
|
$this->serviceTypes = $typesElement;
|
|
}
|
|
|
|
}
|