60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
class Zend_View_Helper_DocMethod extends Zend_View_Helper_Abstract
|
|
{
|
|
|
|
protected $_transcodeType = array(
|
|
'str' => 'string',
|
|
'bool' => 'boolean',
|
|
'int' => 'integer',
|
|
);
|
|
|
|
public function docMethod($method)
|
|
{
|
|
$output = '';
|
|
|
|
$returnType = $method['return'];
|
|
$methodName = $method['name'];
|
|
|
|
$cptParameters = 0;
|
|
$parameters = '';
|
|
foreach ($method['params'] as $param) {
|
|
if (isset($param['optional'])) {
|
|
$parameters.= '[';
|
|
}
|
|
$parameters.= '<i>' . $this->transcodeType($param['type']) . '</i>';
|
|
$parameters.= ' ';
|
|
$parameters.= '<b>' . $param['name'] . '</b>';
|
|
|
|
if (isset($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 = '<i>' . $this->transcodeType($returnType) . '</i>';
|
|
$output.= ' ';
|
|
$output.= '<b>' . $methodName . '</b>' . ' <b>(</b> ' . $parameters . ' <b>)</b>';
|
|
return $output;
|
|
}
|
|
|
|
private function transcodeType($type)
|
|
{
|
|
if(array_key_exists($type, $this->_transcodeType)){
|
|
return $this->_transcodeType[$type];
|
|
} else {
|
|
return $type;
|
|
}
|
|
}
|
|
|
|
}
|