Ajout helpers pour afficher la documentation du service, issue #0000339

This commit is contained in:
Michael RICOIS 2010-09-17 14:48:06 +00:00
parent 21c381840b
commit 4c96305413
4 changed files with 148 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?php
class Zend_View_Helper_DocDescription extends Zend_View_Helper_Abstract
{
public function docDescription($method)
{
return $method['desc'];
}
}

View File

@ -0,0 +1,41 @@
<?php
class Zend_View_Helper_DocMethod extends Zend_View_Helper_Abstract
{
public function docMethod($method)
{
$output = '';
$returnType = $method['return'];
$methodName = $method['name'];
$cptParameters = 0;
$parameters = '';
foreach ($method['params'] as $param) {
if ($param['optional']) {
$parameters.= '[';
}
$parameters.= $param['type'];
$parameters.= '&nbsp;';
$parameters.= $param['name'];
if ($param['optional']) {
if (isset($param['defaultValue'])) {
$parameters.= ' = ';
if (is_bool($param['defaultValue'])){
$parameters.= ($param['defaultValue'] === false) ? 'false' : 'true' ;
} else {
$parameters.= $param['defaultValue'];
}
}
$parameters.= ']';
}
$cptParameters++;
if ($cptParameters < count($method['params'])){
$parameters.= ', ';
}
}
$output = $returnType . ' ' . $methodName . ' ( ' . $parameters . ' )';
return $output;
}
}

View File

@ -0,0 +1,54 @@
<?php
class Zend_View_Helper_DocParameter extends Zend_View_Helper_Abstract
{
protected $serviceTypes;
public function docParameter($params, $serviceTypes)
{
$this->serviceTypes = $serviceTypes;
$output = '';
if (count($params)>0) {
$output.= '<ul>';
foreach ($params as $param) {
$output.= $this->formatParam($param);
}
$output.= '</ul>';
}
return $output;
}
private function parseType($type)
{
$output = '';
if (array_key_exists($type, $this->serviceTypes)) {
$types = $this->serviceTypes[$type];
$output.= '<ul>';
foreach ($types as $param) {
$output.= $this->formatParam($param);
}
$output.= '</ul>';
}
return $output;
}
private function formatParam($param)
{
$output = '';
$output.= '<li>';
$output.= $param['type'] . ' ' . $param['name'];
if (isset($param['description']) && !empty($param['description'])) {
$output.= ' : '.$param['description'];
}
if (!in_array($param['type'], array(
'string', 'str',
'boolean', 'bool',
'interger', 'int',
'float', 'double',
'array', 'object', 'mixed'))) {
$output.= $this->parseType($param['type']);
}
$output.= '</li>';
return $output;
}
}

View File

@ -0,0 +1,45 @@
<?php
class Zend_View_Helper_DocReturn extends Zend_View_Helper_Abstract
{
protected $serviceTypes;
public function docReturn($type, $serviceTypes)
{
$this->serviceTypes = $serviceTypes;
return $this->parseType($type);
}
private function parseType($type)
{
$output = '';
if (array_key_exists($type, $this->serviceTypes)) {
$types = $this->serviceTypes[$type];
$output.= '<ul>';
foreach ($types as $param) {
$output.= $this->formatParam($param);
}
$output.= '</ul>';
}
return $output;
}
private function formatParam($param){
$output = '';
$output.= '<li>';
$output.= $param['type'] . ' ' . $param['name'];
if (isset($param['description']) && !empty($param['description'])) {
$output.= ' : '.$param['description'];
}
if (!in_array($param['type'], array(
'string', 'str',
'boolean', 'bool',
'interger', 'int',
'float', 'double',
'array', 'object', 'mixed'))) {
$output.= $this->parseType($param['type']);
}
$output.= '</li>';
return $output;
}
}