Beispiel #1
0
 public function getAnnotations()
 {
     if ($this->annotations === false) {
         $this->annotations = Helper::getAnnotations($this);
     }
     return $this->annotations;
 }
Beispiel #2
0
 public function run($context)
 {
     foreach ($this as $annotation) {
         if ($handler = Helper::getAnnotationHandler($annotation)) {
             $handler->run($this->reflector, $context);
         }
     }
 }
 public function run(Reflector $reflMethod, $instance)
 {
     try {
         if (Helper::hasAnnotation($reflMethod, AccessControl::class)) {
             $this->handleAnnotation($reflMethod, $instance);
         }
     } catch (UnAuthorizedException $ex) {
         $this->handleUnAuthorizedException($instance, $ex);
     }
 }
Beispiel #4
0
 private static function callPropertyAnnotationHandlers($reflClass, $instance, $counter)
 {
     foreach ($reflClass->getProperties() as $property) {
         $hasAnnotation = $property->hasAnnotation(Autowired::class);
         if ($hasAnnotation) {
             $annotation = $property->getAnnotation(Autowired::class);
             Helper::getAnnotationHandler(get_class($annotation))->run($property, $instance);
         }
     }
 }
Beispiel #5
0
 /**
  * @param Reflector $refl
  * @param object $context
  */
 public function run(Reflector $refl, $context)
 {
     if ($refl instanceof \ReflectionProperty) {
         $type = Helper::getPropertyType($refl);
         $isPrimitiveType = in_array($type, Constants::$php_default_types) || in_array($type, Constants::$php_pseudo_types);
         if (!($refl instanceof ReflectionProperty || method_exists($refl, 'getAnnotation'))) {
             $refl = new ReflectionProperty($refl->getDeclaringClass()->getName(), $refl->getName());
         }
         $serviceName = ($qualifier = $refl->getAnnotation(Qualifier::class)) ? $qualifier->value : null;
         if (($type === null || $isPrimitiveType) && $serviceName === null) {
             throw new RuntimeException("Must set the property type by @var annotation or you must use @Quealifier annotation to define the service");
         }
         if (empty($serviceName)) {
             $serviceName = $type;
         }
         $service = BeanFactory::getInstance()->getBean($serviceName);
         $refl->setAccessible(true);
         $refl->setValue($context, $service);
     }
 }
Beispiel #6
0
 public function run(Reflector $refl, $context)
 {
     if ($refl instanceof ReflectionProperty) {
         $annotation = Helper::getAnnotation($refl, Config::class);
         $path = explode('.', $annotation->value);
         $config = $this->config;
         while (!empty($path)) {
             $config = $config->{array_shift($path)};
         }
         $type = Helper::getPropertyType($refl);
         $isPrimitiveType = in_array($type, Constants::$php_default_types) || in_array($type, Constants::$php_pseudo_types);
         $refl->setAccessible(true);
         if ($type !== null && $isPrimitiveType) {
             if (gettype($config) === $type) {
                 $refl->setValue($context, $config);
             } elseif ($type === 'array' && method_exists($config, 'toArray')) {
                 $refl->setValue($context, $config->toArray());
             }
         } else {
             $refl->setValue($context, $config);
         }
     }
 }
 private function fillForm($form, $request = null)
 {
     $class = new ReflectionClass($form);
     /* @var $property ReflectionProperty */
     foreach ($class->getProperties() as $property) {
         $value = array_key_exists($property->getName(), (array) $request) ? $request[$property->getName()] : null;
         $type = Helper::getPropertyType($property);
         if (!$this->isPrimitive($type)) {
             $value = $this->fillForm(ClassInvoker::getNewInstance($type), $value);
         }
         $this->setFormFieldValue($property, $form, $value);
     }
     return $form;
 }
Beispiel #8
0
 /**
  * @param ReflectionProperty $refl
  * @return string
  */
 public static function getServiceName(ReflectionProperty $refl)
 {
     $annotation = AnnotationHelper::getAnnotation($refl, Qualifier::class);
     if ($annotation) {
         return $annotation->value;
     }
     return null;
 }