Esempio n. 1
0
 /**
  * @return ClassGenerator
  */
 public function create()
 {
     $class = ClassGen::classGen($this->exception, $this->namespace);
     if (!empty($this->extends)) {
         $class->addUse('Phrest\\API\\Exceptions\\' . $this->extends);
         $class->setExtendedClass($this->extends);
     }
     return $class;
 }
Esempio n. 2
0
 /**
  * @return ClassGenerator
  */
 public function create()
 {
     $class = ClassGen::classGen($this->name, $this->namespace, ['Phalcon\\Mvc\\Model'], 'Model');
     foreach ($this->columns as $name => $type) {
         $property = ClassGen::property($name, 'public', null, $type);
         $class->addPropertyFromGenerator($property);
     }
     $class->addMethodFromGenerator(ClassGen::method('initialize'));
     $findFirst = ClassGen::method('findFirst', [new ParameterGenerator('params', 'mixed', [])])->setBody('return parent::findFirst($params);');
     $findFirst->setStatic(true);
     $findFirst->getDocBlock()->setTag(new Tag\GenericTag('return', 'static'));
     $class->addMethodFromGenerator($findFirst);
     return $class;
 }
Esempio n. 3
0
 /**
  * Process and create code/files
  *
  * @return ClassGenerator
  */
 public function create()
 {
     $class = ClassGen::classGen($this->entityName . 'Controller', $this->namespace, ['Phrest\\API\\Controllers\\RESTController'], 'RESTController');
     foreach ($this->entityDefinition->requests as $requestMethod => $actions) {
         foreach ($actions as $actionName => $action) {
             if (empty($action)) {
                 continue;
             }
             $params = $this->generateParamsFromUrl($action->url);
             $docblock = $this->createDocblockForMethod($requestMethod, $action, $params);
             $method = ClassGen::method($actionName, $params, 'public');
             $method->setDocBlock($docblock);
             $body = $this->createBodyForMethod($action);
             $method->setBody($body);
             $class->addMethodFromGenerator($method);
         }
     }
     foreach ($this->uses as $use) {
         $class->addUse($use);
     }
     return $class;
 }
Esempio n. 4
0
 /**
  * Process and create code/files
  */
 public function create()
 {
     $uses = ['Phrest\\API\\DI\\PhrestDIInterface', 'Phrest\\SDK\\PhrestSDK', 'Phrest\\SDK\\Request\\AbstractRequest', $this->namespace . '\\' . Generator::$name . 'API'];
     foreach ($this->requests as $request) {
         $uses[] = $request->getNamespace() . '\\' . $request->getName();
     }
     $class = ClassGen::classGen($this->name, $this->namespace . '\\' . $this->version, $uses, 'PhrestSDK');
     $di = new ParameterGenerator('di', 'PhrestDIInterface');
     $constructor = ClassGen::constructor([$di]);
     $constructor->setBody($this->getConstructorBody());
     $class->addMethodFromGenerator($constructor);
     $abstractRequest = new ParameterGenerator('request', 'AbstractRequest');
     $injectDependencies = ClassGen::method('injectDependencies', [$abstractRequest], 'private', 'return $request;');
     $docBlock = $injectDependencies->getDocBlock();
     $docBlock->setTag(new GenericTag('return', 'AbstractRequest'));
     $class->addMethodFromGenerator($injectDependencies);
     foreach ($this->requests as $request) {
         $getRequest = ClassGen::method('get' . ucfirst($request->getName()), [], 'public', 'return $this->injectDependencies(new ' . $request->getName() . '());');
         $getRequest->getDocBlock()->setTag(new GenericTag('return', $request->getName()));
         $class->addMethodFromGenerator($getRequest);
     }
     return $class;
 }
Esempio n. 5
0
 /**
  * @return ClassGenerator
  */
 public function generatePlural()
 {
     $class = ClassGen::classGen($this->name . 'sResponse', $this->namespace, ['Phrest\\API\\Response\\ResponseArray'], 'ResponseArray');
     return $class;
 }
Esempio n. 6
0
 /**
  * Process and create code/files
  */
 public function create()
 {
     $class = ClassGen::classGen($this->name, $this->namespace, ['Phrest\\SDK\\Request\\AbstractRequest', 'Phrest\\SDK\\Request\\RequestOptions', 'Phrest\\SDK\\PhrestSDK'], 'AbstractRequest');
     // Path
     $path = '/' . $this->version . '/' . strtolower($this->entityName) . $this->getPlaceholderUriFromUrl($this->action->url);
     $property = ClassGen::property('path', 'private', $path, 'string');
     $class->addPropertyFromGenerator($property);
     // Properties and constructor parameters
     /** @var ParameterGenerator[] $parameters */
     $parameters = [];
     // Get properties
     $getParams = $this->generateGetParamsFromUrl($this->action->url);
     if (!empty($getParams)) {
         foreach ($getParams as $getParam) {
             $class->addPropertyFromGenerator(ClassGen::property($getParam, 'public', null));
             $parameter = new ParameterGenerator($getParam);
             $parameter->setDefaultValue(null);
             $parameters[$getParam] = $parameter;
         }
     }
     // Post properties
     if (!empty($this->action->postParams)) {
         foreach ($this->action->postParams as $name => $type) {
             if ($class->hasProperty($name)) {
                 continue;
             }
             $class->addPropertyFromGenerator(ClassGen::property($name, 'public', null, $type));
             $parameter = new ParameterGenerator($name, $type);
             $parameter->setDefaultValue(null);
             $parameters[$name] = $parameter;
         }
     }
     // Constructor
     if (!empty($parameters)) {
         $constructor = ClassGen::constructor($parameters);
         $class->addMethodFromGenerator($constructor);
     }
     // Create method
     $create = ClassGen::method('create', [], 'public', $this->getCreateBody());
     $class->addMethodFromGenerator($create);
     // Setters
     foreach ($parameters as $parameter) {
         $class->addMethodFromGenerator(ClassGen::setter($parameter->getName(), $parameter->getType()));
     }
     return $class;
 }