/** * {@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 getTemplateDataForModel($model) { $data = ['name' => Helper::get()->shortName($model), 'slug' => Helper::get()->slugify($model), 'properties' => []]; $reflectionClass = new \ReflectionClass($model); $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC); $reader = new AnnotationReader(); foreach ($properties as $property) { $name = $property->getName(); $type = null; $targetEntity = null; $mappedBySlug = null; $propertyDefinition = ['name' => $name]; if (($fieldAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Field')) !== null) { $type = $fieldAnnotation->type; } elseif (($referenceOneAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceOne')) !== null) { $name .= '.id'; $type = 'reference'; $targetEntity = Helper::get()->shortName($referenceOneAnnotation->targetDocument); } elseif (($referenceManyAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceMany')) !== null) { $type = 'referenced_list'; $targetEntity = Helper::get()->shortName($referenceManyAnnotation->targetDocument); $mappedBySlug = Helper::get()->slugify($referenceManyAnnotation->mappedBy, false); } elseif ($reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Id') === null) { continue; } $propertyDefinition['name'] = $name; $propertyDefinition['type'] = $type; if ($targetEntity) { $propertyDefinition[$type] = ['targetEntity' => $targetEntity, 'targetEntitySlug' => Helper::get()->slugify($targetEntity), 'mappedBySlug' => $mappedBySlug]; } $data['properties'][] = $propertyDefinition; } return $data; }
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 onSerializerPreDeserialize(PreDeserializeEvent $e) { $className = $e->getType(); $className = $className['name']; /** Handle ArrayCollection or array JMS type. */ if ($className == "ArrayCollection" || $className == "array") { $className = $e->getType(); $className = $className['params'][0]['name']; } $classMetadata = $e->getContext()->getMetadataFactory()->getMetadataForClass($className); /** @var PropertyMetadata $propertyMetadata */ foreach ($classMetadata->propertyMetadata as $propertyMetadata) { if ($propertyMetadata->reflection === null) { continue; } /** @var JoinColumn $joinColumnAnnotation */ $joinColumnAnnotation = $this->reader->getPropertyAnnotation($propertyMetadata->reflection, 'Doctrine\\ORM\\Mapping\\JoinColumn'); if ($joinColumnAnnotation !== null) { if (array_key_exists($joinColumnAnnotation->name, $e->getData())) { $idValue = $e->getData(); $idValue = $idValue[$joinColumnAnnotation->name]; if ($idValue !== null) { $e->setData($e->getData() + array($propertyMetadata->name => array('id' => $idValue))); } else { $e->setData($e->getData() + array($propertyMetadata->name => null)); } } } } }
/** * 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()]); } } }
public function setBriefProperty($object, $name, $value, $expectedClass = null) { $reflection = new \ReflectionClass($object); if (!$reflection->hasProperty($name)) { return false; } $property = $reflection->getProperty($name); $property->setAccessible(true); if ($value instanceof Resource) { $value = $value->getUri(); $annotation = $this->annotationReader->getPropertyAnnotation($property, 'Soil\\CommentsDigestBundle\\Annotation\\Entity'); if ($annotation) { $expectedClass = $annotation->value ?: true; var_dump($expectedClass); try { $entity = $this->resolver->getEntityForURI($value, $expectedClass); } catch (\Exception $e) { $entity = null; echo "Problem with discovering" . PHP_EOL; echo $e->getMessage() . PHP_EOL; var_dump($value, $expectedClass); echo PHP_EOL; //FIXME: Add logging } if ($entity) { $value = $entity; } } } elseif ($value instanceof Literal) { $value = $value->getValue(); } $property->setValue($object, $value); }
/** * buildMetaData * * build the columns and other metadata for this class */ protected function buildMetaData() { $columnArray = array(); $className = $this->getClassName($this->tableConfig); $refl = new \ReflectionClass($className); $properties = $refl->getProperties(); foreach ($properties as $property) { $column = $this->reader->getPropertyAnnotation($property, $this->columnNs); if (!empty($column)) { if (!isset($column->source)) { throw new InvalidArgumentException('DataTables requires a "source" attribute be provided for a column'); } if (!isset($column->name)) { throw new InvalidArgumentException('DataTables requires a "name" attribute be provided for a column'); } // check for default $default = $this->reader->getPropertyAnnotation($property, $this->defaultSortNs); if (!empty($default)) { $column->defaultSort = true; } // check for formatting $format = $this->reader->getPropertyAnnotation($property, $this->formatNs); if (!empty($format)) { if (!isset($format->dataFields)) { throw new InvalidArgumentException('DataTables requires a "dataFields" attribute be provided for a column formatter'); } $column->format = $format; } $this->columns[] = $column; $columnArray[$column->source] = $column->name; } } $this->table->setColumns($columnArray); $this->table->setMetaData(array('table' => $this->tableConfig, 'columns' => $this->columns)); }
/** * * @param \ReflectionClass $class * @param Object $c_ann */ public function addProperties(\ReflectionClass $class, $c_ann) { if ($this->isListener($c_ann)) { foreach ($class->getProperties() as $ref_prop) { $annotation = $this->reader->getPropertyAnnotation($ref_prop, 'DIPcom\\AnnEvents\\Mapping\\On'); if ($annotation) { $this->guideline->addListener($ref_prop, $annotation); } } } }
/** */ public function shouldReceiveAnnotation() { $reader = new AnnotationReader(); $refObj = new \ReflectionClass(Article::class); $titleProp = $refObj->getProperty('title'); $bodyProp = $refObj->getProperty('body'); $titleAnnotation = $reader->getPropertyAnnotation($titleProp, 'Vertigolabs\\DoctrineFullTextPostgres\\ORM\\Mapping\\TsVector'); $bodyAnnotation = $reader->getPropertyAnnotation($bodyProp, 'Vertigolabs\\DoctrineFullTextPostgres\\ORM\\Mapping\\TsVector'); $this->assertNotNull($titleAnnotation, 'TsVector annotation not found for title'); $this->assertNotNull($bodyAnnotation, 'TsVector annotation not found for body'); }
/** * {@inheritdoc} */ public function fillEntity(Utils\ArrayHash $values, Entities\IEntity $entity, $isNew = FALSE) { $classMetadata = $this->managerRegistry->getManagerForClass(get_class($entity))->getClassMetadata(get_class($entity)); foreach (array_merge($classMetadata->getFieldNames(), $classMetadata->getAssociationNames()) as $fieldName) { $propertyReflection = new Nette\Reflection\Property(get_class($entity), $fieldName); /** @var Doctrine\Mapping\Annotation\Crud $crud */ if ($crud = $this->annotationReader->getPropertyAnnotation($propertyReflection, self::EXTENSION_ANNOTATION)) { if ($isNew && $crud->isRequired() && !$values->offsetExists($fieldName)) { throw new Exceptions\InvalidStateException('Missing required key "' . $fieldName . '"'); } if (!$values->offsetExists($fieldName) || !$isNew && !$crud->isWritable() || $isNew && !$crud->isRequired()) { continue; } $value = $values->offsetGet($fieldName); if ($value instanceof Utils\ArrayHash || is_array($value)) { if (!$classMetadata->getFieldValue($entity, $fieldName) instanceof Entities\IEntity) { $propertyAnnotations = $this->annotationReader->getPropertyAnnotations($propertyReflection); $annotations = array_map(function ($annotation) { return get_class($annotation); }, $propertyAnnotations); if (in_array('Doctrine\\ORM\\Mapping\\OneToOne', $annotations, TRUE)) { $className = $this->annotationReader->getPropertyAnnotation($propertyReflection, 'Doctrine\\ORM\\Mapping\\OneToOne')->targetEntity; } elseif (in_array('Doctrine\\ORM\\Mapping\\ManyToOne', $annotations, TRUE)) { $className = $this->annotationReader->getPropertyAnnotation($propertyReflection, 'Doctrine\\ORM\\Mapping\\ManyToOne')->targetEntity; } else { $className = $propertyReflection->getAnnotation('var'); } // Check if class is callable if (class_exists($className)) { $classMetadata->setFieldValue($entity, $fieldName, new $className()); } else { $classMetadata->setFieldValue($entity, $fieldName, $value); } } // Check again if entity was created if (($fieldValue = $classMetadata->getFieldValue($entity, $fieldName)) && $fieldValue instanceof Entities\IEntity) { $classMetadata->setFieldValue($entity, $fieldName, $this->fillEntity(Utils\ArrayHash::from((array) $value), $fieldValue, $isNew)); } } else { if ($crud->validator !== NULL) { $value = $this->validateProperty($crud->validator, $value); } $classMetadata->setFieldValue($entity, $fieldName, $value); } } } return $entity; }
/** * (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; } } }
/** * Get all relationships in the entity * * @return Relationship[] */ public function getRelationships() { $r = []; $properties = $this->reflection_obj->getProperties(); foreach ($properties as $property) { /** @var OneToOne $oto */ $oto = $this->annotation_reader->getPropertyAnnotation($property, self::OTO_ANNOTATION); if ($oto) { $r[] = $this->createRelationship($property->getName(), RelationshipType::ONETOONE(), $oto); } /** @var OneToMany $otm */ $otm = $this->annotation_reader->getPropertyAnnotation($property, self::OTM_ANNOTATION); if ($otm) { $r[] = $this->createRelationship($property->getName(), RelationshipType::ONETOMANY(), $otm); } /** @var ManyToOne $mto */ $mto = $this->annotation_reader->getPropertyAnnotation($property, self::MTO_ANNOTATION); if ($mto) { $r[] = $this->createRelationship($property->getName(), RelationshipType::MANYTOONE(), $mto); } /** @var ManyToMany $mtm */ $mtm = $this->annotation_reader->getPropertyAnnotation($property, self::MTM_ANNOTATION); if ($mtm) { $r[] = $this->createRelationship($property->getName(), RelationshipType::MANYTOMANY(), $mtm); } } return $r; }
/** * {@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}")); }
/** * Get Column Type of a model. * * @param $entity string Class name of the entity * @param $property string * @return string */ public function getEntityColumnType($entity, $property) { $classRef = new \ReflectionClass($entity); $columnRef = null; $propertyRef = null; if ($classRef->hasProperty($property)) { $propertyRef = $classRef->getProperty($property); $columnRef = $this->annoReader->getPropertyAnnotation($propertyRef, 'Doctrine\\ORM\\Mapping\\Column'); } else { /** Can not find the property on the class. Check the all the Column annotation */ foreach ($classRef->getProperties() as $propertyRef) { $columnRef = $this->annoReader->getPropertyAnnotation($propertyRef, 'Doctrine\\ORM\\Mapping\\Column'); if ($columnRef->name == $property) { break; } else { $columnRef = null; } } } if ($columnRef === null) { $idRef = $this->annoReader->getPropertyAnnotation($propertyRef, 'Doctrine\\ORM\\Mapping\\Id'); if ($idRef !== null) { return "int"; } else { return "string"; } } else { return $this->getColumnType($columnRef->type); } }
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; } }
/** * reads the entity and returns a set of annotations * * @param string $entity * @param string $type * * @return Annotation[] */ private function getPropertiesByType($entity, $type) { $properties = $this->readClassProperties($entity); $fields = array(); foreach ($properties as $property) { $annotation = $this->reader->getPropertyAnnotation($property, $type); if (null === $annotation) { continue; } $property->setAccessible(true); $annotation->value = $property->getValue($entity); $annotation->name = $property->getName(); $fields[] = $annotation; } return $fields; }
public function readExtendedMetadata($meta, array &$config) { // load our available annotations require_once __DIR__ . '/../Annotations.php'; $reader = new AnnotationReader(); // set annotation namespace and alias //$reader->setAnnotationNamespaceAlias('Gedmo\Mapping\Mock\Extension\Encoder\Mapping\\', 'ext'); $class = $meta->getReflectionClass(); // check only property annotations foreach ($class->getProperties() as $property) { // skip inherited properties if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) { continue; } // now lets check if property has our annotation if ($encode = $reader->getPropertyAnnotation($property, 'Gedmo\\Mapping\\Mock\\Extension\\Encoder\\Mapping\\Encode')) { $field = $property->getName(); // check if field is mapped if (!$meta->hasField($field)) { throw new \Exception("Field is not mapped as object property"); } // allow encoding only strings if (!in_array($encode->type, array('sha1', 'md5'))) { throw new \Exception("Invalid encoding type supplied"); } // validate encoding type $mapping = $meta->getFieldMapping($field); if ($mapping['type'] != 'string') { throw new \Exception("Only strings can be encoded"); } // store the metadata $config['encode'][$field] = array('type' => $encode->type, 'secret' => $encode->secret); } } }
/** * ElasticSearch constructor. * * @param \Elasticsearch\Client $client * @param array $entityPaths */ public function __construct(\Elasticsearch\Client $client, array $entityPaths) { $this->_client = $client; AnnotationRegistry::registerFile(__DIR__ . '/elasticsearch/annotations/Entity.php'); AnnotationRegistry::registerFile(__DIR__ . '/elasticsearch/annotations/ElasticField.php'); AnnotationRegistry::registerFile(__DIR__ . '/elasticsearch/annotations/Id.php'); $reader = new AnnotationReader(); $mappings = []; foreach ($entityPaths as $entityPath) { $dir = new \DirectoryIterator($entityPath); foreach ($dir as $fileinfo) { if ($fileinfo->getExtension() === 'php') { $className = str_replace('.php', '', $fileinfo->getFilename()); $content = file_get_contents($fileinfo->getPath() . '/' . $fileinfo->getFilename()); preg_match('/namespace\\s([\\S]*)\\;/', $content, $namespace); $class = new \ReflectionClass($namespace[1] . '\\' . $className); $entity = $reader->getClassAnnotation($class, 'thewulf7\\friendloc\\components\\elasticsearch\\annotations\\Entity'); if ($entity === null) { continue; } $properties = []; $props = $class->getProperties(); foreach ($props as $prop) { $idprop = $reader->getPropertyAnnotation($prop, 'Doctrine\\ORM\\Mapping\\Id'); if ($idprop === null) { $annotation = $reader->getPropertyAnnotation($prop, 'thewulf7\\friendloc\\components\\elasticsearch\\annotations\\ElasticField'); if ($annotation) { $proper = ['type' => $annotation->type, 'include_in_all' => $annotation->includeInAll]; if ($annotation->type === 'geo_point') { $proper['lat_lon'] = true; } $properties[$prop->getName()] = $proper; } } } $mappings[$entity->index]['mappings'][$entity->type] = ['_all' => ['index_analyzer' => 'autocomplete'], 'properties' => $properties]; $mappings[$entity->index]['settings'] = ['number_of_shards' => $entity->number_of_shards, 'number_of_replicas' => $entity->number_of_replicas, 'autocomplete' => $entity->autocomplete]; $this->_entities[$className] = $entity; $this->_classes[$className] = $class; } } } foreach ($mappings as $index => $mapp) { $this->_mappings[] = ['index' => $index, 'body' => ['mappings' => $mapp['mappings'], 'settings' => $mapp['settings']]]; } }
/** * @return \Closure */ protected function createFindManyClosure() { return $this->findMany ?: function ($resourceRequest) { /** * @var \Hive\ResourceRequest $resourceRequest */ $settings = $resourceRequest->resource->settings; $request = $resourceRequest->request; $limit = intval($request->param($settings['params']['limit']) ?: $settings['maxLimit']); $offset = intval($request->param($settings['params']['offset']) ?: 0); $order = $request->param($settings['params']['order']) ?: 'DESC'; $sort = $request->param($settings['params']['sort']) ?: 'id'; $q = $request->param($settings['params']['query']); $limit = max(1, min($settings['maxLimit'], $limit)); $offset = max(0, $offset); $className = null; $mappedBy = null; if ($resourceRequest->property !== null) { $reflectionClass = new \ReflectionClass($resourceRequest->resource->class); $referenceManyAnnotation = $this->reader->getPropertyAnnotation($reflectionClass->getProperty($resourceRequest->property), 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceMany'); $className = $referenceManyAnnotation->targetDocument; $mappedBy = $referenceManyAnnotation->mappedBy; } else { $className = $resourceRequest->resource->class; } $repo = $this->dm->getRepository($className); $query = $repo->createQueryBuilder()->eagerCursor(true)->limit($limit)->skip($offset)->sort($sort, $order); if ($settings['fullText'] === true && !empty($q)) { $regex = new \MongoRegex('/.*' . preg_quote($q) . '.*/i'); $equals = null; $reflectionClass = new \ReflectionClass($className); $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC); foreach ($properties as $property) { $name = $property->getName(); if ($name == 'id') { $equals = $q; } elseif ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceOne') !== null) { $name .= '.id'; $equals = $q; } elseif (($fieldAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Field')) !== null) { if ($fieldAnnotation->type !== 'string') { $equals = $q; } else { $equals = $regex; } } else { continue; } $query = $query->addOr($query->expr()->field($name)->equals($equals)); } } if ($mappedBy !== null) { $query = $query->field($mappedBy . '.id')->equals($resourceRequest->request->owner_id); } $resourceRequest->response->headers()['X-Total-Count'] = $query->count()->getQuery()->execute(); return $query->find()->getQuery()->execute()->toArray(); }; }
/** * Read values from Vlabs\Media annotation * Store all readed values into metadata property * * @param string $class * @param \ReflectionProperty $property */ public function handle($class, $property) { $reader = new AnnotationReader(); $property = new \ReflectionProperty($class, $property); $media = $reader->getPropertyAnnotation($property, $this->annotationClass); $this->identifier = $media->getIdentifier(); $this->uploadDir = $media->getUploadDir(); $this->metadatas[$class][$property->getName()]['identifier'] = $this->identifier; $this->metadatas[$class][$property->getName()]['uploadDir'] = $this->uploadDir; }
/** * Checks if the specified class has a property annotated with Id * * @param string $className Name of the class to check against * @param string $methodName Name of the method to check against * @param string $methodDeclaringClassName Name of the class the method was originally declared in * @param mixed $pointcutQueryIdentifier Some identifier for this query - must at least differ from a previous identifier. Used for circular reference detection. * @return boolean TRUE if the class has *no* Id properties */ public function matches($className, $methodName, $methodDeclaringClassName, $pointcutQueryIdentifier) { $class = new \ReflectionClass($className); foreach ($class->getProperties() as $property) { if ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id') !== null) { return false; } } return true; }
/** * @param $object * @return array */ public function convert($object) : array { $reflectionObject = new \ReflectionObject($object); $owners = []; foreach ($reflectionObject->getProperties() as $property) { /** @var Owner $annotation */ $annotation = $this->reader->getPropertyAnnotation($property, $this->annotationClass); if (null !== $annotation) { $owners[] = $annotation->value; } } foreach ($reflectionObject->getMethods() as $method) { $annotation = $this->reader->getMethodAnnotation($method, $this->annotationClass); if (null !== $annotation) { $owners[] = $method->invoke($object); } } return $owners; }
/** * (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\\Sluggable\\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; } // sluggable property if ($sluggable = $reader->getPropertyAnnotation($property, self::ANNOTATION_SLUGGABLE)) { $field = $property->getName(); if (!$meta->hasField($field)) { throw MappingException::fieldMustBeMapped($field, $meta->name); } if (!$this->_isValidField($meta, $field)) { throw MappingException::notValidFieldType($field, $meta->name); } $config['fields'][] = $field; } // slug property if ($slug = $reader->getPropertyAnnotation($property, self::ANNOTATION_SLUG)) { $field = $property->getName(); if (!$meta->hasField($field)) { throw MappingException::slugFieldMustBeMapped($field, $meta->name); } if (!$this->_isValidField($meta, $field)) { throw MappingException::notValidFieldType($field, $meta->name); } if (isset($config['slug'])) { throw MappingException::slugFieldIsDuplicate($field, $meta->name); } $config['slug'] = $field; $config['style'] = $slug->style; $config['updatable'] = $slug->updatable; $config['unique'] = $slug->unique; $config['separator'] = $slug->separator; } } }
/** * (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\\Tree\\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; } // left if ($left = $reader->getPropertyAnnotation($property, self::ANNOTATION_LEFT)) { $field = $property->getName(); if (!$meta->hasField($field)) { throw MappingException::fieldMustBeMapped($field, $meta->name); } if (!$this->_isValidField($meta, $field)) { throw MappingException::notValidFieldType($field, $meta->name); } $config['left'] = $field; } // right if ($right = $reader->getPropertyAnnotation($property, self::ANNOTATION_RIGHT)) { $field = $property->getName(); if (!$meta->hasField($field)) { throw MappingException::fieldMustBeMapped($field, $meta->name); } if (!$this->_isValidField($meta, $field)) { throw MappingException::notValidFieldType($field, $meta->name); } $config['right'] = $field; } // ancestor/parent if ($parent = $reader->getPropertyAnnotation($property, self::ANNOTATION_PARENT)) { $field = $property->getName(); if (!$meta->isSingleValuedAssociation($field)) { throw MappingException::parentFieldNotMappedOrRelated($field, $meta->name); } $config['parent'] = $field; } // level if ($parent = $reader->getPropertyAnnotation($property, self::ANNOTATION_LEVEL)) { $field = $property->getName(); if (!$meta->hasField($field)) { throw MappingException::fieldMustBeMapped($field, $meta->name); } if (!$this->_isValidField($meta, $field)) { throw MappingException::notValidFieldType($field, $meta->name); } $config['level'] = $field; } } }
/** * Read values from Vlabs\Cdn annotation * Return default CDN if not set * * @param string $class * @param \ReflectionProperty $property */ public function handle(BaseFileInterface $file) { $reader = new AnnotationReader(); $property = new \ReflectionProperty($this->adapter->getClass($file), 'path'); $cdn = $reader->getPropertyAnnotation($property, $this->annotationClass); if ($cdn != null && array_key_exists($cdn->getBaseUrl(), $this->config)) { $this->baseUrl = $this->config[$cdn->getBaseUrl()]; } else { $this->baseUrl = isset($this->config['default']) ? $this->config['default'] : null; } }
private function isWatchFieldNullable(\ReflectionClass $class, TsVector $annotation) { foreach ($annotation->fields as $fieldName) { $property = $class->getProperty($fieldName); /** @var Column $propAnnot */ $propAnnot = $this->reader->getPropertyAnnotation($property, Column::class); if ($propAnnot->nullable === false) { return false; } } return true; }
/** * Get annotation of uploadeble field * * @param object|string $source An class name or entity * @param string $field An field name * * @return array */ public function getUploadebleFieldAnnotation($source, $field) { $source = $this->getClass($source); if (!$this->isUploadable($source)) { return null; } $metadata = $this->getClassMetadata($source); if (!$metadata->hasField($field)) { return null; } return $this->annotationReader->getPropertyAnnotation($metadata->getReflectionProperty($field), static::UPLOADEBLE_FILED); }
/** * @return array */ public function getChildEntities() { $entities = array(); foreach (ReflectionUtils::getProperties($this->reflectionClass) as $property) { $annotation = $this->reader->getPropertyAnnotation($property, EventSourcedMember::class); if (null !== $annotation) { $property->setAccessible(true); $child = $property->getValue($this->targetObject); if (is_array($child)) { $entities = array_merge($entities, $child); } else { if ($child instanceof \IteratorAggregate) { foreach ($child as $element) { $entities[] = $element; } } else { $entities[] = $child; } } } } return $entities; }
/** * Get the list of properites of this object. * * "[Semantical Error] The annotation "@Octopus\Annotation\Foo" in property * Models\Book::$title does not exist, or could not be auto-loaded." * * @param \Doctrine\Common\Annotations\AnnotationReader $reader * @return array */ private function getFieldNames(AnnotationReader $reader) { $fieldNames = array(); $reflectionObject = new \ReflectionObject($this); /** * @var $property \ReflectionProperty */ foreach ($reflectionObject->getProperties() as $property) { $annotation = $reader->getPropertyAnnotation($property, 'Octopus\\Annotation\\PropertyName'); if ($annotation) { $fieldNames[] = $property->getName(); } } return $fieldNames; }
private function readParameterMapping($settings) { $mapping = []; $reader = new AnnotationReader(); $reflClass = new \ReflectionClass($settings); $properties = $reflClass->getProperties(); foreach ($properties as $property) { /** @var Parameter $parameterPath */ $parameterPath = $reader->getPropertyAnnotation($property, Parameter::class); if ($parameterPath != null) { $mapping[$parameterPath->name] = ['path' => $property->getName(), 'type' => $parameterPath->type]; } } return $mapping; }