本文整理汇总了PHP中Doctrine\Common\Annotations\AnnotationReader::getClassAnnotation方法的典型用法代码示例。如果您正苦于以下问题:PHP AnnotationReader::getClassAnnotation方法的具体用法?PHP AnnotationReader::getClassAnnotation怎么用?PHP AnnotationReader::getClassAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Annotations\AnnotationReader
的用法示例。
在下文中一共展示了AnnotationReader::getClassAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: realpath
/**
* @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);
}
示例2: loadMetadataForClass
/**
* 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()]);
}
}
}
示例3: getProperties
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;
}
示例4: orderOf
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;
}
示例5: parseClass
/**
* 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;
}
}
示例6: parseClass
/**
* 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;
}
}
示例7: indexEntity
/**
* 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;
}
示例8: parseClass
/**
* 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;
}
}
示例9: create
/**
* @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;
}
示例10: getClassMetadata
/**
* @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;
}
示例11: guessType
/**
* {@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);
}
示例12: execute
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));
}
示例13: execute
/**
* {@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();
}
示例14: persist
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;
}
}
示例15: __construct
/**
* 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);
}
}