/** * Builds class schemata from classes annotated as entities or value objects * * @param array $classNames * @return void * @author Robert Lemke <*****@*****.**> * @author Karsten Dambekalns <*****@*****.**> */ protected function buildClassSchemata(array $classNames) { foreach ($classNames as $className) { $classSchema = new \F3\FLOW3\Reflection\ClassSchema($className); if ($this->isClassTaggedWith($className, 'entity')) { $classSchema->setModelType(\F3\FLOW3\Reflection\ClassSchema::MODELTYPE_ENTITY); $possibleRepositoryClassName = str_replace('\\Model\\', '\\Repository\\', $className) . 'Repository'; if ($this->isClassReflected($possibleRepositoryClassName)) { $classSchema->setAggregateRoot(TRUE); } } elseif ($this->isClassTaggedWith($className, 'valueobject')) { $classSchema->setModelType(\F3\FLOW3\Reflection\ClassSchema::MODELTYPE_VALUEOBJECT); } foreach ($this->getClassPropertyNames($className) as $propertyName) { if (!$this->isPropertyTaggedWith($className, $propertyName, 'transient') && $this->isPropertyTaggedWith($className, $propertyName, 'var')) { $classSchema->addProperty($propertyName, implode(' ', $this->getPropertyTagValues($className, $propertyName, 'var')), $this->isPropertyTaggedWith($className, $propertyName, 'lazy')); } if ($this->isPropertyTaggedWith($className, $propertyName, 'uuid')) { $classSchema->setUuidPropertyName($propertyName); } if ($this->isPropertyTaggedWith($className, $propertyName, 'identity')) { $classSchema->markAsIdentityProperty($propertyName); } } $this->classSchemata[$className] = $classSchema; } }
/** * @test * @author Karsten Dambekalns <*****@*****.**> */ public function setModelTypeResetsUuidPropertyNameAndIdentityPropertiesForValueObjects() { $classSchema = new \F3\FLOW3\Reflection\ClassSchema('SomeClass'); $classSchema->setModelType(\F3\FLOW3\Reflection\ClassSchema::MODELTYPE_ENTITY); $classSchema->addProperty('foo', 'string'); $classSchema->addProperty('bar', 'string'); $classSchema->setUuidPropertyName('foo'); $classSchema->markAsIdentityProperty('bar'); $this->assertSame('foo', $classSchema->getUuidPropertyName()); $this->assertSame(array('bar' => 'string'), $classSchema->getIdentityProperties()); $classSchema->setModelType(\F3\FLOW3\Reflection\ClassSchema::MODELTYPE_VALUEOBJECT); $this->assertNull($classSchema->getUuidPropertyName()); $this->assertSame(array(), $classSchema->getIdentityProperties()); }