public function get($being) { $c = array(); if (isset($this->settings["Defaults"])) { $classRaw = $this->settings["Defaults"]; $propertyRaw = $classRaw["properties"]; unset($classRaw["properties"]); $c = $this->convert($classRaw); if (class_exists($being, false)) { $propertyDefaults = $this->convert($propertyRaw); $schema = $this->reflectionService->getClassSchema($being); if (is_object($schema)) { $properties = $schema->getProperties(); } else { $properties = array_flip($this->reflectionService->getClassPropertyNames($being)); } foreach ($properties as $property => $meta) { if ($property == "FLOW3_Persistence_Identifier") { continue; } $c["properties"][$property] = $propertyDefaults; } } } return $c; }
public function get($class) { $c = array(); if (class_exists($class)) { $c = array(); // Loac Class Annotations foreach ($this->reflectionService->getClassAnnotations($class) as $key => $object) { $shortName = $this->convertAnnotationName(get_class($object)); if (!isset($c[$shortName])) { $c[$shortName] = array(); } $c[$shortName][] = $object; } $schema = $this->reflectionService->getClassSchema($class); if (is_object($schema)) { if (!isset($c["repository"])) { $c["repository"] = array(new \Admin\Annotations\Repository(array("class" => $schema->getRepositoryClassName()))); } $properties = $schema->getProperties(); } else { $properties = array_flip($this->reflectionService->getClassPropertyNames($class)); } foreach ($properties as $property => $meta) { if ($property == "FLOW3_Persistence_Identifier") { continue; } $c["properties"][$property] = array(); // Load legacy Annotations like @var,... foreach ($this->reflectionService->getPropertyTagsValues($class, $property) as $shortName => $tags) { if (!isset($c["properties"][$property])) { $c["properties"][$property] = array(); } $c["properties"][$property][$shortName] = $tags; } // $c["properties"][$property]["type"] = array( // new \Admin\Annotations\Type(array( // "name" => $meta["type"], // "subtype" => $meta["elementType"], // )) // ); // Load Annotations and override legacy Annotations $annotations = $this->reflectionService->getPropertyAnnotations($class, $property); foreach ($annotations as $key => $objects) { $shortName = $this->convertAnnotationName($key); if (!isset($c["properties"][$property])) { $c["properties"][$property] = array(); } $c["properties"][$property][$shortName] = $objects; } } } return $c; }
/** * Fetch a class schema for the given class, if possible. * * @param string $className * @return \TYPO3\FLOW3\Reflection\ClassSchema * @throws \TYPO3\FLOW3\Persistence\Doctrine\Mapping\Exception\ClassSchemaNotFoundException */ protected function getClassSchema($className) { $className = preg_replace('/' . \TYPO3\FLOW3\Object\Proxy\Compiler::ORIGINAL_CLASSNAME_SUFFIX . '$/', '', $className); $classSchema = $this->reflectionService->getClassSchema($className); if (!$classSchema) { throw new \TYPO3\FLOW3\Persistence\Doctrine\Mapping\Exception\ClassSchemaNotFoundException('No class schema found for "' . $className . '".', 1295973082); } return $classSchema; }
/** * If $this->uriPattern is specified, this will be returned, otherwise identity properties of $this->objectType * are returned in the format {property1}/{property2}/{property3}. * If $this->objectType does not contain identity properties, an empty string is returned. * * @return string */ public function getUriPattern() { if ($this->uriPattern === NULL) { $classSchema = $this->reflectionService->getClassSchema($this->objectType); $identityProperties = $classSchema->getIdentityProperties(); if (count($identityProperties) === 0) { $this->uriPattern = ''; } else { $this->uriPattern = '{' . implode('}/{', array_keys($identityProperties)) . '}'; } } return $this->uriPattern; }
public function getProperties($source) { if ($source instanceof \Doctrine\ORM\Proxy\Proxy) { $class = get_parent_class($source); } else { $class = get_class($source); } $schema = $this->reflectionService->getClassSchema($class); if (is_object($schema)) { $properties = $schema->getProperties(); } else { $properties = array_flip($this->reflectionService->getClassPropertyNames($class)); } return $properties; }
/** * Remove objects removed from SplObjectStorage compared to * $previousSplObjectStorage. * * @param \SplObjectStorage $splObjectStorage * @param array $previousObjectStorage * @return void */ protected function removeDeletedSplObjectStorageEntries(\SplObjectStorage $splObjectStorage = NULL, array $previousObjectStorage) { // remove objects detached since reconstitution foreach ($previousObjectStorage as $item) { if ($splObjectStorage instanceof \TYPO3\FLOW3\Persistence\Generic\LazySplObjectStorage && !$this->persistenceSession->hasIdentifier($item['value']['identifier'])) { // ingore this identifier, assume it was blocked by security query rewriting upon activation continue; } $object = $this->persistenceSession->getObjectByIdentifier($item['value']['identifier']); if ($splObjectStorage === NULL || !$splObjectStorage->contains($object)) { if ($this->reflectionService->getClassSchema($object)->getModelType() === \TYPO3\FLOW3\Reflection\ClassSchema::MODELTYPE_ENTITY && $this->reflectionService->getClassSchema($object)->isAggregateRoot() === FALSE) { $this->removeEntity($object); } elseif ($this->reflectionService->getClassSchema($object)->getModelType() === \TYPO3\FLOW3\Reflection\ClassSchema::MODELTYPE_VALUEOBJECT) { $this->removeValueObject($object); } } } }
/** * An onFlush event listener used to validate entities upon persistence. * * @param \Doctrine\ORM\Event\OnFlushEventArgs $eventArgs * @return void */ public function onFlush(\Doctrine\ORM\Event\OnFlushEventArgs $eventArgs) { $unitOfWork = $this->entityManager->getUnitOfWork(); $entityInsertions = $unitOfWork->getScheduledEntityInsertions(); $validatedInstancesContainer = new \SplObjectStorage(); $knownValueObjects = array(); foreach ($entityInsertions as $entity) { if ($this->reflectionService->getClassSchema($entity)->getModelType() === \TYPO3\FLOW3\Reflection\ClassSchema::MODELTYPE_VALUEOBJECT) { $identifier = $this->getIdentifierByObject($entity); $className = $this->reflectionService->getClassNameByObject($entity); if (isset($knownValueObjects[$className][$identifier]) || $unitOfWork->getEntityPersister($className)->exists($entity)) { unset($entityInsertions[spl_object_hash($entity)]); continue; } $knownValueObjects[$className][$identifier] = TRUE; } $this->validateObject($entity, $validatedInstancesContainer); } \TYPO3\FLOW3\Reflection\ObjectAccess::setProperty($unitOfWork, 'entityInsertions', $entityInsertions, TRUE); foreach ($unitOfWork->getScheduledEntityUpdates() as $entity) { $this->validateObject($entity, $validatedInstancesContainer); } }
/** * Sets the given properties on the object. * * @param object $object The object to set properties on * @param string $identifier The identifier of the object * @param array $objectData * @return void * @throws \TYPO3\FLOW3\Persistence\Exception\UnknownObjectException */ public function thawProperties($object, $identifier, array $objectData) { $classSchema = $this->reflectionService->getClassSchema($objectData['classname']); foreach ($objectData['properties'] as $propertyName => $propertyData) { if (!$classSchema->hasProperty($propertyName)) { continue; } $propertyValue = NULL; if ($propertyData['value'] !== NULL) { switch ($propertyData['type']) { case 'integer': $propertyValue = (int) $propertyData['value']; break; case 'float': $propertyValue = (double) $propertyData['value']; break; case 'boolean': $propertyValue = (bool) $propertyData['value']; break; case 'string': $propertyValue = (string) $propertyData['value']; break; case 'array': $propertyValue = $this->mapArray($propertyData['value']); break; case 'Doctrine\\Common\\Collections\\Collection': case 'Doctrine\\Common\\Collections\\ArrayCollection': $propertyValue = new \Doctrine\Common\Collections\ArrayCollection($this->mapArray($propertyData['value'])); break; case 'SplObjectStorage': $propertyMetaData = $classSchema->getProperty($propertyName); $propertyValue = $this->mapSplObjectStorage($propertyData['value'], $propertyMetaData['lazy']); break; case 'DateTime': $propertyValue = $this->mapDateTime($propertyData['value']); break; default: if ($propertyData['value'] === FALSE) { throw new \TYPO3\FLOW3\Persistence\Exception\UnknownObjectException('An expected object was not found by the backend. It was expected for ' . $objectData['classname'] . '::' . $propertyName, 1289509867); } $propertyValue = $this->mapToObject($propertyData['value']); break; } } else { switch ($propertyData['type']) { case 'NULL': continue; break; case 'array': $propertyValue = $this->mapArray(NULL); break; case 'Doctrine\\Common\\Collections\\Collection': case 'Doctrine\\Common\\Collections\\ArrayCollection': $propertyValue = new \Doctrine\Common\Collections\ArrayCollection(); break; case 'SplObjectStorage': $propertyValue = $this->mapSplObjectStorage(NULL); break; } } \TYPO3\FLOW3\Reflection\ObjectAccess::setProperty($object, $propertyName, $propertyValue, TRUE); } if (isset($objectData['metadata'])) { $object->FLOW3_Persistence_Metadata = $objectData['metadata']; } \TYPO3\FLOW3\Reflection\ObjectAccess::setProperty($object, 'FLOW3_Persistence_Identifier', $identifier, TRUE); }
/** * Constructs a query object working on the given type * * @param string $type * @param \TYPO3\FLOW3\Reflection\ReflectionService $reflectionService */ public function __construct($type, \TYPO3\FLOW3\Reflection\ReflectionService $reflectionService) { $this->type = $type; $this->classSchema = $reflectionService->getClassSchema($type); }