Exemplo n.º 1
0
 /**
  * Add method to definition
  *
  * @param  array|Rest_Method_Definition $method
  * @param  null|string $name
  * @return Rest_Definition
  * @throws Rest_Exception if duplicate or invalid method provided
  */
 public function addMethod($method, $name = null)
 {
     if (is_array($method)) {
         require_once 'classes/rest/method/Definition.php';
         $method = new Rest_Method_Definition($method);
     } elseif (!$method instanceof Rest_Method_Definition) {
         require_once 'Exception.php';
         throw new Rest_Exception('Invalid method provided');
     }
     if (is_numeric($name)) {
         $name = null;
     }
     if (null !== $name) {
         $method->setName($name);
     } else {
         $name = $method->getName();
     }
     if (null === $name) {
         require_once 'Exception.php';
         throw new Rest_Exception('No method name provided');
     }
     if (!$this->_overwriteExistingMethods && array_key_exists($name, $this->_methods)) {
         require_once 'Exception.php';
         throw new Rest_Exception(sprintf('Method by name of "%s" already exists', $name));
     }
     $this->_methods[$name] = $method;
     return $this;
 }