Ejemplo n.º 1
0
 private function addRouteForController($controllerClass)
 {
     $ref = new ReflectionClass($controllerClass);
     $annotations = $this->reflectionHelper->getAnnotations($ref->getDocComment());
     // these are used by the generated code
     /** @noinspection PhpUnusedLocalVariableInspection */
     $container = $this->container;
     /** @noinspection PhpUnusedLocalVariableInspection */
     $app = $this->app;
     $middlewareAnnotations = $annotations->getWithName('middleware');
     foreach ($annotations->getWithName('route') as $ano) {
         $builder = new RouteBuilder();
         $values = $ano->getValues();
         $builder->setMethod(strtolower($values[0]));
         $builder->setControllerName($controllerClass);
         $builder->setRoute($values[1]);
         preg_match_all('/\\/:([a-z0-9]+)/i', $values[1], $matches);
         foreach ($matches[1] as $match) {
             $builder->addParam($match);
         }
         foreach ($middlewareAnnotations as $midAno) {
             $midValues = $midAno->getValues();
             $builder->addMiddleware($midValues[0]);
         }
         eval($builder->render());
     }
 }
 public function toArray($instance)
 {
     $ref = new ReflectionClass($instance);
     $fields = $ref->getProperties();
     $result = array();
     foreach ($fields as $field) {
         if ($this->reflectionHelper->hasAnnotation($field->getDocComment(), 'jsonIgnore')) {
             continue;
         }
         if ($this->reflectionHelper->hasAnnotation($field->getDocComment(), 'calculatedBy')) {
             $annotations = $this->reflectionHelper->getAnnotations($field->getDocComment());
             $calculatedByAnnotations = $annotations->getWithName('calculatedBy');
             $values = $calculatedByAnnotations[0]->getValues();
             $instance->{$values}[0]();
         }
         $field->setAccessible(true);
         $value = $field->getValue($instance);
         if (!is_null($value)) {
             $result[$field->getName()] = $this->getValue($value);
         }
     }
     return $result;
 }