本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::getReflectionClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getReflectionClass方法的具体用法?PHP ClassMetadata::getReflectionClass怎么用?PHP ClassMetadata::getReflectionClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::getReflectionClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadClassMetadata
/**
* Event triggered during metadata loading
*
* @param LoadClassMetadataEventArgs $eventArgs
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
$this->classMetadata = $eventArgs->getClassMetadata();
$reflectionClass = $this->classMetadata->getReflectionClass();
if (null === $reflectionClass) {
return;
}
if ($this->hasMethod($reflectionClass, 'updateTimestamps')) {
$this->addLifecycleCallbacks();
$this->mapFields();
}
}
示例2: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
if ($timestampable = $this->reader->getPropertyAnnotation($property, self::TIMESTAMPABLE)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'date', 'datetime' or 'time' in class - {$meta->name}");
}
if (!in_array($timestampable->on, array('update', 'create', 'change'))) {
throw new InvalidMappingException("Field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$meta->name}");
}
if ($timestampable->on == 'change') {
if (!isset($timestampable->field) || !isset($timestampable->value)) {
throw new InvalidMappingException("Missing parameters on property - {$field}, field and value must be set on [change] trigger in class - {$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;
}
}
}
示例3: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// position
if ($position = $this->reader->getPropertyAnnotation($property, self::POSITION)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find 'position' - [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Sortable position field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
}
$config['position'] = $field;
}
// group
if ($group = $this->reader->getPropertyAnnotation($property, self::GROUP)) {
$field = $property->getName();
if (!$meta->hasField($field) && !$meta->hasAssociation($field)) {
throw new InvalidMappingException("Unable to find 'group' - [{$field}] as mapped property in entity - {$meta->name}");
}
if (!isset($config['groups'])) {
$config['groups'] = array();
}
$config['groups'][] = $field;
}
}
}
示例4: isResource
/**
* @param ClassMetadata $metadata
*
* @return bool
*/
protected function isResource(ClassMetadata $metadata)
{
if (!($reflClass = $metadata->getReflectionClass())) {
return false;
}
return $reflClass->implementsInterface(PersistableInterface::class);
}
示例5: testInitializedProxyUnserialization
public function testInitializedProxyUnserialization()
{
// persister will retrieve the lazy object itself, so that we don't have to re-define all field values
$this->proxyLoader->expects($this->once())->method('load')->will($this->returnValue($this->lazyObject));
$this->lazyObject->__setInitializer($this->getSuggestedInitializerImplementation());
$this->lazyObject->__load();
$serialized = serialize($this->lazyObject);
$reflClass = $this->lazyLoadableObjectMetadata->getReflectionClass();
/* @var $unserialized LazyLoadableObject|Proxy */
$unserialized = unserialize($serialized);
$this->assertTrue($unserialized->__isInitialized(), 'serialization didn\'t cause intialization');
// Checking transient fields
$this->assertSame('publicTransientFieldValue', $unserialized->publicTransientField, 'transient fields are kept');
$protectedTransientField = $reflClass->getProperty('protectedTransientField');
$protectedTransientField->setAccessible(true);
$this->assertSame('protectedTransientFieldValue', $protectedTransientField->getValue($unserialized), 'transient fields are kept');
// Checking persistent fields
$this->assertSame('publicPersistentFieldValue', $unserialized->publicPersistentField, 'persistent fields are kept');
$protectedPersistentField = $reflClass->getProperty('protectedPersistentField');
$protectedPersistentField->setAccessible(true);
$this->assertSame('protectedPersistentFieldValue', $protectedPersistentField->getValue($unserialized), 'persistent fields are kept');
// Checking identifiers
$this->assertSame('publicIdentifierFieldValue', $unserialized->publicIdentifierField, 'identifiers are kept');
$protectedIdentifierField = $reflClass->getProperty('protectedIdentifierField');
$protectedIdentifierField->setAccessible(true);
$this->assertSame('protectedIdentifierFieldValue', $protectedIdentifierField->getValue($unserialized), 'identifiers are kept');
// Checking associations
$this->assertSame('publicAssociationValue', $unserialized->publicAssociation, 'associations are kept');
$protectedAssociationField = $reflClass->getProperty('protectedAssociation');
$protectedAssociationField->setAccessible(true);
$this->assertSame('protectedAssociationValue', $protectedAssociationField->getValue($unserialized), 'associations are kept');
}
示例6: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
$config['fields'] = array();
$config['fields_delete'] = array();
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
$field = null;
if ($file = $this->reader->getPropertyAnnotation($property, self::FILE)) {
$field['name'] = $property->getName();
$field['dir'] = CMSCore::init()->getUploadsDir() . '/' . $file->dir;
if (!$meta->hasField($field['name'])) {
throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
}
}
// if ($fileDelete = $this->reader->getPropertyAnnotation($property, self::FILE_DELETE)) {
//
// $config['fields_delete'][] = $property->getName();
//
// }
if ($field) {
$config['fields'][] = $field;
}
}
}
示例7: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// class annotations
if ($annot = $this->reader->getClassAnnotation($class, self::LOGGABLE)) {
$config['loggable'] = true;
if ($annot->logEntryClass) {
if (!class_exists($annot->logEntryClass)) {
throw new InvalidMappingException("LogEntry class: {$annot->logEntryClass} does not exist.");
}
$config['logEntryClass'] = $annot->logEntryClass;
}
}
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// versioned property
if ($versioned = $this->reader->getPropertyAnnotation($property, self::VERSIONED)) {
$field = $property->getName();
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
}
// fields cannot be overrided and throws mapping exception
$config['versioned'][] = $field;
}
}
}
示例8: 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()]);
}
}
}
示例9: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadata $metadata
* @throws \Doctrine\ORM\ODMAdapter\Exception\MappingException
* @return void
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
/** @var $class \Doctrine\ORM\ODMAdapter\Mapping\ClassMetadata */
$reflClass = $metadata->getReflectionClass();
$documentAnnots = array();
foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
foreach ($this->entityAnnotationClasses as $annotClass => $i) {
if ($annot instanceof $annotClass) {
$documentAnnots[$i] = $annot;
}
}
}
if (!$documentAnnots) {
throw MappingException::classIsNotAValidDocument($className);
}
$metadata->className = $className;
foreach ($reflClass->getProperties() as $property) {
if ($metadata->className !== $property->getDeclaringClass()->getName()) {
continue;
}
$mapping = array();
$mapping['fieldName'] = $property->getName();
foreach ($this->reader->getPropertyAnnotations($property) as $propertyAnnotation) {
if ($propertyAnnotation instanceof Adapter\ReferencePhpcr) {
$mapping['type'] = Reference::PHPCR;
$this->extractReferencedObjects($propertyAnnotation, $metadata, $className, $mapping);
}
if ($propertyAnnotation instanceof Adapter\ReferenceDbalOrm) {
$mapping['type'] = Reference::DBAL_ORM;
$this->extractReferencedObjects($propertyAnnotation, $metadata, $className, $mapping);
}
}
}
}
示例10: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
/** @var $class ClassMetadataInfo */
$reflClass = $metadata->getReflectionClass();
if ($entityAnnot = $this->reader->getClassAnnotation($reflClass, 'Pasinter\\OHM\\Mapping\\Annotations\\Entity')) {
$metadata->database = $entityAnnot->database;
}
// Evaluate annotations on properties/fields
foreach ($reflClass->getProperties() as $property) {
if ($fieldAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\Field')) {
$mapping = $this->fieldToArray($property->getName(), $fieldAnnot);
if ($this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\Id')) {
$mapping['id'] = true;
}
$metadata->mapField($mapping);
} elseif ($referenceOneAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\ReferenceOne')) {
$mapping = $this->referenceOneToArray($property->getName(), $referenceOneAnnot);
$metadata->mapOneReference($mapping);
} elseif ($referenceManyAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\ReferenceMany')) {
$mapping = $this->referenceManyToArray($property->getName(), $referenceManyAnnot);
$metadata->mapManyReference($mapping);
} elseif ($embedOneAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\EmbedOne')) {
$mapping = $this->embedOneToArray($property->getName(), $embedOneAnnot);
$metadata->mapOneEmbed($mapping);
} elseif ($embedManyAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\EmbedMany')) {
$mapping = $this->embedManyToArray($property->getName(), $embedManyAnnot);
$metadata->mapManyEmbed($mapping);
}
}
}
示例11: readExtendedMetadata
public function readExtendedMetadata(ClassMetadata $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);
}
}
}
示例12: hydrate
/**
* Hydrate $object with the provided $data.
*
* @param array $data
* @param object $object
* @throws \Exception
* @return object
*/
public function hydrate(array $data, $object)
{
$this->metadata = $this->objectManager->getClassMetadata(get_class($object));
$object = $this->tryConvertArrayToObject($data, $object);
foreach ($data as $field => &$value) {
$value = $this->hydrateValue($field, $value);
if ($value === null) {
continue;
}
// @todo DateTime (and other types) conversion should be handled by doctrine itself in future
if (in_array($this->metadata->getTypeOfField($field), array('datetime', 'time', 'date'))) {
if (is_int($value)) {
$dt = new DateTime();
$dt->setTimestamp($value);
$value = $dt;
} elseif (is_string($value)) {
$value = new DateTime($value);
}
}
if ($this->metadata->hasAssociation($field)) {
$target = $this->metadata->getAssociationTargetClass($field);
if ($this->metadata->isSingleValuedAssociation($field)) {
$value = $this->toOne($value, $target);
} elseif ($this->metadata->isCollectionValuedAssociation($field)) {
$value = $this->toMany($value, $target);
// Automatically merge collections using helper utility
$propertyRefl = $this->metadata->getReflectionClass()->getProperty($field);
$propertyRefl->setAccessible(true);
$previousValue = $propertyRefl->getValue($object);
$value = CollectionUtils::intersectUnion($previousValue, $value);
}
}
}
return $this->hydrator->hydrate($data, $object);
}
示例13: appendConfigurationFromMetadata
protected function appendConfigurationFromMetadata(ClassMetadata $metadata, &$configuration)
{
$serializationFilePath = $this->resolvePath($metadata->getReflectionClass());
if ($this->filesystem->exists($serializationFilePath)) {
$content = file_get_contents($serializationFilePath);
$configuration = array_replace_recursive($configuration, $this->parseContent($content));
}
}
示例14: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// slug property
if ($slug = $this->reader->getPropertyAnnotation($property, self::SLUG)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find slug [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
}
// process slug handlers
$handlers = array();
if (is_array($slug->handlers) && $slug->handlers) {
foreach ($slug->handlers as $handler) {
if (!$handler instanceof SlugHandler) {
throw new InvalidMappingException("SlugHandler: {$handler} should be instance of SlugHandler annotation in entity - {$meta->name}");
}
if (!strlen($handler->class)) {
throw new InvalidMappingException("SlugHandler class: {$handler->class} should be a valid class name in entity - {$meta->name}");
}
$class = $handler->class;
$handlers[$class] = array();
foreach ((array) $handler->options as $option) {
if (!$option instanceof SlugHandlerOption) {
throw new InvalidMappingException("SlugHandlerOption: {$option} should be instance of SlugHandlerOption annotation in entity - {$meta->name}");
}
if (!strlen($option->name)) {
throw new InvalidMappingException("SlugHandlerOption name: {$option->name} should be valid name in entity - {$meta->name}");
}
$handlers[$class][$option->name] = $option->value;
}
$class::validate($handlers[$class], $meta);
}
}
// process slug fields
if (empty($slug->fields) || !is_array($slug->fields)) {
throw new InvalidMappingException("Slug must contain at least one field for slug generation in class - {$meta->name}");
}
foreach ($slug->fields as $slugField) {
if (!$meta->hasField($slugField)) {
throw new InvalidMappingException("Unable to find slug [{$slugField}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $slugField)) {
throw new InvalidMappingException("Cannot use field - [{$slugField}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
}
}
// set all options
$config['slugs'][$field] = array('fields' => $slug->fields, 'slug' => $field, 'style' => $slug->style, 'updatable' => $slug->updatable, 'unique' => $slug->unique, 'separator' => $slug->separator, 'handlers' => $handlers);
}
}
}
示例15: mapTranslation
/**
* {@inheritDoc}
*/
public function mapTranslation(ClassMetadata $meta, $translatableClassName)
{
$rc = $meta->getReflectionClass();
if (!$rc->hasProperty('object') || $meta->hasAssociation('object') || !$rc->isSubclassOf($this->personalTranslation)) {
return;
}
$namingStrategy = $this->getObjectManager()->getConfiguration()->getNamingStrategy();
$meta->mapManyToOne(['targetEntity' => $translatableClassName, 'fieldName' => 'object', 'inversedBy' => 'translations', 'isOwningSide' => true, 'joinColumns' => [['name' => $namingStrategy->joinColumnName('object'), 'referencedColumnName' => $namingStrategy->referenceColumnName(), 'onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']]]);
}