/** * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container * @param \Doctrine\Common\Annotations\AnnotationReader $annotationReader * @param \FSi\Bundle\AdminBundle\Finder\AdminClassFinder $adminClassFinder */ function it_registers_annotated_admin_classes_as_services($container, $annotationReader, $adminClassFinder) { $container->getParameter('kernel.bundles')->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\MyBundle', 'FSi\\Bundle\\AdminBundle\\FSiAdminBundle', 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle')); $baseDir = __DIR__ . '/../../../../../..'; $adminClassFinder->findClasses(array(realpath($baseDir . '/spec/fixtures/Admin'), realpath($baseDir . '/Admin')))->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement')); $annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(null); $annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(new Element(array())); $container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/spec/fixtures/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled(); $container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled(); $container->addDefinitions(Argument::that(function ($definitions) { if (count($definitions) !== 1) { return false; } /** @var \Symfony\Component\DependencyInjection\Definition $definition */ $definition = $definitions[0]; if ($definition->getClass() !== 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement') { return false; } if (!$definition->hasTag('admin.element')) { return false; } return true; }))->shouldBeCalled(); $this->process($container); }
/** * Loads the metadata for the specified class into the provided container. * * @param string $className * @param ClassMetadata $metadata */ public function loadMetadataForClass($className, ClassMetadata $metadata) { $class = $metadata->getReflectionClass(); if (!$class) { // this happens when running annotation driver in combination with // static reflection services. This is not the nicest fix $class = new \ReflectionClass($metadata->name); } $entityAnnot = $this->reader->getClassAnnotation($class, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Entity'); if (!$entityAnnot) { throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.'); } $metadata->storageName = $entityAnnot->storageName; // Evaluate annotations on properties/fields foreach ($class->getProperties() as $property) { $idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Id'); $transientAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Transient'); if ($idAnnot) { $metadata->mapIdentifier($property->getName()); } elseif ($transientAnnot) { $metadata->skipTransientField($property->getName()); } else { $metadata->mapField(['fieldName' => $property->getName()]); } } }
protected function getProperties($object) { $reflClass = new \ReflectionClass($object); $codeAnnotation = $this->annotationReader->getClassAnnotation($reflClass, Segment::class); if (!$codeAnnotation) { throw new AnnotationMissing(sprintf("Missing @Segment annotation for class %", $reflClass->getName())); } $properties = [$codeAnnotation->value]; foreach ($reflClass->getProperties() as $propRefl) { $propRefl->setAccessible(true); /** @var SegmentPiece $isSegmentPiece */ $isSegmentPiece = $this->annotationReader->getPropertyAnnotation($propRefl, SegmentPiece::class); if ($isSegmentPiece) { if (!$isSegmentPiece->parts) { $properties[$isSegmentPiece->position] = $propRefl->getValue($object); } else { $parts = $isSegmentPiece->parts; $value = $propRefl->getValue($object); $valuePieces = []; foreach ($parts as $key => $part) { if (is_integer($key)) { $partName = $part; } else { $partName = $key; } $valuePieces[] = isset($value[$partName]) ? $value[$partName] : null; } $properties[$isSegmentPiece->position] = $this->weedOutEmpty($valuePieces); } } } $properties = $this->weedOutEmpty($properties); return $properties; }
public function orderOf(EventListenerInterface $listener) { $order = $this->reader->getClassAnnotation(new \ReflectionClass($listener), Order::class); if (null === $order && $listener instanceof EventListenerProxyInterface) { $order = $this->reader->getClassAnnotation(new \ReflectionClass($listener->getTargetType()), Order::class); } return null === $order ? 0 : $order->value; }
/** * Parse a class. * * @param array $annotations * @return string|null */ public function parseClass($class) { $reflectionClass = new ReflectionClass($class); // check if class is entity if ($annotation = $this->reader->getClassAnnotation($reflectionClass, '\\ProAI\\Datamapper\\Annotations\\Presenter')) { return $this->parsePresenter($class, $annotation); } else { return null; } }
/** * Parse a class. * * @param string $class * @return array|null */ public function parseClass($class) { $reflectionClass = new ReflectionClass($class); // check if class is controller if ($annotation = $this->reader->getClassAnnotation($reflectionClass, '\\ProAI\\Annotations\\Annotations\\Controller')) { return $this->parseController($class); } else { return null; } }
/** * Start indexing entity for the indexer specific content * * @param EntityStructure $structure Structure reference * @return mixed * @throws InvalidAnnotationException */ public function indexEntity(&$structure) { $table = $this->reader->getClassAnnotation($this->entityClass, Table::class); if (!$table instanceof Table) { throw new InvalidAnnotationException("Entity '" . $this->entityClass->getName() . "' has no Table entity!"); // @codeCoverageIgnore } if ($table->name == null) { throw new InvalidAnnotationException("Entity '" . $this->entityClass->getName() . "' is required to have the name parameter in the Table annotation."); // @codeCoverageIgnore } $structure->table = $table; $structure->tableName = $table->name; }
/** * Parse a class. * * @param string $class * @return array|null */ public function parseClass($class) { $reflectionClass = new ReflectionClass($class); // check if class is controller if ($annotation = $this->reader->getClassAnnotation($reflectionClass, '\\ProAI\\Annotations\\Annotations\\Hears')) { $class = $annotation->value; if (isset($this->config['events_namespace']) && substr($class, 0, strlen($this->config['events_namespace'])) != $this->config['events_namespace']) { $class = $this->config['events_namespace'] . '\\' . $class; } return $class; } else { return null; } }
/** * @param $datagridClass * @return \Abbert\Datagrid\Datagrid * @throws \Exception */ public function create($datagridClass) { // annotation reader $reflection = new \ReflectionClass($datagridClass); $reader = new AnnotationReader(); $annotationDatagrid = $reader->getClassAnnotation($reflection, 'Abbert\\DatagridBundle\\Annotation\\Datagrid'); // datasource $annotation = $reader->getClassAnnotation($reflection, 'Abbert\\DatagridBundle\\Annotation\\DoctrineSource'); $setDatasource = null; if ($annotation !== null && $annotation->entityClass != '') { $repo = $this->entityManager->getRepository($annotation->entityClass); $setDatasource = new DoctrineSource($repo); } if (isset($this->serviceIds[$datagridClass])) { // service $service = $this->container->get($this->serviceIds[$datagridClass]); if ($service instanceof \Abbert\Datagrid\Datagrid) { $datagrid = clone $service; } else { $datagrid = new \Abbert\Datagrid\Datagrid(); $service->create($datagrid); } } else { // normale class, hier worden dependencies ondersteund $deps = []; if ($annotationDatagrid !== null && count($annotationDatagrid->dependencies)) { foreach ($annotationDatagrid->dependencies as $dep) { if (strstr($dep, '@')) { $deps[] = $this->container->get(str_replace('@', '', $dep)); } else { if (strstr('%', '', $dep)) { $deps[] = $this->container->getParameter(str_replace('%', '', $dep)); } } } } if ($setDatasource !== null) { $deps[] = $setDatasource; } $datagrid = call_user_func_array(array($reflection, 'newInstance'), $deps); } // configuratie $datagrid->setViewPath($this->viewPath); if ($setDatasource !== null) { $datagrid->setDatasource($setDatasource); } return $datagrid; }
/** * @param string $classname * @return array */ public function getClassMetadata($classname) { $classMetadata = []; $reflexionClass = $this->getReflectionClass($classname); $classAnnotations = $this->reader->getClassAnnotations($reflexionClass); foreach ($classAnnotations as $classAnnotation) { if (!isset($classMetadata[get_class($classAnnotation)])) { $classMetadata[get_class($classAnnotation)] = []; } $classMetadata[get_class($classAnnotation)][] = $classAnnotation; } if ($this->reader->getClassAnnotation($reflexionClass, ParentClass::class)) { $classMetadata = array_merge_recursive($this->getClassMetadata(get_parent_class($classname)), $classMetadata); } return $classMetadata; }
/** * {@inheritdoc} */ public function guessType($class, $property) { $metadata = $this->getClassMetadata($class); if (!$metadata->hasAssociation($property)) { return null; } $multiple = $metadata->isCollectionValuedAssociation($property); $annotationReader = new AnnotationReader(); $associationMapping = $metadata->getAssociationMapping($property); $associationMetadata = $this->getClassMetadata($associationMapping['targetEntity']); if (null === $annotationReader->getClassAnnotation($associationMetadata->getReflectionClass(), static::TREE_ANNOTATION)) { return null; } $levelProperty = null; $parentProperty = null; foreach ($associationMetadata->getReflectionProperties() as $property) { if ($annotationReader->getPropertyAnnotation($property, static::TREE_LEVEL_ANNOTATION)) { $levelProperty = $property->getName(); } if ($annotationReader->getPropertyAnnotation($property, static::TREE_PARENT_ANNOTATION)) { $parentProperty = $property->getName(); } } if (null === $levelProperty || null === $parentProperty) { return null; } return new TypeGuess('tree_choice', ['class' => $associationMapping['targetEntity'], 'multiple' => $multiple, 'level_property' => $levelProperty, 'parent_property' => $parentProperty], Guess::VERY_HIGH_CONFIDENCE); }
protected function execute(InputInterface $input, OutputInterface $output) { // get repository $entityClass = $input->getArgument('entityClass'); $repository = $this->getHelper('em')->getEntityManager()->getRepository($entityClass); $reflClass = new ReflectionClass($entityClass); $reader = new AnnotationReader(); $annotation = $reader->getClassAnnotation($reflClass, '\\Keratine\\Lucene\\Mapping\\Annotation\\Indexable'); if (!$annotation) { $output->writeln(sprintf('<error>%s must define the "%s" annotation.</error>', $entityClass, '\\Keratine\\Lucene\\Mapping\\Annotation\\Indexable')); return; } $indexManager = new IndexManager($this->getHelper('zendsearch')->getIndices()[$annotation->index]); // delete all indexed documents $numDocs = $indexManager->numDocs(); for ($id = 0; $id < $numDocs; $id++) { $indexManager->delete($id); } // index each entity foreach ($repository->findAll() as $entity) { $indexManager->index($entity); } // optimize index $indexManager->optimize(); // get number of indexed documents $numDocs = $indexManager->numDocs(); $output->writeln(sprintf('<info>%d document(s) indexed</info>', $numDocs)); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $reader = new AnnotationReader(); /** @var ManagerRegistry $doctrine */ $doctrine = $this->getContainer()->get('doctrine'); $em = $doctrine->getManager(); $cmf = $em->getMetadataFactory(); $existing = []; $created = []; /** @var ClassMetadata $metadata */ foreach ($cmf->getAllMetadata() as $metadata) { $refl = $metadata->getReflectionClass(); if ($refl === null) { $refl = new \ReflectionClass($metadata->getName()); } if ($reader->getClassAnnotation($refl, 'Padam87\\AttributeBundle\\Annotation\\Entity') != null) { $schema = $em->getRepository('Padam87AttributeBundle:Schema')->findOneBy(['className' => $metadata->getName()]); if ($schema === null) { $schema = new Schema(); $schema->setClassName($metadata->getName()); $em->persist($schema); $em->flush($schema); $created[] = $metadata->getName(); } else { $existing[] = $metadata->getName(); } } } $table = new Table($output); $table->addRow(['Created:', implode(PHP_EOL, $created)]); $table->addRow(new TableSeparator()); $table->addRow(['Existing:', implode(PHP_EOL, $existing)]); $table->render(); }
public function persist($entity) { $reflection = new \ReflectionClass($entity); $originURI = $entity->getOrigin(); if (!$originURI) { throw new \Exception("Cannot persist entity, because origin URI is not defined"); } $sparql = ''; $annotationReader = new AnnotationReader(); $iri = $annotationReader->getClassAnnotation($reflection, 'Soil\\DiscoverBundle\\Annotation\\Iri'); if ($iri) { $iri = $iri->value; $sparql .= "<{$originURI}> rdf:type {$iri} . " . PHP_EOL; } $props = $reflection->getProperties(); foreach ($props as $prop) { $matchAnnotation = $annotationReader->getPropertyAnnotation($prop, 'Soil\\DiscoverBundle\\Annotation\\Iri'); if ($matchAnnotation && $matchAnnotation->persist) { $match = $matchAnnotation->value; $prop->setAccessible(true); $value = $prop->getValue($entity); $sparql .= "<{$originURI}> {$match} <{$value}> . " . PHP_EOL; } } if ($sparql) { $this->logger->addInfo('Persisting: '); $this->logger->addInfo($sparql); $num = $this->endpoint->insert($sparql); $this->logger->addInfo('Return: ' . print_r($num, true)); return $num; } else { return null; } }
/** * Entity Indexer * @param string|EntityClass $entityClassName * * @throws InvalidAnnotationException Invalid annotations used */ public function __construct($entityClassName) { $this->entityClass = new \ReflectionClass($entityClassName); if (!$this->entityClass->isSubclassOf("\\SweetORM\\Entity")) { throw new \UnexpectedValueException("The className for getTable should be a class that is extending the SweetORM Entity class"); // @codeCoverageIgnore } $this->entity = new EntityStructure(); $this->entity->name = $this->entityClass->getName(); // Reader $reader = new AnnotationReader(); $this->classAnnotations = $reader->getClassAnnotations($this->entityClass); $this->entityAnnotation = $reader->getClassAnnotation($this->entityClass, EntityClass::class); // Validate Entity annotation if ($this->entityAnnotation === null || !$this->entityAnnotation instanceof EntityClass) { throw new InvalidAnnotationException("Entity '" . $this->entityClass->getName() . "' should use Annotations to use it! Please look at the documentation for help."); // @codeCoverageIgnore } // Run all the indexers foreach (self::$indexers as $indexerClass) { $indexerFullClass = "\\SweetORM\\Structure\\Indexer\\" . $indexerClass; /** @var Indexer $instance */ $instance = new $indexerFullClass($this->entityClass, $reader); $instance->indexEntity($this->entity); } }
/** * {@inheritdoc} */ protected function tryReadOption($name, &$out, $default = null) { $out = $default; if (!$this->reflectionClass) { return false; } try { $annotationName = static::ANNOTATION_NAMESPACE . ucfirst($name); // try { // // Inspects method first, since method has priority over class // $methodAnnotation = $this // ->annotationReader // ->getMethodAnnotation( // $this->reflectionMethod, // $annotationName); // // if ($methodAnnotation // && $methodAnnotation instanceof AbstractAnnotation // ) { // $out = $methodAnnotation->values(); // return true; // } // } catch (\Exception $ex) { // } // If we do not have method annotation, // then look at the class annotation $class = $this->reflectionClass; while ($class) { try { $classAnnotation = $this->annotationReader->getClassAnnotation($class, $annotationName); if ($classAnnotation && $classAnnotation instanceof AbstractAnnotation) { $out = $classAnnotation->values(); return true; } } catch (\Exception $ex) { } $class = $class->getParentClass(); } } catch (\Exception $ex) { // Lazily catch any exception and return false, and set // $out to default value $out = $default; return false; } // sad, no method nor class annotation? return false; }
/** * @covers \Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonInclude */ public function testBasic() { AnnotationRegistry::registerFile(__DIR__ . '/../../../../../lib/Weasel/JsonMarshaller/Config/DoctrineAnnotations/JsonInclude.php'); $annotationReader = new AnnotationReader(); $got = $annotationReader->getClassAnnotation(new \ReflectionClass(__NAMESPACE__ . '\\JsonIncludeTestVictim'), __NAMESPACE__ . '\\JsonInclude'); $this->assertInstanceOf(__NAMESPACE__ . '\\JsonInclude', $got); $this->assertEquals(JsonInclude::INCLUDE_ALWAYS, $got->getValue()); }
/** * @param LoadClassMetadataEventArgs $args * * @return void */ public function loadClassMetadata(LoadClassMetadataEventArgs $args) { //in the installer if (!defined('MAUTIC_TABLE_PREFIX')) { return; } /** @var \Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata */ $classMetadata = $args->getClassMetadata(); // Do not re-apply the prefix in an inheritance hierarchy. if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) { return; } if (FALSE !== strpos($classMetadata->namespace, 'Mautic')) { //if in the installer, use the prefix set by it rather than what is cached $prefix = MAUTIC_TABLE_PREFIX; // Prefix indexes $uniqueConstraints = array(); if (isset($classMetadata->table['uniqueConstraints'])) { foreach ($classMetadata->table['uniqueConstraints'] as $name => $uc) { $uniqueConstraints[$prefix . $name] = $uc; } } $indexes = array(); if (isset($classMetadata->table['indexes'])) { foreach ($classMetadata->table['indexes'] as $name => $uc) { $indexes[$prefix . $name] = $uc; } } // Prefix the table $classMetadata->setPrimaryTable(array('name' => $prefix . $classMetadata->getTableName(), 'indexes' => $indexes, 'uniqueConstraints' => $uniqueConstraints)); foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) { $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name']; $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $prefix . $mappedTableName; } } // Prefix sequences if supported by the DB platform if ($classMetadata->isIdGeneratorSequence()) { $newDefinition = $classMetadata->sequenceGeneratorDefinition; $newDefinition['sequenceName'] = $prefix . $newDefinition['sequenceName']; $classMetadata->setSequenceGeneratorDefinition($newDefinition); $em = $args->getEntityManager(); if (isset($classMetadata->idGenerator)) { $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator($em->getConfiguration()->getQuoteStrategy()->getSequenceName($newDefinition, $classMetadata, $em->getConnection()->getDatabasePlatform()), $newDefinition['allocationSize']); $classMetadata->setIdGenerator($sequenceGenerator); } } $reader = new AnnotationReader(); $class = $classMetadata->getReflectionClass(); $annotation = $reader->getClassAnnotation($class, 'Mautic\\CoreBundle\\Doctrine\\Annotation\\LoadClassMetadataCallback'); if (null !== $annotation) { if (method_exists($class->getName(), $annotation->functionName['value'])) { $func = $class->getName() . '::' . $annotation->functionName['value']; call_user_func($func, $args); } } } }
/** * @param string $entity * @param string $annotationName * * @return SynchronizationFilter */ private function getClassAnnotation($entity, $annotationName) { $reflectionClass = new \ReflectionClass($entity); $annotation = $this->reader->getClassAnnotation($reflectionClass, $annotationName); if ($annotation === null && $reflectionClass->getParentClass()) { $annotation = $this->reader->getClassAnnotation($reflectionClass->getParentClass(), $annotationName); } return $annotation; }
/** * @covers \Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonIgnoreProperties */ public function testIgnoreUsage() { AnnotationRegistry::registerFile(__DIR__ . '/../../../../../lib/Weasel/JsonMarshaller/Config/DoctrineAnnotations/JsonIgnoreProperties.php'); $annotationReader = new AnnotationReader(); $got = $annotationReader->getClassAnnotation(new \ReflectionClass(__NAMESPACE__ . '\\JsonIgnorePropertiesTestVictimD'), __NAMESPACE__ . '\\JsonIgnoreProperties'); $this->assertInstanceOf(__NAMESPACE__ . '\\JsonIgnoreProperties', $got); $this->assertEquals(array(), $got->getNames()); $this->assertTrue($got->getIgnoreUnknown()); }
/** * @param string $class * * @return Metadata */ public function create($class) { $reader = new AnnotationReader(); $reflClass = new ReflectionClass($class); $resource = $reader->getClassAnnotation($reflClass, Resource::class); $hal = $reader->getClassAnnotation($reflClass, Hal::class); $metadata = new Metadata($reflClass); $metadata->setResource($resource->value); $metadata->setRepositoryClass($resource->repositoryClass); $identifier = $this->getIdentifier($reflClass, $reader); if (null === $identifier) { throw new MissingIdentifierMappingException('You must specify an identifier mapping.'); } if (null !== $hal) { $metadata->setEmbeddedRel($hal->embeddedRel); } $metadata->setIdentifier($identifier); return $metadata; }
/** * Register the controller if a Controller annotation exists in the class doc block or $controllerAnnotation is provided. * * @param string $controllerName */ public function registerController($controllerName) { $reflectionClass = new ReflectionClass($controllerName); $annotationClassName = "\\DDesrosiers\\SilexAnnotations\\Annotations\\Controller"; $controllerAnnotation = $this->reader->getClassAnnotation($reflectionClass, $annotationClassName); if ($controllerAnnotation instanceof Controller) { $this->app['annot.registerServiceController'](trim($controllerName, "\\")); $controllerAnnotation->process($this->app, $reflectionClass); } }
public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); $method = $request->attributes->get('_controller'); $class_full = explode("::", $method); if (sizeof($class_full) != 2) { return; } if ($class_full[1] != "indexAction") { return; } $class = trim($class_full[0]); $reflectionClass = new \ReflectionClass($class); $reader = new AnnotationReader(); $hdata = $reader->getClassAnnotation($reflectionClass, 'BOS\\ApiBundle\\Annotations\\BOSApiController'); if ($hdata) { $i = -1; $methods = array(); $methodsArray = $reflectionClass->getMethods(); foreach ($methodsArray as $m) { $currentFullMethod = $class . "::" . $m->getName(); $collection = $this->router->getRouteCollection()->all(); $url = null; foreach ($collection as $route => $params) { $defaults = $params->getDefaults(); if (isset($defaults['_controller'])) { if ($currentFullMethod == $defaults['_controller']) { $url = $this->router->generate($route); } } } //die("ffFF"); $rm = new \ReflectionMethod($class . "::" . $m->getName()); $data = $reader->getMethodAnnotation($rm, 'BOS\\ApiBundle\\Annotations\\BOSApiMethod'); if ($data) { /* Method data, POST OR GET OR ANY */ $mData = $reader->getMethodAnnotation($rm, "Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Method"); $nMethods = array(); if ($mData) { $nMethods = $mData->getMethods(); } if (!$url) { die("BOSApiBundle fatal error: couldn't generate route for: " . $rm->getName()); } $i++; $data->url = $url; $data->methods = $nMethods; $methods[$i] = $data; } } $message = $this->render->render("BOSApiBundle:Default:index.html.twig", array("api_header" => $hdata, "api_methods" => $methods)); $response = new Response($message); $event->setResponse($response); } }
/** * @param array $paths * @return array */ private function findAnnotatedAdminClasses(array $paths) { $annotatedAdminClasses = array(); foreach ($this->adminClassFinder->findClasses($paths) as $class) { $annotation = $this->annotationReader->getClassAnnotation(new \ReflectionClass($class), self::ANNOTATION_CLASS); if (isset($annotation) && $annotation instanceof Element) { $annotatedAdminClasses[] = $class; } } return $annotatedAdminClasses; }
/** * Lazy-load @Entity annotation * * @return EntityAnnotation */ public function getEntityAnnotation() { if ($this->entity_annotation === null) { /** @var EntityAnnotation $entity */ $this->entity_annotation = $this->annotation_reader->getClassAnnotation($this->reflection_obj, self::ENTITY_ANNOTATION); if (!$this->entity_annotation) { throw new InvalidEntityException('Entity "' . $this->class_name . '" does not contain an @Entity annotation'); } } return $this->entity_annotation; }
/** * @param $class * @return array */ public function readAnnotation($class) { $annotation = []; $reader = new AnnotationReader(); $drupalCommandAnnotation = $reader->getClassAnnotation(new \ReflectionClass($class), 'Drupal\\Console\\Annotations\\DrupalCommand'); if ($drupalCommandAnnotation) { $annotation['extension'] = $drupalCommandAnnotation->extension ?: ''; $annotation['extensionType'] = $drupalCommandAnnotation->extensionType ?: ''; $annotation['dependencies'] = $drupalCommandAnnotation->dependencies ?: []; } return $annotation; }
/** * @param string $class * @return string */ private function getTranslationClassName($class) { $reflectionClass = new \ReflectionClass($class); $namespace = $reflectionClass->getNamespaceName(); $reader = new AnnotationReader(); $annotationClass = $reader->getClassAnnotation($reflectionClass, 'DavidDel\\DoctrineIntlBundle\\Mapping\\Annotation\\TranslatableEntity'); $class = $annotationClass->translationClass; if (!class_exists($class)) { $class = $namespace . '\\' . $class; } return $class; }
/** * Get model name of an entity * @param $entity string Class name of the entity * @return mixed|null */ public function getModelName($entity) { $classRef = new \ReflectionClass($entity); $classModelAnnotation = $this->annoReader->getClassAnnotation($classRef, 'Tpg\\ExtjsBundle\\Annotation\\Model'); if ($classModelAnnotation !== null) { if ($classModelAnnotation->name) { return $classModelAnnotation->name; } else { return str_replace("\\", ".", $classRef->getName()); } } return null; }
/** * @return void * @throws AnnotationBuilderException */ private function buildForClass() { $class = $this->reflectionClass(); $webServiceAnnotation = $this->annotationReader->getClassAnnotation($class, '\\WSDL\\Annotation\\WebService'); if ($webServiceAnnotation === null) { throw new AnnotationBuilderException('Class must have @WebService annotation'); } /** @var ClassAnnotation[] $classAnnotations */ $classAnnotations = $this->annotationReader->getClassAnnotations($class); foreach ($classAnnotations as $classAnnotation) { $classAnnotation->build($this->builder, $class); } }
public function onKernelController(FilterControllerEvent $event) { $controller = $event->getController(); if (!is_array($controller) || !$controller[0] instanceof RestController) { return; } $action = $controller[1]; $controller = $controller[0]; $reflection = new \ReflectionObject($controller); $reader = new AnnotationReader(); $authorize = $reader->getClassAnnotation($reflection, Authorize::class); $methodAuthorize = $reader->getMethodAnnotation($reflection->getMethod($action), Authorize::class); if ($methodAuthorize != null) { $authorize = $methodAuthorize; } $config = $this->container->getParameter("rest.config")["authentication"]; if ($authorize != null && $config["enabled"]) { $authHeader = $event->getRequest()->headers->get("authorization", "null null"); $explode = explode(" ", $authHeader); $type = $explode[0]; $token = $explode[1]; if ($authHeader == "null null") { $this->unauth(); } if (strtolower($type) != "bearer") { $this->unauth(); } $type = $config["oauth_type"]; if ($type == "own") { /** @var OAuthService $oauthService */ $oauthService = $this->container->get("rest.oauth_service"); $authToken = $oauthService->getAuthToken($token); if ($authToken == null) { $this->unauth(); } $session = new Session(new MockArraySessionStorage()); $session->set("token", $authToken); $session->set("consumer", $authToken->getConsumer()); $session->set("user", $authToken->getUser()); $event->getRequest()->setSession($session); } else { if ($type == "static") { $tokens = $config["oauth"]["static_tokens"]; if (!in_array($token, $tokens)) { $this->unauth(); } } } } }