Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $actionMetadata = new ActionMetadata($class->name);
     $actionMetadata->fileResources[] = $class->getFilename();
     $actionAnnotation = $this->reader->getClassAnnotation($class, Action::class);
     /** @var Action $actionAnnotation */
     if ($actionAnnotation !== null) {
         $actionMetadata->isAction = true;
         $actionMetadata->serviceId = $actionAnnotation->serviceId ?: null;
         $actionMetadata->alias = $actionAnnotation->alias ?: null;
     } else {
         return null;
     }
     /** @var Security $securityAnnotation */
     $securityAnnotation = $this->reader->getClassAnnotation($class, Security::class);
     if ($securityAnnotation) {
         $actionMetadata->authorizationExpression = $securityAnnotation->expression;
     }
     $methodCount = 0;
     foreach ($class->getMethods() as $method) {
         if (!$method->isPublic()) {
             continue;
         }
         $methodMetadata = $this->loadMetadataForMethod($class, $method);
         if ($methodMetadata) {
             $actionMetadata->addMethodMetadata($methodMetadata);
             $methodCount++;
         }
     }
     if ($methodCount < 1) {
         return null;
     }
     return $actionMetadata;
 }
 /**
  * Modifies the Request object to apply configuration information found in
  * controllers annotations like the template to render or HTTP caching
  * configuration.
  *
  * @param FilterControllerEvent $event A FilterControllerEvent instance
  *
  * @return void
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         return;
     }
     $className = class_exists('Doctrine\\Common\\Util\\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]);
     $object = new \ReflectionClass($className);
     $transactional = $this->reader->getClassAnnotation($object, Transactional::NAME);
     if (!$transactional instanceof Transactional) {
         return;
     }
     $avoidTransaction = $this->reader->getMethodAnnotation($object->getMethod($controller[1]), AvoidTransaction::NAME);
     if (!is_null($avoidTransaction)) {
         return;
     }
     $request = $event->getRequest();
     $modelName = $transactional->model;
     $model = new $modelName();
     $this->transactionBuilder->setRequestMethod($request->getRealMethod());
     $this->transactionBuilder->setRequestSource(Transaction::SOURCE_REST);
     $this->transactionBuilder->setRelatedRoute($transactional->relatedRoute);
     $ids = [];
     foreach ($model->getIds() as $field => $value) {
         $ids[$field] = $request->attributes->get($field);
     }
     $this->transactionBuilder->setRelatedIds($ids);
     $this->transactionBuilder->setModel($transactional->model);
     $transaction = $this->transactionBuilder->build();
     $request->attributes->set('transaction', $transaction);
 }
 /**
  * Attempts to read the uploadable annotation.
  *
  * @param  \ReflectionClass $class The reflection class.
  * @return null|\Iphp\FileStoreBundle\Annotation\Uploadable The annotation.
  */
 public function readUploadable(\ReflectionClass $class)
 {
     $baseClassName = $className = $class->getNamespaceName() . '\\' . $class->getName();
     do {
         if (isset($this->uploadedClass[$className])) {
             if ($baseClassName != $className) {
                 $this->uploadedClass[$baseClassName] = $this->uploadedClass[$className];
             }
             return $this->uploadedClass[$baseClassName];
         }
         $annotation = $this->reader->getClassAnnotation($class, 'Iphp\\FileStoreBundle\\Mapping\\Annotation\\Uploadable');
         if ($annotation) {
             $this->uploadedClass[$baseClassName] = $annotation;
             if ($baseClassName != $className) {
                 $this->uploadedClass[$className] = $annotation;
             }
             return $annotation;
         }
         $class = $class->getParentClass();
         if ($class) {
             $className = $class->getNamespaceName() . '\\' . $class->getName();
         }
     } while ($class);
     return $annotation;
 }
