Returns the object with the (internal) identifier, if it is known to the
backend. Otherwise NULL is returned.
public getObjectByIdentifier ( mixed $identifier, string $objectType = null, boolean $useLazyLoading = false ) : object | ||
$identifier | mixed | |
$objectType | string | |
$useLazyLoading | boolean | Set to TRUE if you want to use lazy loading for this object |
리턴 | object | The object for the identifier if it is known, or NULL |
/** * Loads the objects this LazySplObjectStorage is supposed to hold. * * @return void */ protected function initialize() { if (is_array($this->objectIdentifiers)) { foreach ($this->objectIdentifiers as $identifier) { try { parent::attach($this->persistenceManager->getObjectByIdentifier($identifier)); } catch (Exception\InvalidObjectDataException $exception) { // when security query rewriting holds back an object here, we skip it... } } $this->objectIdentifiers = null; } }
/** * Returns the real object this proxy stands for * * @return object The "content object" as it was originally passed to the constructor */ public function getObject() { if ($this->contentObject === null) { $this->contentObject = $this->persistenceManager->getObjectByIdentifier($this->targetId, $this->targetType); } return $this->contentObject; }
/** * Generates a unique string for the given identifier according to $this->uriPattern. * If no UriPattern is set, the path segment is equal to the (URL-encoded) $identifier - otherwise a matching * ObjectPathMapping is fetched from persistence. * If no ObjectPathMapping exists for the given identifier, a new ObjectPathMapping is created. * * @param string $identifier the technical identifier of the object * @return string|integer the resolved path segment(s) * @throws InfiniteLoopException if no unique path segment could be found after 100 iterations */ protected function getPathSegmentByIdentifier($identifier) { if ($this->getUriPattern() === '') { return rawurlencode($identifier); } $objectPathMapping = $this->objectPathMappingRepository->findOneByObjectTypeUriPatternAndIdentifier($this->objectType, $this->getUriPattern(), $identifier); if ($objectPathMapping !== null) { return $this->lowerCase ? strtolower($objectPathMapping->getPathSegment()) : $objectPathMapping->getPathSegment(); } $object = $this->persistenceManager->getObjectByIdentifier($identifier, $this->objectType); $pathSegment = $uniquePathSegment = $this->createPathSegmentForObject($object); $pathSegmentLoopCount = 0; do { if ($pathSegmentLoopCount++ > 99) { throw new InfiniteLoopException('No unique path segment could be found after ' . ($pathSegmentLoopCount - 1) . ' iterations.', 1316441798); } if ($uniquePathSegment !== '') { $objectPathMapping = $this->objectPathMappingRepository->findOneByObjectTypeUriPatternAndPathSegment($this->objectType, $this->getUriPattern(), $uniquePathSegment, !$this->lowerCase); if ($objectPathMapping === null) { $this->storeObjectPathMapping($uniquePathSegment, $identifier); break; } } $uniquePathSegment = sprintf('%s-%d', $pathSegment, $pathSegmentLoopCount); } while (true); return $this->lowerCase ? strtolower($uniquePathSegment) : $uniquePathSegment; }
/** * Fetch an object from persistence layer. * * @param mixed $identity * @param string $targetType * @return object * @throws TargetNotFoundException * @throws InvalidSourceException */ protected function fetchObjectFromPersistence($identity, $targetType) { if (is_string($identity)) { $object = $this->persistenceManager->getObjectByIdentifier($identity, $targetType); } elseif (is_array($identity)) { $object = $this->findObjectByIdentityProperties($identity, $targetType); } else { throw new InvalidSourceException(sprintf('The identity property is neither a string nor an array but of type "%s".', gettype($identity)), 1297931020); } return $object; }
/** * Fetch an object from persistence layer. * * @param mixed $identity * @param string $targetType * @return object * @throws TargetNotFoundException * @throws InvalidSourceException */ protected function fetchObjectFromPersistence($identity, $targetType) { if ($targetType === Thumbnail::class) { $object = $this->persistenceManager->getObjectByIdentifier($identity, $targetType); } elseif (is_string($identity)) { $object = $this->assetRepository->findByIdentifier($identity); } else { throw new InvalidSourceException('The identity property "' . $identity . '" is not a string.', 1415817618); } return $object; }
/** * 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; }
/** * Traverses the $array and replaces known persisted objects (tuples of * type and identifier) with actual instances. * * @param array $array * @return void */ protected function decodeObjectReferences(array &$array) { foreach ($array as &$value) { if (!is_array($value)) { continue; } if (isset($value['__flow_object_type'])) { $value = $this->persistenceManager->getObjectByIdentifier($value['__identifier'], $value['__flow_object_type'], true); } else { $this->decodeObjectReferences($value); } } }
/** * Import resources to asset management * * This command detects Flow "PersistentResource"s which are not yet available as "Asset" objects and thus don't appear * in the asset management. The type of the imported asset is determined by the file extension provided by the * PersistentResource. * * @param boolean $simulate If set, this command will only tell what it would do instead of doing it right away * @return void */ public function importResourcesCommand($simulate = false) { $this->initializeConnection(); $sql = ' SELECT r.persistence_object_identifier, r.filename, r.mediatype FROM typo3_flow_resource_resource r LEFT JOIN typo3_media_domain_model_asset a ON a.resource = r.persistence_object_identifier LEFT JOIN typo3_media_domain_model_thumbnail t ON t.resource = r.persistence_object_identifier WHERE a.persistence_object_identifier IS NULL AND t.persistence_object_identifier IS NULL '; $statement = $this->dbalConnection->prepare($sql); $statement->execute(); $resourceInfos = $statement->fetchAll(); if ($resourceInfos === array()) { $this->outputLine('Found no resources which need to be imported.'); $this->quit(); } foreach ($resourceInfos as $resourceInfo) { $mediaType = $resourceInfo['mediatype']; if (substr($mediaType, 0, 6) === 'image/') { $resource = $this->persistenceManager->getObjectByIdentifier($resourceInfo['persistence_object_identifier'], \Neos\Flow\ResourceManagement\PersistentResource::class); if ($resource === null) { $this->outputLine('Warning: PersistentResource for file "%s" seems to be corrupt. No resource object with identifier %s could be retrieved from the Persistence Manager.', array($resourceInfo['filename'], $resourceInfo['persistence_object_identifier'])); continue; } if (!$resource->getStream()) { $this->outputLine('Warning: PersistentResource for file "%s" seems to be corrupt. The actual data of resource %s could not be found in the resource storage.', array($resourceInfo['filename'], $resourceInfo['persistence_object_identifier'])); continue; } $image = new Image($resource); if ($simulate) { $this->outputLine('Simulate: Adding new image "%s" (%sx%s px)', array($image->getResource()->getFilename(), $image->getWidth(), $image->getHeight())); } else { $this->assetRepository->add($image); $this->outputLine('Adding new image "%s" (%sx%s px)', array($image->getResource()->getFilename(), $image->getWidth(), $image->getHeight())); } } } }
/** * @param array $source * @param PropertyMappingConfigurationInterface $configuration * @return PersistentResource|FlowError * @throws \Exception */ protected function handleFileUploads(array $source, PropertyMappingConfigurationInterface $configuration = null) { if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) { if (isset($source['originallySubmittedResource']) && isset($source['originallySubmittedResource']['__identity'])) { return $this->persistenceManager->getObjectByIdentifier($source['originallySubmittedResource']['__identity'], PersistentResource::class); } return null; } if ($source['error'] !== \UPLOAD_ERR_OK) { switch ($source['error']) { case \UPLOAD_ERR_INI_SIZE: case \UPLOAD_ERR_FORM_SIZE: case \UPLOAD_ERR_PARTIAL: return new FlowError(Files::getUploadErrorMessage($source['error']), 1264440823); default: $this->systemLogger->log(sprintf('A server error occurred while converting an uploaded resource: "%s"', Files::getUploadErrorMessage($source['error'])), LOG_ERR); return new FlowError('An error occurred while uploading. Please try again or contact the administrator if the problem remains', 1340193849); } } if (isset($this->convertedResources[$source['tmp_name']])) { return $this->convertedResources[$source['tmp_name']]; } try { $resource = $this->resourceManager->importUploadedResource($source, $this->getCollectionName($source, $configuration)); $this->convertedResources[$source['tmp_name']] = $resource; return $resource; } catch (\Exception $exception) { $this->systemLogger->log('Could not import an uploaded file', LOG_WARNING); $this->systemLogger->logException($exception); return new FlowError('During import of an uploaded file an error occurred. See log for more details.', 1264517906); } }
/** * Finds an object matching the given identifier. * * @param string $identifier The identifier of the object to find * @return object The matching object if found, otherwise NULL * @api */ public function findByIdentifier($identifier) { return $this->persistenceManager->getObjectByIdentifier($identifier, $this->entityClassName); }
/** * Reconstitutes a persistence object (entity or valueobject) identified by the given UUID. * * @param string $className The class name of the object to retrieve * @param string $uuid The UUID of the object * @return object The reconstituted persistence object, NULL if none was found */ protected function reconstitutePersistenceObject($className, $uuid) { return $this->persistenceManager->getObjectByIdentifier($uuid, $className); }
/** * Returns the workspace owner. * * @return UserInterface * @api */ public function getOwner() { if ($this->owner === null) { return null; } return $this->persistenceManager->getObjectByIdentifier($this->owner, $this->reflectionService->getDefaultImplementationClassNameForInterface(UserInterface::class)); }