Source of file Prototype.php
Size: 4,319 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Server/Method/Prototype.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Server\Method; /** * Method prototype metadata */ class Prototype { /** * @var string Return type */ protected $returnType = 'void'; /** * @var array Map parameter names to parameter index */ protected $parameterNameMap = array(); /** * @var array Method parameters */ protected $parameters = array(); /** * Constructor * * @param null|array $options */ public function __construct($options = null) { if ((null !== $options) && is_array($options)) { $this->setOptions($options); } } /** * Set return value * * @param string $returnType * @return \Zend\Server\Method\Prototype */ public function setReturnType($returnType) { $this->returnType = $returnType; return $this; } /** * Retrieve return type * * @return string */ public function getReturnType() { return $this->returnType; } /** * Add a parameter * * @param string $parameter * @return \Zend\Server\Method\Prototype */ public function addParameter($parameter) { if ($parameter instanceof Parameter) { $this->parameters[] = $parameter; if (null !== ($name = $parameter->getName())) { $this->parameterNameMap[$name] = count($this->parameters) - 1; } } else { $parameter = new Parameter(array( 'type' => (string) $parameter, )); $this->parameters[] = $parameter; } return $this; } /** * Add parameters * * @param array $parameters * @return \Zend\Server\Method\Prototype */ public function addParameters(array $parameters) { foreach ($parameters as $parameter) { $this->addParameter($parameter); } return $this; } /** * Set parameters * * @param array $parameters * @return \Zend\Server\Method\Prototype */ public function setParameters(array $parameters) { $this->parameters = array(); $this->parameterNameMap = array(); $this->addParameters($parameters); return $this; } /** * Retrieve parameters as list of types * * @return array */ public function getParameters() { $types = array(); foreach ($this->parameters as $parameter) { $types[] = $parameter->getType(); } return $types; } /** * Get parameter objects * * @return array */ public function getParameterObjects() { return $this->parameters; } /** * Retrieve a single parameter by name or index * * @param string|int $index * @return null|\Zend\Server\Method\Parameter */ 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; } /** * Set object state from array * * @param array $options * @return \Zend\Server\Method\Prototype */ public function setOptions(array $options) { foreach ($options as $key => $value) { $method = 'set' . ucfirst($key); if (method_exists($this, $method)) { $this->$method($value); } } return $this; } /** * Serialize to array * * @return array */ public function toArray() { return array( 'returnType' => $this->getReturnType(), 'parameters' => $this->getParameters(), ); } } |