Пример #4
0
 /**
  * @param \ReflectionClass $class
  *
  * @return \Metadata\ClassMetadata
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $metadata = new ClassMetadata($class->getName());
     // Resource annotation
     $annotation = $this->reader->getClassAnnotation($class, 'Conjecto\\Nemrod\\ResourceManager\\Annotation\\Resource');
     if (null !== $annotation) {
         $types = $annotation->types;
         $pattern = $annotation->uriPattern;
         if (!is_array($types)) {
             $types = array($types);
         }
         $metadata->types = $types;
         $metadata->uriPattern = $pattern;
     }
     foreach ($class->getProperties() as $reflectionProperty) {
         $propMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName());
         // Property annotation
         $annotation = $this->reader->getPropertyAnnotation($reflectionProperty, 'Conjecto\\Nemrod\\ResourceManager\\Annotation\\Property');
         if (null !== $annotation) {
             $propMetadata->value = $annotation->value;
             $propMetadata->cascade = $annotation->cascade;
         }
         $metadata->addPropertyMetadata($propMetadata);
     }
     return $metadata;
 }
Пример #5
0
 /**
  * @param string $className
  *
  * @return array
  */
 public function processClass($className, $path)
 {
     $reflection = new \ReflectionClass($className);
     if (null === $this->reader->getClassAnnotation($reflection, $this->annotationClass)) {
         return array();
     }
     $mappings = array();
     $this->output->writeln("Found class: {$className}");
     foreach ($reflection->getMethods() as $method) {
         /** @var Method[] $annotations */
         $annotations = $this->reader->getMethodAnnotations($method);
         if (0 == count($annotations)) {
             continue;
         }
         $this->output->writeln(sprintf("Found annotations for method %s::%s.", $method->class, $method->getName()));
         foreach ($annotations as $annotation) {
             if (!$annotation instanceof Method) {
                 continue;
             }
             $this->output->writeln(sprintf("Found mapping: %s::%s --> %s::%s", $method->class, $method->getName(), $annotation->getClass(), $annotation->getMethod()));
             $mapping = new Mapping();
             $moduleFile = $reflection->getFileName();
             $moduleFile = substr($moduleFile, strpos($moduleFile, $path));
             $mapping->setOxidClass($annotation->getClass())->setOxidMethod($annotation->getMethod())->setModuleClass($className)->setModuleMethod($method->getName())->setReturn($annotation->hasReturnValue())->setParentExecution($annotation->getParentExecution())->setModuleFile($moduleFile);
             $mappings[] = $mapping;
         }
     }
     return $mappings;
 }
 /**
  * @param LifecycleEventArgs $args
  * @return bool
  * @throws \Exception
  */
 public function checkBadWords(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if (!$entity instanceof BadWordDetectorInterface) {
         return true;
     }
     $badWords = $args->getEntityManager()->getRepository('RenowazeBundle:BadWord')->findAll();
     /** @var BadWordDetector $annotationParams */
     $annotationParams = $this->reader->getClassAnnotation(new \ReflectionClass($entity), 'RenowazeBundle\\Annotation\\BadWordDetector');
     foreach ($annotationParams->fields as $field) {
         $methodName = 'get' . ucfirst($field);
         if (!method_exists($entity, $methodName)) {
             throw new \Exception(sprintf('Field "%s" not found in entity "%s"', $methodName, get_class($entity)));
         }
         /** @var BadWord $badWord */
         foreach ($badWords as $badWord) {
             if (strpos($entity->{$methodName}(), $badWord->getWord()) !== false) {
                 $entity->setHasBadWords(true);
                 return true;
             }
         }
     }
     $entity->setHasBadWords(false);
     return true;
 }
