<?php
class Zend_Server_Method_Prototype
{
protected $_returnType = 'void';
protected $_parameterNameMap = array();
protected $_parameters = array();
public function __construct($options = null)
{
if ((null !== $options) && is_array($options)) {
$this->setOptions($options);
}
}
public function setReturnType($returnType)
{
$this->_returnType = $returnType;
return $this;
}
public function getReturnType()
{
return $this->_returnType;
}
public function addParameter($parameter)
{
if ($parameter instanceof Zend_Server_Method_Parameter) {
$this->_parameters[] = $parameter;
if (null !== ($name = $parameter->getName())) {
$this->_parameterNameMap[$name] = count($this->_parameters) - 1;
}
} else {
require_once 'Zend/Server/Method/Parameter.php';
$parameter = new Zend_Server_Method_Parameter(array(
'type' => (string) $parameter,
));
$this->_parameters[] = $parameter;
}
return $this;
}
public function addParameters(array $parameters)
{
foreach ($parameters as $parameter) {
$this->addParameter($parameter);
}
return $this;
}
public function setParameters(array $parameters)
{
$this->_parameters = array();
$this->_parameterNameMap = array();
$this->addParameters($parameters);
return $this;
}
public function getParameters()
{
$types = array();
foreach ($this->_parameters as $parameter) {
$types[] = $parameter->getType();
}
return $types;
}
public function getParameterObjects()
{
return $this->_parameters;
}
public function getParameter($index)
{
if (!is_string($index) && !is_numeric($index)) {
return null;
}
if (array_key_exists($index, $this->_parameterNameMap)) {
$index = $this->_parameterNameMap[$index];
}
if (array_key_exists($index, $this->_parameters)) {
return $this->_parameters[$index];
}
return null;
}
public function setOptions(array $options)
{
foreach ($options as $key => $value) {
$method = 'set' . ucfirst($key);
if (method_exists($this, $method)) {
$this->$method($value);
}
}
return $this;
}
public function toArray()
{
return array(
'returnType' => $this->getReturnType(),
'parameters' => $this->getParameters(),
);
}
}