/**
  * Generates the actual interfaces
  */
 public function generate()
 {
     $interfacesData = json_decode($this->json, true);
     foreach ($interfacesData as $interface) {
         $filename = $interface['name'] . '.php';
         $interfaceObject = new PHPInterfaceObject();
         $interfaceObject->setName($interface['name']);
         foreach ($interface['methods'] as $method) {
             $methodObject = new PHPMethod();
             $methodObject->setName($method['name']);
             $methodObject->setReturnValue($method['returnType']);
             $methodObject->setScope($method['scope']);
             $methodObject->setComment($method['comment']);
             foreach ($method['parameters'] as $parameter) {
                 $parameterObject = new Parameter();
                 $parameterObject->setName($parameter['name']);
                 $parameterObject->setType($parameter['type']);
                 $methodObject->addParameter($parameterObject);
             }
             foreach ($method['annotations'] as $annotation) {
                 $annotationObject = new Annotation();
                 $annotationObject->setName($annotation['name']);
                 $annotationObject->setValue($annotation['value']);
                 $annotationObject->setInterpreter('@');
                 $methodObject->addAnnotation($annotationObject);
             }
             $interfaceObject->addMethod($methodObject);
         }
         file_put_contents($this->folder . DIRECTORY_SEPARATOR . $filename, $interfaceObject->toString());
     }
 }
Esempio n. 2
0
 /**
  * setMethod()
  *
  * @param array|\Zend\CodeGenerator\PHP\PHPMethod $method
  * @return \Zend\CodeGenerator\PHP\PHPClass
  */
 public function setMethod($method)
 {
     if (is_array($method)) {
         $method = new PHPMethod($method);
         $methodName = $method->getName();
     } elseif ($method instanceof PHPMethod) {
         $methodName = $method->getName();
     } else {
         throw new Exception('setMethod() expects either an array of method options or an instance of Zend_CodeGenerator_Php_Method');
     }
     if (isset($this->_methods[$methodName])) {
         throw new Exception('A method by name ' . $methodName . ' already exists in this class.');
     }
     $this->_methods[$methodName] = $method;
     return $this;
 }