Пример #7
0
 /**
  * Loads ACL annotations from PHP files
  *
  * @param AclAnnotationStorage $storage
  */
 public function load(AclAnnotationStorage $storage)
 {
     $configLoader = OroSecurityExtension::getAclAnnotationLoader();
     $resources = $configLoader->load();
     foreach ($resources as $resource) {
         foreach ($resource->data as $file) {
             $className = $this->getClassName($file);
             if ($className !== null) {
                 $reflection = $this->getReflectionClass($className);
                 // read annotations from class
                 $annotation = $this->reader->getClassAnnotation($reflection, self::ANNOTATION_CLASS);
                 if ($annotation) {
                     $storage->add($annotation, $reflection->getName());
                 } else {
                     $ancestor = $this->reader->getClassAnnotation($reflection, self::ANCESTOR_CLASS);
                     if ($ancestor) {
                         $storage->addAncestor($ancestor, $reflection->getName());
                     }
                 }
                 // read annotations from methods
                 foreach ($reflection->getMethods() as $reflectionMethod) {
                     $annotation = $this->reader->getMethodAnnotation($reflectionMethod, self::ANNOTATION_CLASS);
                     if ($annotation) {
                         $storage->add($annotation, $reflection->getName(), $reflectionMethod->getName());
                     } else {
                         $ancestor = $this->reader->getMethodAnnotation($reflectionMethod, self::ANCESTOR_CLASS);
                         if ($ancestor) {
                             $storage->addAncestor($ancestor, $reflection->getName(), $reflectionMethod->getName());
                         }
                     }
                 }
             }
         }
     }
 }
Пример #8
0
 /**
  * Load JSON API configuration from controller annotations
  *
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     if (!is_array($controller)) {
         return;
     }
     $config = null;
     $refClass = new \ReflectionClass($controller[0]);
     if (null !== ($annotation = $this->reader->getClassAnnotation($refClass, ApiRequest::class))) {
         /* @var $annotation ApiRequest */
         $config = $annotation->toArray();
     }
     $refMethod = $refClass->getMethod($controller[1]);
     if (null !== ($annotation = $this->reader->getMethodAnnotation($refMethod, ApiRequest::class))) {
         if (null !== $config) {
             $config = array_replace($config, $annotation->toArray());
         } else {
             $config = $annotation->toArray();
         }
     }
     if (null !== $config) {
         if (!array_key_exists('matcher', $config)) {
             $config['matcher'] = $this->defMatcher;
         }
         $event->getRequest()->attributes->set('_jsonapi', $this->factory->createEnvironment($config));
     }
 }
 /**
  * Gets the Geograhpical annotation for the specified object.
  * 
  * @param object $obj The object
  * @return Geographical The geographical annotation
  */
 public function getGeographicalAnnotation($obj)
 {
     if (!is_object($obj)) {
         throw new \InvalidArgumentException();
     }
     $refClass = new \ReflectionClass($obj);
     return $this->reader->getClassAnnotation($refClass, 'Vich\\GeographicalBundle\\Annotation\\Geographical');
 }
Пример #10
0
 /**
  * @param \ReflectionClass $classRefl
  * @param string $segmentCode
  * @throws IncorrectSegmentId
  */
 protected function checkSegmentCode($classRefl, $segmentCode)
 {
     if ($segmentAnnotation = $this->annotationReader->getClassAnnotation($classRefl, Segment::class)) {
         if ($segmentCode != $segmentAnnotation->value) {
             throw new IncorrectSegmentId(sprintf("Expected %s segment, %s found", $segmentAnnotation->value, $segmentCode));
         }
     }
 }
 /**
  * @return boolean
  */
 private function isProtectedByCsrfDoubleSubmit(\ReflectionClass $class, \ReflectionMethod $method)
 {
     $annotation = $this->annotationReader->getClassAnnotation($class, 'Bazinga\\Bundle\\RestExtraBundle\\Annotation\\CsrfDoubleSubmit');
     if (null !== $annotation) {
         return true;
     }
     $annotation = $this->annotationReader->getMethodAnnotation($method, 'Bazinga\\Bundle\\RestExtraBundle\\Annotation\\CsrfDoubleSubmit');
     return null !== $annotation;
 }
 /**
  * @param string $nodeEntityClass
  * @param string $property
  *
  * @return \GraphAware\Neo4j\OGM\Metadata\NodeAnnotationMetadata
  */
 public function create($nodeEntityClass)
 {
     $reflectionClass = new \ReflectionClass($nodeEntityClass);
     /** @var Node $annotation */
     $annotation = $this->reader->getClassAnnotation($reflectionClass, Node::class);
     if (null !== $annotation) {
         return new NodeAnnotationMetadata($annotation->label, $annotation->repository);
     }
     throw new MappingException(sprintf('The class "%s" is missing the "%s" annotation', $nodeEntityClass, Node::class));
 }
