/** * Add method to definition * * @param array|\Zend\Server\Method\Definition $method * @param null|string $name * @return \Zend\Server\Definition * @throws \Zend\Server\Exception\InvalidArgumentException if duplicate or invalid method provided */ public function addMethod($method, $name = null) { if (is_array($method)) { $method = new Method\Definition($method); } elseif (!$method instanceof Method\Definition) { throw new Exception\InvalidArgumentException('Invalid method provided'); } if (is_numeric($name)) { $name = null; } if (null !== $name) { $method->setName($name); } else { $name = $method->getName(); } if (null === $name) { throw new Exception\InvalidArgumentException('No method name provided'); } if (!$this->overwriteExistingMethods && array_key_exists($name, $this->methods)) { throw new Exception\InvalidArgumentException(sprintf('Method by name of "%s" already exists', $name)); } $this->methods[$name] = $method; return $this; }
/** * Add service method to service map * * @param Method\Definition $method * @return void */ protected function _addMethodServiceMap(Method\Definition $method) { $serviceInfo = array('name' => $method->getName(), 'return' => $this->_getReturnType($method)); $params = $this->_getParams($method); $serviceInfo['params'] = $params; $serviceMap = $this->getServiceMap(); if (false !== $serviceMap->getService($serviceInfo['name'])) { $serviceMap->removeService($serviceInfo['name']); } $serviceMap->addService($serviceInfo); }