81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?php
|
|
class Zend_View_Helper_DocParameter extends Zend_View_Helper_Abstract
|
|
{
|
|
protected $serviceTypes;
|
|
|
|
protected $types = array(
|
|
'string', 'str',
|
|
'boolean', 'bool',
|
|
'int', 'integer', 'long',
|
|
'float', 'double',
|
|
'array', 'object', 'mixed'
|
|
);
|
|
|
|
protected $_transcodeType = array(
|
|
'str' => 'string',
|
|
'bool' => 'boolean',
|
|
'integer' => 'int',
|
|
);
|
|
|
|
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 = '';
|
|
$type = str_replace('[]', '', $type);
|
|
if (array_key_exists($type, $this->serviceTypes)) {
|
|
$types = $this->serviceTypes[$type];
|
|
$output.= '<ul>';
|
|
foreach ($types as $param) {
|
|
$output.= $this->formatParam($param);
|
|
}
|
|
$output.= '</ul>';
|
|
} elseif (in_array($type, $this->types)) {
|
|
$output.= '';
|
|
} elseif ($type == 'void') {
|
|
$output.= 'Void';
|
|
} else {
|
|
$output.= ' => <b>Type '.$type.' inconnu</b>';
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
private function formatParam($param)
|
|
{
|
|
$output = '';
|
|
$output.= '<li>';
|
|
$output.= '<i>' . $this->transcodeType($param['type']) . '</i>';
|
|
$output.= ' ';
|
|
$output.= '<b>' . $param['name'] . '</b>';
|
|
if (isset($param['description']) && !empty($param['description'])) {
|
|
$output.= ' - '.$param['description'];
|
|
}
|
|
if (!in_array($param['type'], $this->types)) {
|
|
$output.= $this->parseType($param['type']);
|
|
}
|
|
$output.= '</li>';
|
|
return $output;
|
|
}
|
|
|
|
private function transcodeType($type)
|
|
{
|
|
if (array_key_exists($type, $this->_transcodeType)) {
|
|
return $this->_transcodeType[$type];
|
|
} else {
|
|
return $type;
|
|
}
|
|
}
|
|
}
|