Пример #13
0
 /**
  * @param $entityClass
  * @return TransformerAbstract|null
  */
 protected function getEntityTransformer($entityClass)
 {
     $reflectionClass = new \ReflectionClass($entityClass);
     /** @var FractalTransformer $annotation */
     $annotation = $this->annotationReader->getClassAnnotation($reflectionClass, FractalTransformer::class);
     if (is_null($annotation)) {
         return null;
     }
     $transformerClass = $annotation->value;
     return new $transformerClass();
 }
Пример #14
0
 /**
  * @inheritdoc
  */
 public function loadClassMetadata(\ReflectionClass $class)
 {
     if (null !== ($resource = $this->reader->getClassAnnotation($class, ApiResource::class))) {
         return $this->loadResourceMetadata($resource, $class);
     } elseif (null !== ($document = $this->reader->getClassAnnotation($class, ApiDocument::class))) {
         return $this->loadDocumentMetadata($document, $class);
     } else {
         $object = $this->reader->getClassAnnotation($class, ApiObject::class);
         return $this->loadObjectMetadata($class, $object);
     }
 }
 /**
  * This event will fire during any controller call
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         return;
     }
     $class = new \ReflectionClass(get_class($controller[0]));
     // get controller
     if (!empty($this->reader->getClassAnnotation($class, self::STATE_LESS_ANNOTATION))) {
         $this->handleAuthenticated($class);
     }
 }
 /**
  * @param string $annotation
  * @return object
  */
 public function getSingleClassAnnotation($annotation)
 {
     $annotation = ltrim($annotation, '\\');
     $res = $this->annotationReader->getClassAnnotation($this->rClass, $annotation);
     if (empty($res)) {
         return null;
     }
     if (is_array($res)) {
         return array_shift($res);
     }
     return $res;
 }
 /**
  * @inheritdoc
  */
 public function supports(ParamConverter $configuration)
 {
     if ($configuration->getClass() === null) {
         return false;
     }
     try {
         $class = new \ReflectionClass($configuration->getClass());
     } catch (\ReflectionException $e) {
         return false;
     }
     return $this->reader->getClassAnnotation($class, RequestAnnotation::class) !== null;
 }
Пример #18
0
 /**
  * @param $class
  */
 public function setWorkerAnnotation($class)
 {
     $class = new \ReflectionClass($class);
     $annotation = $this->reader->getClassAnnotation($class, self::WORKER_ANNOTATION_CLASS);
     if ($annotation) {
         $worker = $annotation->getWorker() ? $annotation->getWorker() : "default";
         if (isset($this->workerAnnotations[$worker])) {
             throw new Exception("The Worker '{$worker}' has already been registered in '{$class->getName()}'.  Workers can only be defined once on the Class level");
         }
         $this->workerAnnotations[$worker] = $annotation;
         $this->workerAnnotationsClasses[$class->getName()] = $annotation;
     }
 }
 protected function getParentAnnotations(\ReflectionClass $class)
 {
     $parents = ['method' => '', 'context' => [], 'default_context' => true];
     /** @var Method $annot */
     if ($annot = $this->reader->getClassAnnotation($class, Method::class)) {
         if (null !== $annot->getMethod()) {
             $parents['method'] = $annot->getMethod();
         }
         if (null !== $annot->getContext()) {
             $parents['context'] = $annot->getContext();
         }
     }
     return $parents;
 }
Пример #20
0
 /**
  * Indicates wether the constraints validation is enabled or not for the given object.
  *
  * @param array  $objectClasses The classes of the object to read.
  * @param \Doctrine\Common\Annotations\Reader $annotationReader The annotation reader to use.
  *
  * @return boolean True if the validation is enabled, else false.
  */
 public static function isConstraintsValidationEnabled($objectClasses, $annotationReader)
 {
     $enabled = Configuration::isConstraintsValidationEnabled();
     foreach ($objectClasses as $class) {
         if ($annotationReader->getClassAnnotation($class, self::$disableConstraintsValidationAnnotationClass) !== null) {
             $enabled = false;
             break;
         }
         if ($annotationReader->getClassAnnotation($class, self::$enableConstraintsValidationAnnotationClass) !== null) {
             $enabled = true;
             break;
         }
     }
     return $enabled;
 }
