本文整理汇总了PHP中Doctrine\Common\Annotations\AnnotationReader类的典型用法代码示例。如果您正苦于以下问题:PHP AnnotationReader类的具体用法?PHP AnnotationReader怎么用?PHP AnnotationReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AnnotationReader类的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: 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;
}
}
示例3: setUp
public function setUp()
{
$config = new Configuration();
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$reader = new AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
$config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
$this->dm = DocumentManager::create(new Mongo(), $config);
$currencies = array('USD' => 1, 'EURO' => 1.7, 'JPN' => 0.0125);
foreach ($currencies as $name => &$multiplier) {
$multiplier = new Currency($name, $multiplier);
$this->dm->persist($multiplier);
}
$product = new ConfigurableProduct('T-Shirt');
$product->addOption(new Option('small', new Money(12.99, $currencies['USD']), new StockItem('T-shirt Size S', new Money(9.99, $currencies['USD']), 15)));
$product->addOption(new Option('medium', new Money(14.99, $currencies['USD']), new StockItem('T-shirt Size M', new Money(11.99, $currencies['USD']), 15)));
$product->addOption(new Option('large', new Money(17.99, $currencies['USD']), new StockItem('T-shirt Size L', new Money(13.99, $currencies['USD']), 15)));
$this->dm->persist($product);
$this->dm->flush();
foreach ($currencies as $currency) {
$this->dm->detach($currency);
}
$this->dm->detach($product);
unset($currencies, $product);
}
示例4: testParseAnnotationDocblocks
public function testParseAnnotationDocblocks()
{
$class = new \ReflectionClass(__NAMESPACE__ . '\\DCOM55Annotation');
$reader = new AnnotationReader();
$annots = $reader->getClassAnnotations($class);
$this->assertEquals(0, count($annots));
}
示例5: testPdfAnnotationIsCorrectlyCreatedByReader
/**
* @Pdf()
*/
public function testPdfAnnotationIsCorrectlyCreatedByReader()
{
$reader = new AnnotationReader();
$method = new \ReflectionMethod($this, 'testPdfAnnotationIsCorrectlyCreatedByReader');
$pdf = $reader->getMethodAnnotation($method, 'Ps\\PdfBundle\\Annotation\\Pdf');
$this->assertNotNull($pdf);
}
示例6: 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);
}
示例7: 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();
}
示例8: create
/**
* @param string $className
* @return Datagrid
*/
public function create($className)
{
/** @var \Doctrine\ORM\EntityManager $entityManager */
$entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
$metadata = $entityManager->getClassMetadata($className);
$reflection = $metadata->getReflectionClass();
$datagridSpec = new ArrayObject(array('className' => $className, 'primaryKey' => $metadata->getSingleIdentifierFieldName(), 'name' => array('singular' => '', 'plural' => ''), 'defaultSort' => null, 'headerColumns' => array(), 'searchColumns' => array(), 'suggestColumns' => array()));
$reader = new AnnotationReader();
foreach ($reader->getClassAnnotations($reflection) as $annotation) {
$params = compact('datagridSpec', 'annotation');
$this->getEventManager()->trigger('discoverTitle', $this, $params);
}
foreach ($reflection->getProperties() as $property) {
foreach ($reader->getPropertyAnnotations($property) as $annotation) {
$params = compact('datagridSpec', 'annotation', 'property');
$this->getEventManager()->trigger('configureColumn', $this, $params);
}
}
foreach ($reflection->getMethods() as $method) {
foreach ($reader->getMethodAnnotations($method) as $annotation) {
$params = compact('datagridSpec', 'annotation', 'method');
$this->getEventManager()->trigger('configureColumn', $this, $params);
}
}
$this->datagrids[$className] = new Datagrid($entityManager, $datagridSpec->getArrayCopy());
return $this->datagrids[$className];
}
示例9: __construct
public function __construct($consumerWorker, ConnectionFactory $connectionFactory)
{
$this->connectionFactory = $connectionFactory;
$className = get_class($consumerWorker);
$reflectionClass = new \ReflectionClass($className);
$reader = new AnnotationReader();
$methods = $reflectionClass->getMethods();
foreach ($methods as $method) {
$methodAnnotations = $reader->getMethodAnnotations($method);
foreach ($methodAnnotations as $annotation) {
if ($annotation instanceof Annotation\Consumer) {
$parameters = $method->getParameters();
$taskClassName = false;
if (!empty($parameters)) {
$taskClass = $parameters[0]->getClass();
$isMessage = $taskClass->implementsInterface('IvixLabs\\RabbitmqBundle\\Message\\MessageInterface');
if (!$isMessage) {
throw new \InvalidArgumentException('Task must implmenet IvixLabs\\RabbitmqBundle\\Message\\MessageInterface');
}
$taskClassName = $taskClass->getName();
}
$key = $annotation->connectionName . '_' . $annotation->channelName . '_' . $annotation->exchangeName . '_' . $annotation->routingKey;
if (!isset($this->taskClasses[$key])) {
$this->taskClasses[$key] = [];
}
$this->taskClasses[$key][] = [$taskClassName, $method->getClosure($consumerWorker), $annotation];
}
}
}
}
示例10: setUp
public function setUp()
{
$config = new Configuration();
$config->setProxyDir(__DIR__ . '/../../../../Proxies');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir(__DIR__ . '/../../../../Hydrators');
$config->setHydratorNamespace('Hydrators');
$config->setDefaultDB('doctrine_odm_tests');
/*
$config->setLoggerCallable(function(array $log) {
print_r($log);
});
$config->setMetadataCacheImpl(new ApcCache());
*/
$reader = new AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ODM\MongoDB\Mapping\\');
$this->annotationDriver = new AnnotationDriver($reader, __DIR__ . '/../../../../Documents');
$config->setMetadataDriverImpl($this->annotationDriver);
$conn = new Connection(null, array(), $config);
$this->dm = DocumentManager::create($conn, $config);
$this->uow = $this->dm->getUnitOfWork();
}
示例11: readExtendedMetadata
/**
* (non-PHPdoc)
* @see Gedmo\Mapping.Driver::readExtendedMetadata()
*/
public function readExtendedMetadata(ClassMetadataInfo $meta, array &$config)
{
require_once __DIR__ . '/../Annotations.php';
$reader = new AnnotationReader();
$reader->setAnnotationNamespaceAlias('Gedmo\\Timestampable\\Mapping\\', 'gedmo');
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || $meta->isInheritedAssociation($property->name)) {
continue;
}
if ($timestampable = $reader->getPropertyAnnotation($property, self::ANNOTATION_TIMESTAMPABLE)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw MappingException::fieldMustBeMapped($field, $meta->name);
}
if (!$this->_isValidField($meta, $field)) {
throw MappingException::notValidFieldType($field, $meta->name);
}
if (!in_array($timestampable->on, array('update', 'create', 'change'))) {
throw MappingException::triggerTypeInvalid($field, $meta->name);
}
if ($timestampable->on == 'change') {
if (!isset($timestampable->field) || !isset($timestampable->value)) {
throw MappingException::parametersMissing($field, $meta->name);
}
$field = array('field' => $field, 'trackedField' => $timestampable->field, 'value' => $timestampable->value);
}
// properties are unique and mapper checks that, no risk here
$config[$timestampable->on][] = $field;
}
}
}
示例12: testBasicClassAnnotations
/**
* @covers \Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonAnySetter
*/
public function testBasicClassAnnotations()
{
AnnotationRegistry::registerFile(__DIR__ . '/../../../../../lib/Weasel/JsonMarshaller/Config/DoctrineAnnotations/JsonAnySetter.php');
$annotationReader = new AnnotationReader();
$got = $annotationReader->getMethodAnnotations(new \ReflectionMethod(__NAMESPACE__ . '\\JsonAnySetterTestVictim', 'basic'));
$this->assertEquals(array(new JsonAnySetter()), $got);
}
示例13: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$model = $input->getArgument('model');
$seeds = $input->getArgument('seeds');
$io = new SymfonyStyle($input, $output);
if (!class_exists($model)) {
$io->error(array('The model you specified does not exist.', 'You can create a model with the "model:create" command.'));
return 1;
}
$this->dm = $this->createDocumentManager($input->getOption('server'));
$faker = Faker\Factory::create();
AnnotationRegistry::registerAutoloadNamespace('Hive\\Annotations', dirname(__FILE__) . '/../../');
$reflectionClass = new \ReflectionClass($model);
$properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);
$reader = new AnnotationReader();
for ($i = 0; $i < $seeds; $i++) {
$instance = new $model();
foreach ($properties as $property) {
$name = $property->getName();
$seed = $reader->getPropertyAnnotation($property, 'Hive\\Annotations\\Seed');
if ($seed !== null) {
$fake = $seed->fake;
if (class_exists($fake)) {
$instance->{$name} = $this->createFakeReference($fake);
} else {
$instance->{$name} = $faker->{$seed->fake};
}
}
}
$this->dm->persist($instance);
}
$this->dm->flush();
$io->success(array("Created {$seeds} seeds for {$model}"));
}
示例14: 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));
}
示例15: loadMetadataForClass
public function loadMetadataForClass($className)
{
$metadata = new ClassMetadata($className);
$reflectionClass = new \ReflectionClass($className);
$reflectionProperties = $reflectionClass->getProperties();
foreach ($reflectionProperties as $reflectionProperty) {
$name = $reflectionProperty->getName();
$pMetadata = new PropertyMetadata($name);
$annotations = $this->reader->getPropertyAnnotations($reflectionProperty);
foreach ($annotations as $annotation) {
if ($annotation instanceof Annotations\Expose) {
$pMetadata->setExpose((bool) $annotation->value);
} elseif ($annotation instanceof Annotations\Type) {
$pMetadata->setType((string) $annotation->value);
} elseif ($annotation instanceof Annotations\Groups) {
$pMetadata->setGroups($annotation->value);
} elseif ($annotation instanceof Annotations\SerializedName) {
$pMetadata->setSerializedName((string) $annotation->value);
} elseif ($annotation instanceof Annotations\SinceVersion) {
$pMetadata->setSinceVersion((string) $annotation->value);
} elseif ($annotation instanceof Annotations\UntilVersion) {
$pMetadata->setUntilVersion((string) $annotation->value);
}
}
$metadata->addPropertyMetadata($pMetadata);
}
return $metadata;
}