Exemple #1
0
 /**
  * Adds a new method
  *
  * @param Method $method
  *
  * @return void
  * @throws \Exception
  */
 public function addMethod(Method $method)
 {
     $methods = $this->getMethods();
     $key = $method->getName();
     if (array_key_exists($key, $methods)) {
         throw new \Exception('A Method with the name of: ' . $method->getName() . ' already exists');
     }
     $methods[$key] = $method;
     ksort($methods);
     $this->setMethods($methods);
 }
Exemple #2
0
 /**
  * Generates after events since they are so similar.
  *
  * @param String $methodName
  * @param String $methodDescription
  *
  * @return Object\Method
  */
 private function afterCrudMethod($methodName, $methodDescription)
 {
     $method = new Object\Method();
     $method->setAccess('protected');
     $method->setDescription($methodDescription);
     $method->setReturnType('void');
     $method->setName($methodName);
     $parameter = new Object\Parameter();
     $parameter->setName('entity');
     $parameter->setType('Model');
     $parameter->setStrictType(true);
     $method->addParameter($parameter);
     $method->setContent('return;');
     return $method;
 }
 /**
  * Builds the delete action
  * @return void
  */
 private function buildDeleteAction()
 {
     $api = new Swagger\Api();
     $api->setPath('/' . $this->getClassName() . '/{id}');
     $operation = new Swagger\Operation();
     $operation->setMethod('DELETE');
     $operation->setSummary('Deletes ' . $this->singularModelA_Or_An() . '.');
     $operation->setNotes('');
     $responseMessage = new Swagger\ResponseMessage();
     $responseMessage->setCode(204);
     $responseMessage->setMessage(ucfirst($this->getModel()->getSource()) . " deleted.");
     $operation->addResponseMessage($responseMessage);
     $responseMessage = $this->notAuthorizedResponse();
     $operation->addResponseMessage($responseMessage);
     $responseMessage = $this->notFoundResponse();
     $operation->addResponseMessage($responseMessage);
     $parents = $this->getDeletionPreventingParents();
     if (!empty($parents)) {
         $responseMessage = new Swagger\ResponseMessage();
         $responseMessage->setCode(409);
         $responseMessage->setMessage(ucfirst($this->getModel()->getSource()) . " is connected by foreign key to one of the following entities: " . implode(', ', $parents));
         $operation->addResponseMessage($responseMessage);
     }
     $operation->addParameter($this->buildIdParameter());
     $api->addOperation($operation);
     $method = new Object\Method();
     $method->setDescription($api->__toString());
     $method->setReturnType('void');
     $method->setAccess('public');
     $method->setName('deleteAction');
     $method->setContent('parent::deleteAction();');
     $this->getObject()->addMethod($method);
 }