Пример #21
0
 /**
  * {@inheritdoc}
  */
 public function loadClassMetadata(ClassMetadataInterface $classMetadata, array $normalizationGroups = null, array $denormalizationGroups = null, array $validationGroups = null)
 {
     $reflectionClass = $classMetadata->getReflectionClass();
     if ($iri = $this->reader->getClassAnnotation($reflectionClass, self::IRI_ANNOTATION_NAME)) {
         $classMetadata = $classMetadata->withIri($iri->value);
     }
     foreach ($classMetadata->getAttributesMetadata() as $attributeName => $attributeMetadata) {
         if ($reflectionProperty = $this->getReflectionProperty($reflectionClass, $attributeName)) {
             if ($iri = $this->reader->getPropertyAnnotation($reflectionProperty, self::IRI_ANNOTATION_NAME)) {
                 $classMetadata = $classMetadata->withAttributeMetadata($attributeName, $attributeMetadata->withIri($iri->value));
             }
         }
     }
     return $classMetadata;
 }
Пример #22
0
 /**
  * Loads from annotations from a class.
  *
  * @param string      $class A class name
  * @param string|null $type  The resource type
  *
  * @return RouteCollection A RouteCollection instance
  *
  * @throws \InvalidArgumentException When route can't be parsed
  */
 public function load($class, $type = null)
 {
     if (!class_exists($class)) {
         throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
     }
     $globals = array('path' => '', 'requirements' => array(), 'options' => array(), 'defaults' => array(), 'schemes' => array(), 'methods' => array(), 'host' => '');
     $class = new \ReflectionClass($class);
     if ($class->isAbstract()) {
         throw new \InvalidArgumentException(sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class));
     }
     if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
         // for BC reasons
         if (null !== $annot->getPath()) {
             $globals['path'] = $annot->getPath();
         } elseif (null !== $annot->getPattern()) {
             $globals['path'] = $annot->getPattern();
         }
         if (null !== $annot->getRequirements()) {
             $globals['requirements'] = $annot->getRequirements();
         }
         if (null !== $annot->getOptions()) {
             $globals['options'] = $annot->getOptions();
         }
         if (null !== $annot->getDefaults()) {
             $globals['defaults'] = $annot->getDefaults();
         }
         if (null !== $annot->getSchemes()) {
             $globals['schemes'] = $annot->getSchemes();
         }
         if (null !== $annot->getMethods()) {
             $globals['methods'] = $annot->getMethods();
         }
         if (null !== $annot->getHost()) {
             $globals['host'] = $annot->getHost();
         }
     }
     $collection = new RouteCollection();
     $collection->addResource(new FileResource($class->getFileName()));
     foreach ($class->getMethods() as $method) {
         $this->defaultRouteIndex = 0;
         foreach ($this->reader->getMethodAnnotations($method) as $annot) {
             if ($annot instanceof $this->routeAnnotationClass) {
                 $this->addRoute($collection, $annot, $globals, $class, $method);
             }
         }
     }
     return $collection;
 }
 protected function getGlobals(\ReflectionClass $class)
 {
     $globals = array('path' => '', 'requirements' => array(), 'options' => array(), 'defaults' => array(), 'schemes' => array(), 'methods' => array(), 'host' => '', 'condition' => '');
     if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
         // for BC reasons
         if (null !== $annot->getPath()) {
             $globals['path'] = $annot->getPath();
         } elseif (null !== $annot->getPattern()) {
             $globals['path'] = $annot->getPattern();
         }
         if (null !== $annot->getRequirements()) {
             $globals['requirements'] = $annot->getRequirements();
         }
         if (null !== $annot->getOptions()) {
             $globals['options'] = $annot->getOptions();
         }
         if (null !== $annot->getDefaults()) {
             $globals['defaults'] = $annot->getDefaults();
         }
         if (null !== $annot->getSchemes()) {
             $globals['schemes'] = $annot->getSchemes();
         }
         if (null !== $annot->getMethods()) {
             $globals['methods'] = $annot->getMethods();
         }
         if (null !== $annot->getHost()) {
             $globals['host'] = $annot->getHost();
         }
         if (null !== $annot->getCondition()) {
             $globals['condition'] = $annot->getCondition();
         }
     }
     return $globals;
 }
