本文整理汇总了PHP中Doctrine\Common\Annotations\Reader::getPropertyAnnotations方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::getPropertyAnnotations方法的具体用法?PHP Reader::getPropertyAnnotations怎么用?PHP Reader::getPropertyAnnotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Annotations\Reader
的用法示例。
在下文中一共展示了Reader::getPropertyAnnotations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadMetadata
/**
* {@inheritDoc}
*/
public function loadMetadata($class)
{
// Try get object annotation from class
$objectAnnotation = null;
$classAnnotations = Reflection::loadClassAnnotations($this->reader, $class, true);
foreach ($classAnnotations as $classAnnotation) {
if ($classAnnotation instanceof ObjectAnnotation) {
if ($objectAnnotation) {
throw new \RuntimeException(sprintf('Many @Transformer\\Object annotation in class "%s".', $class));
}
$objectAnnotation = $classAnnotation;
}
}
if (!$objectAnnotation) {
throw new TransformAnnotationNotFoundException(sprintf('Not found @Object annotations in class "%s".', $class));
}
// Try get properties annotations
$properties = [];
$classProperties = Reflection::getClassProperties($class, true);
foreach ($classProperties as $classProperty) {
$propertyAnnotations = $this->reader->getPropertyAnnotations($classProperty);
foreach ($propertyAnnotations as $propertyAnnotation) {
if ($propertyAnnotation instanceof PropertyAnnotation) {
$property = new PropertyMetadata($propertyAnnotation->propertyName ?: $classProperty->getName(), $propertyAnnotation->groups, $propertyAnnotation->shouldTransform, $propertyAnnotation->expressionValue);
$properties[$classProperty->getName()] = $property;
}
}
}
return new ObjectMetadata($objectAnnotation->transformedClass, $properties);
}
示例2: loadMetadataForClass
/**
* Load metadata class
*
* @param \ReflectionClass $class
* @return ClassMetadata
*/
public function loadMetadataForClass(\ReflectionClass $class)
{
$classMetadata = new ClassMetadata($class->name);
$classMetadata->fileResources[] = $class->getFileName();
foreach ($this->reader->getClassAnnotations($class) as $annotation) {
if ($annotation instanceof NamespaceNode) {
$classMetadata->addGraphNamespace($annotation);
}
if ($annotation instanceof GraphNode) {
$classMetadata->addGraphMetadata($annotation, new MetadataValue($annotation->value));
}
}
foreach ($class->getProperties() as $property) {
foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
if ($annotation instanceof GraphNode) {
$classMetadata->addGraphMetadata($annotation, new PropertyMetadata($class->name, $property->name));
}
}
}
foreach ($class->getMethods() as $method) {
foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
if ($annotation instanceof GraphNode) {
$classMetadata->addGraphMetadata($annotation, new MethodMetadata($class->name, $method->name));
}
}
}
return $classMetadata;
}
示例3: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass(\ReflectionClass $class)
{
$annotations = $this->reader->getClassAnnotations($class);
if (0 === count($annotations)) {
return null;
}
$classMetadata = new ClassMetadata($class->getName());
$classMetadata->fileResources[] = $class->getFileName();
foreach ($annotations as $annotation) {
if ($annotation instanceof Annotation\Resource) {
// auto transform type from class name
if (!$annotation->type) {
$annotation->type = String::dasherize($class->getShortName());
}
$classMetadata->setResource(new Resource($annotation->type, $annotation->showLinkSelf));
}
}
$classProperties = $class->getProperties();
foreach ($classProperties as $property) {
$annotations = $this->reader->getPropertyAnnotations($property);
foreach ($annotations as $annotation) {
if ($annotation instanceof Annotation\Id) {
$classMetadata->setIdField($property->getName());
} else {
if ($annotation instanceof Annotation\Relationship) {
$classMetadata->addRelationship(new Relationship($property->getName(), $annotation->includeByDefault, $annotation->showLinkSelf, $annotation->showLinkRelated));
}
}
}
}
return $classMetadata;
}
示例4: loadClassMetadata
/**
* {@inheritdoc}
*/
public function loadClassMetadata(ClassMetadata $metadata)
{
$reflClass = $metadata->getReflectionClass();
$className = $reflClass->name;
$loaded = false;
foreach ($reflClass->getProperties() as $property) {
if ($property->getDeclaringClass()->name == $className) {
foreach ($this->reader->getPropertyAnnotations($property) as $groups) {
if ($groups instanceof Groups) {
foreach ($groups->getGroups() as $group) {
$metadata->addAttributeGroup($property->name, $group);
}
}
$loaded = true;
}
}
}
foreach ($reflClass->getMethods() as $method) {
if ($method->getDeclaringClass()->name == $className) {
foreach ($this->reader->getMethodAnnotations($method) as $groups) {
if ($groups instanceof Groups) {
if (preg_match('/^(get|is)(.+)$/i', $method->name, $matches)) {
foreach ($groups->getGroups() as $group) {
$metadata->addAttributeGroup(lcfirst($matches[2]), $group);
}
} else {
throw new \BadMethodCallException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get" or "is".', $className, $method->name));
}
}
$loaded = true;
}
}
}
return $loaded;
}
示例5: loadClassMetadata
/**
* {@inheritdoc}
*/
public function loadClassMetadata(ClassMetadataInterface $classMetadata)
{
$reflectionClass = $classMetadata->getReflectionClass();
$className = $reflectionClass->name;
$loaded = false;
$attributesMetadata = $classMetadata->getAttributesMetadata();
foreach ($reflectionClass->getProperties() as $property) {
if (!isset($attributesMetadata[$property->name])) {
$attributesMetadata[$property->name] = new AttributeMetadata($property->name);
$classMetadata->addAttributeMetadata($attributesMetadata[$property->name]);
}
if ($property->getDeclaringClass()->name === $className) {
foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
if ($annotation instanceof Groups) {
foreach ($annotation->getGroups() as $group) {
$attributesMetadata[$property->name]->addGroup($group);
}
} elseif ($annotation instanceof MaxDepth) {
$attributesMetadata[$property->name]->setMaxDepth($annotation->getMaxDepth());
}
$loaded = true;
}
}
}
foreach ($reflectionClass->getMethods() as $method) {
if ($method->getDeclaringClass()->name !== $className) {
continue;
}
$accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches);
if ($accessorOrMutator) {
$attributeName = lcfirst($matches[2]);
if (isset($attributesMetadata[$attributeName])) {
$attributeMetadata = $attributesMetadata[$attributeName];
} else {
$attributesMetadata[$attributeName] = $attributeMetadata = new AttributeMetadata($attributeName);
$classMetadata->addAttributeMetadata($attributeMetadata);
}
}
foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
if ($annotation instanceof Groups) {
if (!$accessorOrMutator) {
throw new MappingException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
}
foreach ($annotation->getGroups() as $group) {
$attributeMetadata->addGroup($group);
}
} elseif ($annotation instanceof MaxDepth) {
if (!$accessorOrMutator) {
throw new MappingException(sprintf('MaxDepth on "%s::%s" cannot be added. MaxDepth can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
}
$attributeMetadata->setMaxDepth($annotation->getMaxDepth());
}
$loaded = true;
}
}
return $loaded;
}
示例6: create
public function create($class, \ReflectionProperty $reflectionProperty)
{
$annotations = $this->reader->getPropertyAnnotations($reflectionProperty);
foreach ($annotations as $annotation) {
if ($annotation instanceof GraphId) {
return new IdAnnotationMetadata();
}
}
}
示例7: readPropertyAnnotations
/**
* @param \ReflectionClass $reflectionClass
* @return Annotation[]
* @throws AnnotationReaderException
*/
private function readPropertyAnnotations(\ReflectionClass $reflectionClass) : array
{
return array_reduce($reflectionClass->getProperties(), function (array $accumulator, \ReflectionProperty $reflectionProperty) {
/* @var $annotations \Doctrine\Common\Annotations\Annotation[] */
$annotations = array_filter($this->reader->getPropertyAnnotations($reflectionProperty), function ($annotation) : bool {
return $annotation instanceof Annotation;
});
if (empty($annotations)) {
return $accumulator;
}
return array_merge($accumulator, $this->processPropertyAnnotations($annotations, $reflectionProperty));
}, []);
}
示例8: getPropertyMapping
/**
* @param \ReflectionProperty $property
*
* @return array
*/
private function getPropertyMapping(ReflectionProperty $property)
{
$metadata = [];
foreach ($this->reader->getPropertyAnnotations($property) as $value) {
if (!$value instanceof RiakAnnotation) {
continue;
}
$class = get_class($value);
$name = $property->getName();
$key = lcfirst(substr($class, strrpos($class, '\\') + 1));
$metadata[$key] = $name;
}
return $metadata;
}
示例9: readProperty
/**
* Reads annotations for a selected property in the class
*
* @param ReflectionProperty $property
* @param ClassMetadataInterface $metadata
*/
private function readProperty(ReflectionProperty $property, ClassMetadataInterface $metadata)
{
// Skip if this property is not from this class
if ($property->getDeclaringClass()->getName() != $metadata->getClassName()) {
return;
}
//Iterate over all annotations
foreach ($this->reader->getPropertyAnnotations($property) as $rule) {
//Skip is its not a rule
if (!$rule instanceof Rules\Rule) {
continue;
}
//Add Rule
$metadata->addPropertyRule($property->getName(), $rule);
}
}
示例10: loadMetadataForClass
/**
* {@inheritDoc}
*/
public function loadMetadataForClass($className, ResourceMetadata $resourceMetadata)
{
// get all class annotations
$reflClass = new \ReflectionClass($className);
$classAnnotations = $this->reader->getClassAnnotations($reflClass);
$classAnnotations = $this->indexAnnotationsByType($classAnnotations);
$resourceAnnotation = $this->getAnnotation($classAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\Resource');
if ($resourceAnnotation !== false) {
if (!empty($resourceAnnotation->name)) {
$resourceMetadata->setName($resourceAnnotation->name);
} else {
$resourceName = Inflector::tableize(substr($className, strrpos($className, '\\') + 1));
$resourceMetadata->setName($resourceName);
}
}
$handlerAnnotation = $this->getAnnotation($classAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\Handler');
if ($handlerAnnotation !== false) {
if (!empty($handlerAnnotation->service)) {
$resourceMetadata->setService($handlerAnnotation->service);
}
}
// properties
$subResources = array();
foreach ($reflClass->getProperties() as $reflProp) {
$propAnnotations = $this->reader->getPropertyAnnotations($reflProp);
$propAnnotations = $this->indexAnnotationsByType($propAnnotations);
$subResourceAnnotation = $this->getAnnotation($propAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\SubResource');
if ($subResourceAnnotation !== false) {
$subResources[$subResourceAnnotation->name] = array('fieldName' => $reflProp->name, 'service' => $subResourceAnnotation->service);
}
}
$resourceMetadata->setSubResources($subResources);
}
示例11: getConverterAnnotation
/**
* Get converter annotation
*
* @param \ReflectionProperty $property
*
* @return Money
*
* @throws MoneyAnnotationNotFoundException
*/
private function getConverterAnnotation(\ReflectionProperty $property)
{
$annotations = $this->reader->getPropertyAnnotations($property);
$moneyAnnotation = null;
foreach ($annotations as $annotation) {
if ($annotation instanceof Money) {
if ($moneyAnnotation) {
throw new \RuntimeException(sprintf('Many Money annotation in property %s->%s', $property->getDeclaringClass()->getName(), $property->getName()));
}
$moneyAnnotation = $annotation;
}
}
if ($moneyAnnotation) {
return $moneyAnnotation;
}
throw new MoneyAnnotationNotFoundException(sprintf('Not found DateTime annotation in property %s->%s', $property->getDeclaringClass()->getName(), $property->getName()));
}
示例12: getPropertyAnnotations
/**
* Get annotations for property
*
* @param \ReflectionProperty $property
* @return array
*/
public function getPropertyAnnotations(\ReflectionProperty $property)
{
$annotations = array();
foreach ($this->delegate->getPropertyAnnotations($property) as $annot) {
$annotations[get_class($annot)] = $annot;
}
return $annotations;
}
示例13: loadClassMetadata
/**
* {@inheritdoc}
*/
public function loadClassMetadata(ClassMetadata $metadata)
{
$reflClass = $metadata->getReflectionClass();
$className = $reflClass->name;
$success = false;
foreach ($this->reader->getClassAnnotations($reflClass) as $constraint) {
if ($constraint instanceof GroupSequence) {
$metadata->setGroupSequence($constraint->groups);
} elseif ($constraint instanceof GroupSequenceProvider) {
$metadata->setGroupSequenceProvider(true);
} elseif ($constraint instanceof Constraint) {
$metadata->addConstraint($constraint);
}
$success = true;
}
foreach ($reflClass->getProperties() as $property) {
if ($property->getDeclaringClass()->name == $className) {
foreach ($this->reader->getPropertyAnnotations($property) as $constraint) {
if ($constraint instanceof Constraint) {
$metadata->addPropertyConstraint($property->name, $constraint);
}
$success = true;
}
}
}
foreach ($reflClass->getMethods() as $method) {
if ($method->getDeclaringClass()->name == $className) {
foreach ($this->reader->getMethodAnnotations($method) as $constraint) {
if ($constraint instanceof Callback) {
$constraint->callback = $method->getName();
$constraint->methods = null;
$metadata->addConstraint($constraint);
} elseif ($constraint instanceof Constraint) {
if (preg_match('/^(get|is|has)(.+)$/i', $method->name, $matches)) {
$metadata->addGetterConstraint(lcfirst($matches[2]), $constraint);
} else {
throw new MappingException(sprintf('The constraint on "%s::%s" cannot be added. Constraints can only be added on methods beginning with "get", "is" or "has".', $className, $method->name));
}
}
$success = true;
}
}
}
return $success;
}
示例14: parseSingleClassFile
private function parseSingleClassFile($className)
{
//annotation on class
$reflectionClass = new \ReflectionClass($className);
$classAnnotations = $this->annotationReader->getClassAnnotations($reflectionClass);
if (!$classAnnotations) {
return;
}
foreach ($classAnnotations as $classAnnotation) {
//name not set => bean name className?
if (!isset($classAnnotation->name) or $classAnnotation->name == '') {
$beanClassName = lcfirst(join('', array_slice(explode('\\', $className), -1)));
$classAnnotation->name = $beanClassName;
}
$bean = array('name' => $classAnnotation->name, 'class' => $className, 'scope' => $classAnnotation->scope, 'lazyInit' => (string) $classAnnotation->lazyInit);
//annotation on method
$methods = $reflectionClass->getMethods();
foreach ($methods as $method) {
if ($method->name == self::CONSTRUCT_METHOD) {
//annotaiton on construct
$bean = $this->analyzeConstruct($className, $method, $bean);
} else {
$reflectionMethod = new \ReflectionMethod($className, $method->name);
$methodAnnotations = $this->annotationReader->getMethodAnnotations($reflectionMethod);
if ($methodAnnotations) {
foreach ($methodAnnotations as $pathToClassFile) {
if (isset($method->name)) {
$bean[get_class($pathToClassFile)] = $method->name;
}
}
}
}
}
//annotation on properties
$properties = $reflectionClass->getProperties();
$allProperties = array();
$temp = array();
foreach ($properties as $property) {
$reflectionProperty = new \ReflectionProperty($className, $property->name);
$propertyAnnotations = $this->annotationReader->getPropertyAnnotations($reflectionProperty);
if ($propertyAnnotations) {
foreach ($propertyAnnotations as $pathToClassFile) {
$allProperties[$property->name] = array(get_class($pathToClassFile) => $pathToClassFile->name);
if ($pathToClassFile->ref) {
$temp[] = array('name' => $property->name, 'ref' => $pathToClassFile->ref);
} else {
$temp[] = array('name' => $property->name, 'value' => $this->replaceVariable($pathToClassFile->value), 'type' => $pathToClassFile->type);
}
}
}
if ($temp) {
$bean['properties'] = $temp;
}
}
$this->context[$classAnnotation->name] = $bean;
}
}
示例15: getClassMetadata
/**
* Return the class metadata instance
*
* @param string $entityName
*
* @return ClassMetaDataCollection
*/
public function getClassMetadata($entityName)
{
$r = new ReflectionClass($entityName);
$instanceMetadataCollection = new ClassMetaDataCollection();
$instanceMetadataCollection->name = $entityName;
$classAnnotations = $this->reader->getClassAnnotations($r);
foreach ($classAnnotations as $classAnnotation) {
if ($classAnnotation instanceof RepositoryAttribute) {
$instanceMetadataCollection->setRepository($classAnnotation->getValue());
}
if ($classAnnotation instanceof ObjectClass) {
$instanceMetadataCollection->setObjectClass($classAnnotation->getValue());
}
if ($classAnnotation instanceof SearchDn) {
$instanceMetadataCollection->setSearchDn($classAnnotation->getValue());
}
if ($classAnnotation instanceof Dn) {
$instanceMetadataCollection->setDn($classAnnotation->getValue());
}
}
foreach ($r->getProperties() as $publicAttr) {
$annotations = $this->reader->getPropertyAnnotations($publicAttr);
foreach ($annotations as $annotation) {
if ($annotation instanceof Attribute) {
$varname = $publicAttr->getName();
$attribute = $annotation->getName();
$instanceMetadataCollection->addMeta($varname, $attribute);
}
if ($annotation instanceof DnLinkArray) {
$varname = $publicAttr->getName();
$instanceMetadataCollection->addArrayOfLink($varname, $annotation->getValue());
}
if ($annotation instanceof Sequence) {
$varname = $publicAttr->getName();
$instanceMetadataCollection->addSequence($varname, $annotation->getValue());
}
if ($annotation instanceof DnPregMatch) {
$varname = $publicAttr->getName();
$instanceMetadataCollection->addRegex($varname, $annotation->getValue());
}
if ($annotation instanceof ParentDn) {
$varname = $publicAttr->getName();
$instanceMetadataCollection->addParentLink($varname, $annotation->getValue());
}
if ($annotation instanceof ArrayField) {
$instanceMetadataCollection->addArrayField($varname);
}
if ($annotation instanceof Must) {
$instanceMetadataCollection->addMust($varname);
}
if ($annotation instanceof Operational) {
$instanceMetadataCollection->addOperational($varname);
}
}
}
return $instanceMetadataCollection;
}