/** * Adds an object to this repository. * * @param object $object The object to add * @return void * @throws \TYPO3\Flow\Persistence\Exception\IllegalObjectTypeException * @api */ public function add($object) { if (!is_object($object) || !$object instanceof $this->entityClassName) { $type = is_object($object) ? get_class($object) : gettype($object); throw new \TYPO3\Flow\Persistence\Exception\IllegalObjectTypeException('The value given to add() was ' . $type . ' , however the ' . get_class($this) . ' can only store ' . $this->entityClassName . ' instances.', 1298403438); } $this->persistenceManager->add($object); }
/** * Helper function which creates or fetches a resource pointer object for a given hash. * * If a ResourcePointer with the given hash exists, this one is used. Else, a new one * is created. This is a workaround for missing ValueObject support in Doctrine. * * @param string $hash * @return \TYPO3\Flow\Resource\ResourcePointer */ public function getResourcePointerForHash($hash) { $resourcePointer = $this->persistenceManager->getObjectByIdentifier($hash, 'TYPO3\\Flow\\Resource\\ResourcePointer'); if (!$resourcePointer) { $resourcePointer = new \TYPO3\Flow\Resource\ResourcePointer($hash); $this->persistenceManager->add($resourcePointer); } return $resourcePointer; }
/** * Checks if a propertyValue contains an entity and persists it. * * @param mixed $propertyValue * @return void */ protected function persistEntities($propertyValue) { if (!$propertyValue instanceof \Iterator && !is_array($propertyValue)) { $propertyValue = array($propertyValue); } foreach ($propertyValue as $possibleEntity) { if (is_object($possibleEntity) && $possibleEntity instanceof \TYPO3\Flow\Persistence\Aspect\PersistenceMagicInterface) { $this->persistenceManager->isNewObject($possibleEntity) ? $this->persistenceManager->add($possibleEntity) : $this->persistenceManager->update($possibleEntity); // TODO: Needed because the originalAsset will not cascade persist. We should find a generic solution to this. if ($possibleEntity instanceof ImageVariant) { $asset = $possibleEntity->getOriginalAsset(); $this->persistenceManager->isNewObject($asset) ? $this->persistenceManager->add($asset) : $this->persistenceManager->update($asset); } } } }
/** * Checks if a property value contains an entity and persists it. * * @param mixed $value */ protected function persistRelatedEntities($value) { if (!is_array($value) && !$value instanceof \Iterator) { $value = array($value); } foreach ($value as $element) { if (is_object($element) && $element instanceof PersistenceMagicInterface) { $this->persistenceManager->isNewObject($element) ? $this->persistenceManager->add($element) : $this->persistenceManager->update($element); } } }
/** * @param object $object * @return void */ protected function addObjectToPersistence($object) { $this->persistenceManager->add($object); }