Пример #24
0
 public static function loadClass(ReflectionClass $refl, Reader $reader, Router $router)
 {
     $annotation = $reader->getClassAnnotation($refl, 'Destiny\\Common\\Annotation\\Controller');
     if (empty($annotation)) {
         return;
     }
     $methods = $refl->getMethods(ReflectionMethod::IS_PUBLIC);
     foreach ($methods as $method) {
         /** @var Route[] $routes */
         $routes = array();
         $annotations = $reader->getMethodAnnotations($method);
         for ($i = 0; $i < count($annotations); ++$i) {
             /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
             if ($annotations[$i] instanceof \Destiny\Common\Annotation\Route) {
                 $routes[] = $annotations[$i];
             }
         }
         if (count($routes) <= 0) {
             continue;
         }
         /** @var \Destiny\Common\Annotation\HttpMethod $feature */
         $httpMethod = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\HttpMethod');
         /** @var \Destiny\Common\Annotation\Secure $feature */
         $secure = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\Secure');
         for ($i = 0; $i < count($routes); ++$i) {
             $router->addRoute(new Route(array('path' => $routes[$i]->path, 'classMethod' => $method->name, 'class' => $refl->name, 'httpMethod' => $httpMethod ? $httpMethod->allow : null, 'secure' => $secure ? $secure->roles : null)));
         }
     }
 }
Пример #25
0
 /**
  * @param AnnotationReader $reader
  * @param string $className
  * @return Entity
  * @throws \HireVoice\Neo4j\Exception
  */
 public static function fromClass(AnnotationReader $reader, $className)
 {
     $class = new \ReflectionClass($className);
     if ($class->implementsInterface('HireVoice\\Neo4j\\Proxy\\Entity')) {
         $class = $class->getParentClass();
         $className = $class->getName();
     }
     if (!($entity = $reader->getClassAnnotation($class, 'HireVoice\\Neo4j\\Annotation\\Entity'))) {
         throw new Exception("Class {$className} is not declared as an entity.");
     }
     $object = new self($class->getName());
     if ($entity->repositoryClass) {
         $object->repositoryClass = $entity->repositoryClass;
     }
     if ($entity->labels) {
         $object->labels = explode(",", $entity->labels);
     }
     foreach (self::getClassProperties($class->getName()) as $prop) {
         $prop = new Property($reader, $prop);
         if ($prop->isPrimaryKey()) {
             $object->setPrimaryKey($prop);
         } elseif ($prop->isProperty($prop)) {
             $object->properties[] = $prop;
             if ($prop->isIndexed()) {
                 $object->indexedProperties[] = $prop;
             }
         } elseif ($prop->isRelationList()) {
             $object->manyToManyRelations[] = $prop;
         } elseif ($prop->isRelation()) {
             $object->manyToOneRelations[] = $prop;
         }
     }
     $object->validate();
     return $object;
 }
 /**
  * The interceptor is activated for public methods in Transactional annotated components.
  *
  * {@inheritDoc}
  */
 public function matchesMethod(ReflectionMethod $method)
 {
     $transactionalEnabled = false;
     if ($method->isPublic()) {
         // Gets method-level annotation.
         /** @var Transactional $annotation */
         $annotation = $this->reader->getMethodAnnotation($method, Transactional::class);
         $transactionalEnabled = $annotation !== null;
         if (!$transactionalEnabled) {
             // If there is no method-level annotation, gets class-level annotation.
             $annotation = $this->reader->getClassAnnotation($method->getDeclaringClass(), Transactional::class);
             $transactionalEnabled = $annotation !== null;
         }
         if ($transactionalEnabled) {
             switch ($annotation->getPolicy()) {
                 case Transactional::NOT_REQUIRED:
                     $policyName = 'not required';
                     break;
                 case Transactional::REQUIRED:
                     $policyName = 'required';
                     break;
                 case Transactional::NESTED:
                     $policyName = 'nested';
                     break;
                 default:
                     $policyName = 'default';
             }
             $methodString = $method->getDeclaringClass()->name . '::' . $method->name;
             $this->logger->debug('TX policy for \'' . $methodString . '\': ' . $policyName);
             $noRollbackExceptionsStr = implode(', ', $annotation->getNoRollbackExceptions() === null ? ['default'] : $annotation->getNoRollbackExceptions());
             $this->logger->debug('TX no-rollback exceptions for \'' . $methodString . '\': ' . $noRollbackExceptionsStr);
         }
     }
     return $transactionalEnabled;
 }
