Note: this returns an identifier even if the object has not been
persisted in case of AOP-managed entities. Use isNewObject() if you need
to distinguish those cases.
public getIdentifierByObject ( object $object ) : mixed | ||
$object | object | |
return | mixed | The identifier for the object if it is known, or NULL |
/** * Change the property on the given node. * * @param NodeData $node * @return void */ public function execute(NodeData $node) { foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) { if (isset($propertyConfiguration['type']) && in_array(trim($propertyConfiguration['type']), $this->getHandledObjectTypes())) { if (!isset($nodeProperties)) { $nodeRecordQuery = $this->entityManager->getConnection()->prepare('SELECT properties FROM typo3_typo3cr_domain_model_nodedata WHERE persistence_object_identifier=?'); $nodeRecordQuery->execute([$this->persistenceManager->getIdentifierByObject($node)]); $nodeRecord = $nodeRecordQuery->fetch(\PDO::FETCH_ASSOC); $nodeProperties = unserialize($nodeRecord['properties']); } if (!isset($nodeProperties[$propertyName]) || !is_object($nodeProperties[$propertyName])) { continue; } /** @var Asset $assetObject */ $assetObject = $nodeProperties[$propertyName]; $nodeProperties[$propertyName] = null; $stream = $assetObject->getResource()->getStream(); if ($stream === false) { continue; } fclose($stream); $objectType = TypeHandling::getTypeForValue($assetObject); $objectIdentifier = ObjectAccess::getProperty($assetObject, 'Persistence_Object_Identifier', true); $nodeProperties[$propertyName] = array('__flow_object_type' => $objectType, '__identifier' => $objectIdentifier); } } if (isset($nodeProperties)) { $nodeUpdateQuery = $this->entityManager->getConnection()->prepare('UPDATE typo3_typo3cr_domain_model_nodedata SET properties=? WHERE persistence_object_identifier=?'); $nodeUpdateQuery->execute([serialize($nodeProperties), $this->persistenceManager->getIdentifierByObject($node)]); } }
/** * Gets the Party having an Account assigned * * @param Account $account * @return AbstractParty */ public function getAssignedPartyOfAccount(Account $account) { $accountIdentifier = $this->persistenceManager->getIdentifierByObject($account); if (!isset($this->accountsInPartyRuntimeCache[$accountIdentifier])) { $party = $this->partyRepository->findOneHavingAccount($account); $this->accountsInPartyRuntimeCache[$accountIdentifier] = $party; } return $this->accountsInPartyRuntimeCache[$accountIdentifier]; }
/** * Renders a hidden form field containing the technical identity of the given object. * * @param object $object Object to create the identity field for * @param string $name Name * @return string A hidden field containing the Identity (UUID in Flow) of the given object or NULL if the object is unknown to the persistence framework * @see \Neos\Flow\Mvc\Controller\Argument::setValue() */ protected function renderHiddenIdentityField($object, $name) { if (!is_object($object) || $this->persistenceManager->isNewObject($object)) { return ''; } $identifier = $this->persistenceManager->getIdentifierByObject($object); if ($identifier === null) { return chr(10) . '<!-- Object of type ' . get_class($object) . ' is without identity -->' . chr(10); } $name = $this->prefixFieldName($name) . '[__identity]'; $this->registerFieldNameForFormTokenGeneration($name); return chr(10) . '<input type="hidden" name="' . $name . '" value="' . $identifier . '" />' . chr(10); }
/** * Outputs the identifier of the specified object * * @param object $value the object to render the identifier for, or NULL if VH children should be used * @return mixed the identifier of $value, usually the UUID * @throws ViewHelper\Exception if the given value is no object * @api */ public function render($value = null) { if ($value === null) { $value = $this->renderChildren(); } if ($value === null) { return null; } if (!is_object($value)) { throw new ViewHelper\Exception('f:format.identifier expects an object, ' . gettype($value) . ' given.', 1337700024); } return $this->persistenceManager->getIdentifierByObject($value); }
/** * Fetches the identifier from the set content object. If that * is not using automatically introduced UUIDs by Flow it tries * to call persistAll() and fetch the identifier again. If it still * fails, an exception is thrown. * * @return void * @throws IllegalObjectTypeException */ protected function initializeObject() { if ($this->contentObject !== null) { $this->targetType = get_class($this->contentObject); $this->targetId = $this->persistenceManager->getIdentifierByObject($this->contentObject); if ($this->targetId === null) { $this->persistenceManager->persistAll(); $this->targetId = $this->persistenceManager->getIdentifierByObject($this->contentObject); if ($this->targetId === null) { throw new IllegalObjectTypeException('You cannot add an object without an identifier to a ContentObjectProxy. Probably you didn\'t add a valid entity?', 1303859434); } } } }
/** * After returning advice, generates the value hash for the object * * @param JoinPointInterface $joinPoint The current join point * @return void * @Flow\After("Neos\Flow\Persistence\Aspect\PersistenceMagicAspect->isNonEmbeddedValueObject && method(.*->__construct()) && filter(Neos\Flow\Persistence\Doctrine\Mapping\Driver\FlowAnnotationDriver)") */ public function generateValueHash(JoinPointInterface $joinPoint) { $proxy = $joinPoint->getProxy(); $proxyClassName = get_class($proxy); $hashSourceParts = []; $classSchema = $this->reflectionService->getClassSchema($proxyClassName); foreach ($classSchema->getProperties() as $property => $propertySchema) { // Currently, private properties are transient. Should this behaviour change, they need to be included // in the value hash generation if ($classSchema->isPropertyTransient($property) || $this->reflectionService->isPropertyPrivate($proxyClassName, $property)) { continue; } $propertyValue = ObjectAccess::getProperty($proxy, $property, true); if (is_object($propertyValue) === true) { // The persistence manager will return NULL if the given object is unknown to persistence $propertyValue = $this->persistenceManager->getIdentifierByObject($propertyValue) ?: $propertyValue; } $hashSourceParts[$property] = $propertyValue; } ksort($hashSourceParts); $hashSourceParts['__class_name__'] = $proxyClassName; $serializedSource = $this->useIgBinary === true ? igbinary_serialize($hashSourceParts) : serialize($hashSourceParts); $proxy = $joinPoint->getProxy(); ObjectAccess::setProperty($proxy, 'Persistence_Object_Identifier', sha1($serializedSource), true); }
/** * Removes unused ImageVariants after a Node property changes to a different ImageVariant. * This is triggered via the nodePropertyChanged event. * * Note: This method it triggered by the "nodePropertyChanged" signal, @see \Neos\ContentRepository\Domain\Model\Node::emitNodePropertyChanged() * * @param NodeInterface $node the affected node * @param string $propertyName name of the property that has been changed/added * @param mixed $oldValue the property value before it was changed or NULL if the property is new * @param mixed $value the new property value * @return void */ public function removeUnusedImageVariant(NodeInterface $node, $propertyName, $oldValue, $value) { if ($oldValue === $value || !$oldValue instanceof ImageVariant) { return; } $identifier = $this->persistenceManager->getIdentifierByObject($oldValue); $results = $this->nodeDataRepository->findNodesByRelatedEntities(array(ImageVariant::class => [$identifier])); // This case shouldn't happen as the query will usually find at least the node that triggered this call, still if there is no relation we can remove the ImageVariant. if ($results === []) { $this->assetRepository->remove($oldValue); return; } // If the result contains exactly the node that got a new ImageVariant assigned then we are safe to remove the asset here. if ($results === [$node->getNodeData()]) { $this->assetRepository->remove($oldValue); } }
/** * Convert an object from \Neos\Media\Domain\Model\ImageInterface to a json representation * * @param ImageInterface $source * @param string $targetType must be 'string' * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface $configuration * @return string|Error The converted Image, a Validation Error or NULL */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null) { $data = array('__identity' => $this->persistenceManager->getIdentifierByObject($source), '__type' => TypeHandling::getTypeForValue($source)); if ($source instanceof ImageVariant) { $data['originalAsset'] = ['__identity' => $this->persistenceManager->getIdentifierByObject($source->getOriginalAsset())]; $adjustments = array(); foreach ($source->getAdjustments() as $adjustment) { $index = TypeHandling::getTypeForValue($adjustment); $adjustments[$index] = array(); foreach (ObjectAccess::getGettableProperties($adjustment) as $propertyName => $propertyValue) { $adjustments[$index][$propertyName] = $propertyValue; } } $data['adjustments'] = $adjustments; } return $data; }
/** * Removes all routing cache entries for the given $nodeData * * @param NodeInterface $node * @return void */ protected function flushRoutingCacheForNode(NodeInterface $node) { $nodeData = $node->getNodeData(); $nodeDataIdentifier = $this->persistenceManager->getIdentifierByObject($nodeData); if ($nodeDataIdentifier === null) { return; } $this->routerCachingService->flushCachesByTag($nodeDataIdentifier); }
/** * @param Asset $asset * @return array */ protected function getAssetProperties(Asset $asset) { $assetProperties = ['assetUuid' => $this->persistenceManager->getIdentifierByObject($asset), 'filename' => $asset->getResource()->getFilename()]; $thumbnail = $this->thumbnailService->getThumbnail($asset, $this->thumbnailService->getThumbnailConfigurationForPreset('Neos.Media.Browser:Thumbnail')); if ($thumbnail !== null) { $assetProperties['previewImageResourceUri'] = $this->thumbnailService->getUriForThumbnail($thumbnail); $assetProperties['previewSize'] = ['w' => $thumbnail->getWidth(), 'h' => $thumbnail->getHeight()]; } return $assetProperties; }
/** * @param ImageInterface $thumbnail * @return string * @throws ThumbnailServiceException */ public function getUriForThumbnail(ImageInterface $thumbnail) { $resource = $thumbnail->getResource(); if ($resource) { return $this->resourceManager->getPublicPersistentResourceUri($resource); } $staticResource = $thumbnail->getStaticResource(); if ($staticResource === null) { throw new ThumbnailServiceException(sprintf('Could not generate URI for static thumbnail "%s".', $this->persistenceManager->getIdentifierByObject($thumbnail)), 1450178437); } return $this->resourceManager->getPublicPackageResourceUriByPath($staticResource); }
/** * Finds an object matching the given identifier. * * @param mixed $identifier The identifier of the object to find * @return object The matching object if found, otherwise NULL * @api */ public function findByIdentifier($identifier) { $object = $this->persistenceManager->getObjectByIdentifier($identifier, $this->entityClassName); if ($object === null) { foreach ($this->addedResources as $addedResource) { if ($this->persistenceManager->getIdentifierByObject($addedResource) === $identifier) { $object = $addedResource; break; } } } return $object; }
/** * Actually convert from $source to $targetType, taking into account the fully * built $convertedChildProperties and $configuration. * * The return value can be one of three types: * - an arbitrary object, or a simple type (which has been created while mapping). * This is the normal case. * - NULL, indicating that this object should *not* be mapped (i.e. a "File Upload" Converter could return NULL if no file has been uploaded, and a silent failure should occur. * - An instance of \Neos\Error\Messages\Error -- This will be a user-visible error message later on. * Furthermore, it should throw an Exception if an unexpected failure (like a security error) occurred or a configuration issue happened. * * @param mixed $source * @param string $targetType * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface $configuration * @return mixed|Error the target type, or an error object if a user-error occurred * @throws TypeConverterException thrown in case a developer error occurred * @api */ public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) { $properties = ObjectAccess::getGettableProperties($source); if ($source instanceof \Doctrine\ORM\Proxy\Proxy) { $className = get_parent_class($source); } else { $className = get_class($source); } $properties = array_merge($properties, $convertedChildProperties); if ($source instanceof PersistenceMagicInterface) { $properties['__identity'] = $this->persistenceManager->getIdentifierByObject($source); } $properties['__type'] = $className; return $properties; }
/** * Checks if the given value is a unique entity depending on it's identity properties or * custom configured identity properties. * * @param mixed $value The value that should be validated * @return void * @throws InvalidValidationOptionsException * @api */ protected function isValid($value) { if (!is_object($value)) { throw new InvalidValidationOptionsException('The value supplied for the UniqueEntityValidator must be an object.', 1358454270); } $classSchema = $this->reflectionService->getClassSchema(TypeHandling::getTypeForValue($value)); if ($classSchema === null || $classSchema->getModelType() !== ClassSchema::MODELTYPE_ENTITY) { throw new InvalidValidationOptionsException('The object supplied for the UniqueEntityValidator must be an entity.', 1358454284); } if ($this->options['identityProperties'] !== null) { $identityProperties = $this->options['identityProperties']; foreach ($identityProperties as $propertyName) { if ($classSchema->hasProperty($propertyName) === false) { throw new InvalidValidationOptionsException(sprintf('The custom identity property name "%s" supplied for the UniqueEntityValidator does not exists in "%s".', $propertyName, $classSchema->getClassName()), 1358960500); } } } else { $identityProperties = array_keys($classSchema->getIdentityProperties()); } if (count($identityProperties) === 0) { throw new InvalidValidationOptionsException('The object supplied for the UniqueEntityValidator must have at least one identity property.', 1358459831); } $identifierProperties = $this->reflectionService->getPropertyNamesByAnnotation($classSchema->getClassName(), 'Doctrine\\ORM\\Mapping\\Id'); if (count($identifierProperties) > 1) { throw new InvalidValidationOptionsException('The object supplied for the UniqueEntityValidator must only have one identifier property @ORM\\Id.', 1358501745); } $identifierPropertyName = count($identifierProperties) > 0 ? array_shift($identifierProperties) : 'Persistence_Object_Identifier'; $query = $this->persistenceManager->createQueryForType($classSchema->getClassName()); $constraints = [$query->logicalNot($query->equals($identifierPropertyName, $this->persistenceManager->getIdentifierByObject($value)))]; foreach ($identityProperties as $propertyName) { $constraints[] = $query->equals($propertyName, ObjectAccess::getProperty($value, $propertyName)); } if ($query->matching($query->logicalAnd($constraints))->count() > 0) { $this->addError('Another entity with the same unique identifiers already exists', 1355785874); } }
/** * Returns all nodes that use the asset in a node property. * * @param AssetInterface $asset * @return array */ public function getRelatedNodes(AssetInterface $asset) { $relationMap = []; $relationMap[TypeHandling::getTypeForValue($asset)] = [$this->persistenceManager->getIdentifierByObject($asset)]; if ($asset instanceof Image) { foreach ($asset->getVariants() as $variant) { $type = TypeHandling::getTypeForValue($variant); if (!isset($relationMap[$type])) { $relationMap[$type] = []; } $relationMap[$type][] = $this->persistenceManager->getIdentifierByObject($variant); } } return $this->nodeDataRepository->findNodesByRelatedEntities($relationMap); }
/** * Checks, whether given value can be resolved and if so, sets $this->value to the resolved value. * If $value is empty, this method checks whether a default value exists. * This method can be overridden by custom RoutePartHandlers to implement custom resolving mechanisms. * * @param mixed $value value to resolve * @return boolean TRUE if value could be resolved successfully, otherwise FALSE. * @api */ protected function resolveValue($value) { if ($value === null) { return false; } if (is_object($value)) { $value = $this->persistenceManager->getIdentifierByObject($value); if ($value === null || !is_string($value) && !is_integer($value)) { return false; } } $this->value = rawurlencode($value); if ($this->lowerCase) { $this->value = strtolower($this->value); } return true; }
/** * Resolves the given entity and sets the value to a URI representation (path segment) that matches $this->uriPattern and is unique for the given object. * * @param mixed $value * @return boolean TRUE if the object could be resolved and stored in $this->value, otherwise FALSE. */ protected function resolveValue($value) { $identifier = null; if (is_array($value) && isset($value['__identity'])) { $identifier = $value['__identity']; } elseif ($value instanceof $this->objectType) { $identifier = $this->persistenceManager->getIdentifierByObject($value); } if ($identifier === null || !is_string($identifier) && !is_integer($identifier)) { return false; } $pathSegment = $this->getPathSegmentByIdentifier($identifier); if ($pathSegment === null) { return false; } $this->value = $pathSegment; return true; }
/** * Convert an object from $source to an array * * @param AssetInterface $source * @param string $targetType * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface $configuration * @return array The converted asset or NULL */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null) { $identity = $this->persistenceManager->getIdentifierByObject($source); switch (true) { case $source instanceof ImageVariant: if (!isset($convertedChildProperties['originalAsset']) || !is_array($convertedChildProperties['originalAsset'])) { return null; } $convertedChildProperties['originalAsset']['__identity'] = $this->persistenceManager->getIdentifierByObject($source->getOriginalAsset()); return array('__identity' => $identity, '__type' => \Neos\Media\Domain\Model\ImageVariant::class, 'originalAsset' => $convertedChildProperties['originalAsset'], 'adjustments' => $convertedChildProperties['adjustments']); case $source instanceof AssetInterface: if (!isset($convertedChildProperties['resource']) || !is_array($convertedChildProperties['resource'])) { return null; } $convertedChildProperties['resource']['__identity'] = $this->persistenceManager->getIdentifierByObject($source->getResource()); return array('__identity' => $identity, '__type' => \Neos\Utility\TypeHandling::getTypeForValue($source), 'title' => $source->getTitle(), 'resource' => $convertedChildProperties['resource']); } }
/** * Set the "context node" this operation was working on. * * @param NodeInterface $node * @return void */ public function setNode(NodeInterface $node) { $this->nodeIdentifier = $node->getIdentifier(); $this->workspaceName = $node->getContext()->getWorkspaceName(); $this->dimension = $node->getContext()->getDimensions(); $context = $node->getContext(); if ($context instanceof ContentContext && $context->getCurrentSite() !== null) { $siteIdentifier = $this->persistenceManager->getIdentifierByObject($context->getCurrentSite()); } else { $siteIdentifier = null; } $this->data = Arrays::arrayMergeRecursiveOverrule($this->data, array('nodeContextPath' => $node->getContextPath(), 'nodeLabel' => $node->getLabel(), 'nodeType' => $node->getNodeType()->getName(), 'site' => $siteIdentifier)); $node = self::getClosestAggregateNode($node); if ($node !== null) { $this->documentNodeIdentifier = $node->getIdentifier(); $this->data = Arrays::arrayMergeRecursiveOverrule($this->data, array('documentNodeContextPath' => $node->getContextPath(), 'documentNodeLabel' => $node->getLabel(), 'documentNodeType' => $node->getNodeType()->getName())); } }
/** * * * @return void */ public function updateEventsAfterPublish() { if (!$this->eventEmittingService->isEnabled()) { return; } /** @var $entityManager EntityManager */ $entityManager = $this->entityManager; foreach ($this->scheduledNodeEventUpdates as $documentPublish) { /* @var $nodeEvent NodeEvent */ $nodeEvent = $this->eventEmittingService->emit(self::DOCUMENT_PUBLISHED, array(), NodeEvent::class); $nodeEvent->setNode($documentPublish['documentNode']); $nodeEvent->setWorkspaceName($documentPublish['targetWorkspace']); $this->persistenceManager->whitelistObject($nodeEvent); $this->persistenceManager->persistAll(true); $parentEventIdentifier = $this->persistenceManager->getIdentifierByObject($nodeEvent); $qb = $entityManager->createQueryBuilder(); $qb->update(NodeEvent::class, 'e')->set('e.parentEvent', ':parentEventIdentifier')->setParameter('parentEventIdentifier', $parentEventIdentifier)->where('e.parentEvent IS NULL')->andWhere('e.workspaceName = :workspaceName')->setParameter('workspaceName', $documentPublish['workspaceName'])->andWhere('e.documentNodeIdentifier = :documentNodeIdentifier')->setParameter('documentNodeIdentifier', $documentPublish['documentNode']->getIdentifier())->andWhere('e.eventType != :publishedEventType')->setParameter('publishedEventType', self::DOCUMENT_PUBLISHED)->getQuery()->execute(); } $this->scheduledNodeEventUpdates = array(); }
/** * Traverses the $array and replaces known persisted objects with a tuple of * type and identifier. * * @param array $array * @return void * @throws \RuntimeException */ protected function encodeObjectReferences(array &$array) { foreach ($array as &$value) { if (is_array($value)) { $this->encodeObjectReferences($value); } if (!is_object($value) || is_object($value) && $value instanceof DependencyProxy) { continue; } $propertyClassName = TypeHandling::getTypeForValue($value); if ($value instanceof \SplObjectStorage) { throw new \RuntimeException('SplObjectStorage in array properties is not supported', 1375196580); } elseif ($value instanceof \Doctrine\Common\Collections\Collection) { throw new \RuntimeException('Collection in array properties is not supported', 1375196581); } elseif ($value instanceof \ArrayObject) { throw new \RuntimeException('ArrayObject in array properties is not supported', 1375196582); } elseif ($this->persistenceManager->isNewObject($value) === false && ($this->reflectionService->isClassAnnotatedWith($propertyClassName, Flow\Entity::class) || $this->reflectionService->isClassAnnotatedWith($propertyClassName, Flow\ValueObject::class) || $this->reflectionService->isClassAnnotatedWith($propertyClassName, \Doctrine\ORM\Mapping\Entity::class))) { $value = ['__flow_object_type' => $propertyClassName, '__identifier' => $this->persistenceManager->getIdentifierByObject($value)]; } } }
/** * Recursively converts objects in an array to their identifiers * * @param array $routeValues the array to be processed * @return array the modified array or NULL if $routeValues contain an object and its identifier could not be determined */ protected function convertObjectsToHashes(array $routeValues) { foreach ($routeValues as &$value) { if (is_object($value)) { if ($value instanceof CacheAwareInterface) { $identifier = $value->getCacheEntryIdentifier(); } else { $identifier = $this->persistenceManager->getIdentifierByObject($value); } if ($identifier === null) { return null; } $value = $identifier; } elseif (is_array($value)) { $value = $this->convertObjectsToHashes($value); if ($value === null) { return null; } } } return $routeValues; }
/** * @return string */ public function getIdentifier() { return $this->persistenceManager->getIdentifierByObject($this); }
/** * Serializes an object as property array. * * @param object $object The object to store in the registry * @param boolean $isTopLevelItem Internal flag for managing the recursion * @return array The property array */ public function serializeObjectAsPropertyArray($object, $isTopLevelItem = true) { if ($isTopLevelItem) { $this->objectReferences = new \SplObjectStorage(); } $this->objectReferences->attach($object); $className = get_class($object); $propertyArray = []; foreach ($this->reflectionService->getClassPropertyNames($className) as $propertyName) { if ($this->reflectionService->isPropertyTaggedWith($className, $propertyName, 'transient')) { continue; } $propertyReflection = new PropertyReflection($className, $propertyName); $propertyValue = $propertyReflection->getValue($object); if (is_object($propertyValue) && $propertyValue instanceof DependencyInjection\DependencyProxy) { continue; } if (is_object($propertyValue) && isset($this->objectReferences[$propertyValue])) { $propertyArray[$propertyName][self::TYPE] = 'object'; $propertyArray[$propertyName][self::VALUE] = \spl_object_hash($propertyValue); continue; } $propertyClassName = is_object($propertyValue) ? get_class($propertyValue) : ''; if ($propertyClassName === 'SplObjectStorage') { $propertyArray[$propertyName][self::TYPE] = 'SplObjectStorage'; $propertyArray[$propertyName][self::VALUE] = []; foreach ($propertyValue as $storedObject) { $propertyArray[$propertyName][self::VALUE][] = spl_object_hash($storedObject); $this->serializeObjectAsPropertyArray($storedObject, false); } } elseif (is_object($propertyValue) && $propertyValue instanceof \Doctrine\Common\Collections\Collection) { $propertyArray[$propertyName][self::TYPE] = 'Collection'; $propertyArray[$propertyName][self::CLASSNAME] = get_class($propertyValue); foreach ($propertyValue as $storedObject) { $propertyArray[$propertyName][self::VALUE][] = spl_object_hash($storedObject); $this->serializeObjectAsPropertyArray($storedObject, false); } } elseif (is_object($propertyValue) && $propertyValue instanceof \ArrayObject) { $propertyArray[$propertyName][self::TYPE] = 'ArrayObject'; $propertyArray[$propertyName][self::VALUE] = $this->buildStorageArrayForArrayProperty($propertyValue->getArrayCopy()); } elseif (is_object($propertyValue) && $this->persistenceManager->isNewObject($propertyValue) === false && ($this->reflectionService->isClassAnnotatedWith($propertyClassName, Flow\Entity::class) || $this->reflectionService->isClassAnnotatedWith($propertyClassName, Flow\ValueObject::class) || $this->reflectionService->isClassAnnotatedWith($propertyClassName, ORM\Entity::class))) { $propertyArray[$propertyName][self::TYPE] = 'persistenceObject'; $propertyArray[$propertyName][self::VALUE] = get_class($propertyValue) . ':' . $this->persistenceManager->getIdentifierByObject($propertyValue); } elseif (is_object($propertyValue)) { $propertyObjectName = $this->objectManager->getObjectNameByClassName($propertyClassName); if ($this->objectManager->getScope($propertyObjectName) === Configuration::SCOPE_SINGLETON) { continue; } $propertyArray[$propertyName][self::TYPE] = 'object'; $propertyArray[$propertyName][self::VALUE] = spl_object_hash($propertyValue); $this->serializeObjectAsPropertyArray($propertyValue, false); } elseif (is_array($propertyValue)) { $propertyArray[$propertyName][self::TYPE] = 'array'; $propertyArray[$propertyName][self::VALUE] = $this->buildStorageArrayForArrayProperty($propertyValue); } else { $propertyArray[$propertyName][self::TYPE] = 'simple'; $propertyArray[$propertyName][self::VALUE] = $propertyValue; } } $this->objectsAsArray[spl_object_hash($object)] = [self::CLASSNAME => $className, self::PROPERTIES => $propertyArray]; if ($isTopLevelItem) { return $this->objectsAsArray; } }
/** * Change the property on the given node. * * @param NodeData $node * @return void */ public function execute(NodeData $node) { foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) { if (isset($propertyConfiguration['type']) && ($propertyConfiguration['type'] === ImageInterface::class || preg_match('/array\\<.*\\>/', $propertyConfiguration['type']))) { if (!isset($nodeProperties)) { $nodeRecordQuery = $this->entityManager->getConnection()->prepare('SELECT properties FROM typo3_typo3cr_domain_model_nodedata WHERE persistence_object_identifier=?'); $nodeRecordQuery->execute([$this->persistenceManager->getIdentifierByObject($node)]); $nodeRecord = $nodeRecordQuery->fetch(\PDO::FETCH_ASSOC); $nodeProperties = unserialize($nodeRecord['properties']); } if (!isset($nodeProperties[$propertyName]) || empty($nodeProperties[$propertyName])) { continue; } if ($propertyConfiguration['type'] === ImageInterface::class) { $adjustments = array(); $oldVariantConfiguration = $nodeProperties[$propertyName]; if (is_array($oldVariantConfiguration)) { foreach ($oldVariantConfiguration as $variantPropertyName => $property) { switch (substr($variantPropertyName, 3)) { case 'originalImage': /** * @var $originalAsset Image */ $originalAsset = $this->assetRepository->findByIdentifier($this->persistenceManager->getIdentifierByObject($property)); break; case 'processingInstructions': $adjustments = $this->processingInstructionsConverter->convertFrom($property, 'array'); break; } } $nodeProperties[$propertyName] = null; if (isset($originalAsset)) { $stream = $originalAsset->getResource()->getStream(); if ($stream === false) { continue; } fclose($stream); $newImageVariant = new ImageVariant($originalAsset); foreach ($adjustments as $adjustment) { $newImageVariant->addAdjustment($adjustment); } $originalAsset->addVariant($newImageVariant); $this->assetRepository->update($originalAsset); $nodeProperties[$propertyName] = $this->persistenceManager->getIdentifierByObject($newImageVariant); } } } elseif (preg_match('/array\\<.*\\>/', $propertyConfiguration['type'])) { if (is_array($nodeProperties[$propertyName])) { $convertedValue = []; foreach ($nodeProperties[$propertyName] as $entryValue) { if (!is_object($entryValue)) { continue; } $stream = $entryValue->getResource()->getStream(); if ($stream === false) { continue; } fclose($stream); $existingObjectIdentifier = null; try { $existingObjectIdentifier = $this->persistenceManager->getIdentifierByObject($entryValue); if ($existingObjectIdentifier !== null) { $convertedValue[] = $existingObjectIdentifier; } } catch (\Exception $exception) { } } $nodeProperties[$propertyName] = $convertedValue; } } } } if (isset($nodeProperties)) { $nodeUpdateQuery = $this->entityManager->getConnection()->prepare('UPDATE typo3_typo3cr_domain_model_nodedata SET properties=? WHERE persistence_object_identifier=?'); $nodeUpdateQuery->execute([serialize($nodeProperties), $this->persistenceManager->getIdentifierByObject($node)]); } }
/** * Convert an entity or valueobject to a string representation (by using the identifier) * * @param object $source * @param string $targetType * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface $configuration * @return object the target type */ public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) { $identifier = $this->persistenceManager->getIdentifierByObject($source); return $identifier; }
/** * Converts the given source object to an array containing the type and identity. * * @param object $source * @param string $targetType * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface $configuration * @return array */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null) { return ['__identity' => $this->persistenceManager->getIdentifierByObject($source), '__type' => TypeHandling::getTypeForValue($source)]; }
/** * Traverses the given object structure in order to transform it into an * array structure. * * @param object $object Object to traverse * @param array $configuration Configuration for transforming the given object or NULL * @return array Object structure as an array */ protected function transformObject($object, array $configuration) { if ($object instanceof \DateTimeInterface) { return $object->format(\DateTime::ISO8601); } else { $propertyNames = ObjectAccess::getGettablePropertyNames($object); $propertiesToRender = []; foreach ($propertyNames as $propertyName) { if (isset($configuration['_only']) && is_array($configuration['_only']) && !in_array($propertyName, $configuration['_only'])) { continue; } if (isset($configuration['_exclude']) && is_array($configuration['_exclude']) && in_array($propertyName, $configuration['_exclude'])) { continue; } $propertyValue = ObjectAccess::getProperty($object, $propertyName); if (!is_array($propertyValue) && !is_object($propertyValue)) { $propertiesToRender[$propertyName] = $propertyValue; } elseif (isset($configuration['_descend']) && array_key_exists($propertyName, $configuration['_descend'])) { $propertiesToRender[$propertyName] = $this->transformValue($propertyValue, $configuration['_descend'][$propertyName]); } } if (isset($configuration['_exposeObjectIdentifier']) && $configuration['_exposeObjectIdentifier'] === true) { if (isset($configuration['_exposedObjectIdentifierKey']) && strlen($configuration['_exposedObjectIdentifierKey']) > 0) { $identityKey = $configuration['_exposedObjectIdentifierKey']; } else { $identityKey = '__identity'; } $propertiesToRender[$identityKey] = $this->persistenceManager->getIdentifierByObject($object); } if (isset($configuration['_exposeClassName']) && ($configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_FULLY_QUALIFIED || $configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_UNQUALIFIED)) { $className = TypeHandling::getTypeForValue($object); $classNameParts = explode('\\', $className); $propertiesToRender['__class'] = $configuration['_exposeClassName'] === self::EXPOSE_CLASSNAME_FULLY_QUALIFIED ? $className : array_pop($classNameParts); } return $propertiesToRender; } }
/** * Returns the workspace owner. * * @param UserInterface|string $user The new user, or user's UUID * @api */ public function setOwner($user) { // Note: We need to do a bit of uuid juggling here, because we can't bind the workspaces Owner to a specific // implementation, and creating entity relations via interfaces is not supported by Flow. Since the property // mapper will call setOwner() with a string parameter (because the property $owner is string), but developers // will want to use objects, we need to support both. if ($user === null || $user === '') { $this->owner = ''; return; } if (is_string($user) && preg_match('/^([a-f0-9]){8}-([a-f0-9]){4}-([a-f0-9]){4}-([a-f0-9]){4}-([a-f0-9]){12}$/', $user)) { $this->owner = $user; return; } if (!$user instanceof UserInterface) { throw new \InvalidArgumentException(sprintf('$user must be an instance of UserInterface, %s given.', gettype($user)), 1447764244); } $this->owner = $this->persistenceManager->getIdentifierByObject($user); }
/** * Filter the object by its identifier (UUID) * * @param object $element * @param string $identifier * @return boolean */ protected function matchesIdentifierFilter($element, $identifier) { return $this->persistenceManager->getIdentifierByObject($element) === $identifier; }