public function loadClassMetadata(ClassMetadataInterface $classMetadata) { /** @var $classMetadata ClassMetadata */ $this->delegate->loadClassMetadata($classMetadata); // Abort if the given class is not a mapped entity if (!($doctrineMetadata = $this->tryLoadingDoctrineMetadata($classMetadata->getName()))) { return true; } $this->setDiscriminator($doctrineMetadata, $classMetadata); // We base our scan on the internal driver's property list so that we // respect any internal white/blacklisting like in the AnnotationDriver foreach ($classMetadata->getAttributesMetadata() as $key => $propertyMetadata) { if (!$propertyMetadata instanceof PropertyMetadata) { continue; } // If the inner driver provides a type, don't guess anymore. if (null !== $propertyMetadata->type) { continue; } if ($this->hideProperty($doctrineMetadata, $propertyMetadata)) { $classMetadata->addAttributeMetadata(new NullMetadata($key)); } $this->setPropertyType($doctrineMetadata, $propertyMetadata); } return true; }
/** * {@inheritdoc} */ public function getMetadataFor($value) { $class = $this->getClass($value); if (empty($class)) { throw InvalidArgumentException::create(InvalidArgumentException::VALUE_IS_NOT_AN_OBJECT, $value); } if (isset($this->loadedClasses[$class])) { return $this->loadedClasses[$class]; } if (null !== $this->cache && ($this->loadedClasses[$class] = $this->cache->fetch($class))) { return $this->loadedClasses[$class]; } if (!class_exists($class) && !interface_exists($class)) { throw InvalidArgumentException::create(InvalidArgumentException::CLASS_DOES_NOT_EXIST, $class); } $reflectionClass = new \ReflectionClass($class); $classMetadata = $this->createMetadata($reflectionClass); if (!$this->loader->loadClassMetadata($classMetadata)) { return $classMetadata; } $this->mergeSuperclasses($classMetadata); $this->validate($classMetadata); if ($this->eventDispatcher) { $this->eventDispatcher->dispatch(ClassMetadataLoadedEvent::LOADED_EVENT, new ClassMetadataLoadedEvent($classMetadata)); } if (null !== $this->cache) { $this->cache->save($class, $classMetadata); } return $this->loadedClasses[$class] = $classMetadata; }
/** * @test */ public function get_metadata_for_should_not_merge_with_superclasses_if_fails() { $this->loader->loadClassMetadata(Argument::type('Kcs\\Metadata\\ClassMetadataInterface'))->willReturn(false); $metadata = $this->prophesize('Kcs\\Metadata\\ClassMetadataInterface'); $metadata->merge(Argument::cetera())->shouldNotBeCalled(); $metadata->getReflectionClass()->willReturn(new \ReflectionClass($this)); $factory = new MockedClassMetadataFactory($this->loader->reveal()); $factory->mock = $metadata->reveal(); $factory->getMetadataFor($this); }