Пример #27
0
 /**
  * Reads class annotations.
  *
  * @param \ReflectionClass $reflectionClass
  * @param string           $annotationName
  *
  * @return RouteAnnotation|null
  */
 private function readClassAnnotation(\ReflectionClass $reflectionClass, $annotationName)
 {
     $annotationClass = "FOS\\RestBundle\\Controller\\Annotations\\{$annotationName}";
     if ($annotation = $this->annotationReader->getClassAnnotation($reflectionClass, $annotationClass)) {
         return $annotation;
     }
 }
 public static function loadClass(ReflectionClass $refl, Reader $reader)
 {
     $router = Application::instance()->getRouter();
     $annotation = $reader->getClassAnnotation($refl, 'Destiny\\Common\\Annotation\\Controller');
     if (empty($annotation)) {
         return;
     }
     $methods = $refl->getMethods(ReflectionMethod::IS_PUBLIC);
     foreach ($methods as $method) {
         // Get all the route annotations
         $routes = array();
         $annotations = $reader->getMethodAnnotations($method);
         for ($i = 0; $i < count($annotations); ++$i) {
             if ($annotations[$i] instanceof \Destiny\Common\Annotation\Route) {
                 $routes[] = $annotations[$i];
             }
         }
         // No routes, continue
         if (count($routes) <= 0) {
             continue;
         }
         // We have 1 or many routes, add to the router
         $httpMethod = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\HttpMethod');
         $secure = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\Secure');
         $feature = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\Feature');
         for ($i = 0; $i < count($routes); ++$i) {
             $router->addRoute(new Route(array('path' => $routes[$i]->path, 'classMethod' => $method->name, 'class' => $refl->name, 'httpMethod' => $httpMethod ? $httpMethod->allow : null, 'secure' => $secure ? $secure->roles : null, 'feature' => $feature ? $feature->features : null)));
         }
     }
 }
Пример #29
0
 /**
  * @param  string $presenter
  * @param  array $routes
  * @return void
  */
 private function findRoutesInPresenter($presenter, &$routes)
 {
     $r = ClassType::from($presenter);
     $route = $this->reader->getClassAnnotation($r, ApiRoute::class);
     if (!$route) {
         return [];
     }
     /**
      * Add route to priority-half-sorted list
      */
     if (empty($routes[$route->getPriority()])) {
         $routes[$route->getPriority()] = [];
     }
     $route->setDescription($r->getAnnotation('description'));
     if (!$route->getPresenter()) {
         $route->setPresenter(preg_replace('/Presenter$/', '', $r->getShortName()));
     }
     /**
      * Find apropriate methods
      */
     foreach ($r->getMethods() as $method_r) {
         $this->findPresenterMethodRoute($method_r, $routes, $route);
     }
     $routes[$route->getPriority()][] = $route;
 }
 /**
  * @internal
  * @param Reader $annotationReader
  * @return string
  * @throws InvalidAnnotationException
  */
 static function getEntityClassName(Reader $annotationReader)
 {
     $reflect = new ReflectionClass(get_called_class());
     $annotation = $annotationReader->getClassAnnotation($reflect, Entity::class);
     InvalidAnnotationException::assert($annotation, Entity::class);
     return $annotation->className;
 }