本文整理汇总了PHP中TYPO3\Flow\Persistence\PersistenceManagerInterface::getObjectByIdentifier方法的典型用法代码示例。如果您正苦于以下问题:PHP PersistenceManagerInterface::getObjectByIdentifier方法的具体用法?PHP PersistenceManagerInterface::getObjectByIdentifier怎么用?PHP PersistenceManagerInterface::getObjectByIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\Flow\Persistence\PersistenceManagerInterface
的用法示例。
在下文中一共展示了PersistenceManagerInterface::getObjectByIdentifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serialize
/**
* @param array $source
* @param boolean $enableSideLoading
* @return string
*/
public function serialize(array $source, $enableSideLoading = TRUE)
{
$data = array();
foreach ($source as $variableName => $valueToRender) {
if (class_exists($variableName)) {
$variableName = EmberDataUtility::uncamelizeClassName($variableName);
}
$data[$variableName] = $this->transformValue($valueToRender, isset($this->configuration[$variableName]) ? $this->configuration[$variableName] : array(), FALSE, $enableSideLoading);
}
if (!empty($this->objectsToSideload)) {
foreach ($this->objectsToSideload as $objectType => $objectUuids) {
if (empty($objectUuids)) {
continue;
}
if (!isset($data[$objectType])) {
$data[$objectType] = array();
}
foreach ($objectUuids as $objectUuid) {
$object = $this->persistenceManager->getObjectByIdentifier($objectUuid, EmberDataUtility::camelizeClassName($objectType));
$data[$objectType][] = $this->transformValue($object, isset($this->configuration[$objectType]) ? $this->configuration[$objectType] : array(), FALSE, FALSE);
}
}
}
foreach ($data as $objectType => $sideLoadedCollection) {
foreach ($sideLoadedCollection as $objectIndex => $sideLoadedObject) {
if (isset($sideLoadedObject['links'])) {
foreach ($sideLoadedObject['links'] as $propertyName => $links) {
$data[$objectType][$objectIndex]['links'][$propertyName] = $this->getUrl($propertyName) . implode(',', $links);
}
}
}
}
return json_encode((object) $data);
}
示例2: deployByIdentifier
/**
* @param string $identifier
* @param LoggerInterface $logger
* @param boolean $dryRun
* @return \Lightwerk\SurfRunner\Domain\Model\Deployment
* @throws \Lightwerk\SurfRunner\Exception\NoAvailableDeploymentException
* @throws \Lightwerk\SurfRunner\Factory\Exception
* @throws \TYPO3\Surf\Exception
*/
public function deployByIdentifier($identifier, LoggerInterface $logger, $dryRun)
{
/** @var SurfCaptainDeployment $surfCaptainDeployment */
$surfCaptainDeployment = $this->persistenceManager->getObjectByIdentifier($identifier, 'Lightwerk\\SurfCaptain\\Domain\\Model\\Deployment');
if ($surfCaptainDeployment instanceof SurfCaptainDeployment === FALSE) {
throw new NoAvailableDeploymentException('deployment with identifier ' . $identifier . ' not found', 1428685495);
}
if (!$dryRun) {
$this->setStatusBeforeDeployment($surfCaptainDeployment);
}
$logger->addBackend(new DatabaseBackend(array('deployment' => $surfCaptainDeployment, 'severityThreshold' => LOG_DEBUG)));
try {
$deployment = $this->deploymentFactory->getDeploymentByDeploymentRecord($surfCaptainDeployment, $logger);
} catch (\Lightwerk\SurfRunner\Factory\Exception $e) {
$this->setStatusAfterDeployment($surfCaptainDeployment, Deployment::STATUS_FAILED);
throw new NoAvailableDeploymentException('cannot create deployment with DeploymentFactoryException ' . $e->getMessage() . ' - ' . $e->getCode(), 1428769117);
}
$deployment->initialize();
if (!$dryRun) {
$this->emitDeploymentStarted($deployment, $surfCaptainDeployment);
try {
$deployment->deploy();
} catch (\TYPO3\Surf\Exception\InvalidConfigurationException $e) {
$this->setStatusAfterDeployment($surfCaptainDeployment, Deployment::STATUS_FAILED);
throw new NoAvailableDeploymentException('cannot deploy with InvalidConfigurationException' . $e->getMessage() . ' - ' . $e->getCode(), 1428769119);
}
$this->setStatusAfterDeployment($surfCaptainDeployment, $deployment->getStatus());
$this->emitDeploymentFinished($deployment, $surfCaptainDeployment);
} else {
$deployment->simulate();
}
return $deployment;
}
示例3: initialize
/**
* 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 (\TYPO3\Flow\Persistence\Generic\Exception\InvalidObjectDataException $exception) {
// when security query rewriting holds back an object here, we skip it...
}
}
$this->objectIdentifiers = null;
}
}
示例4: getObject
/**
* 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;
}
示例5: getPathSegmentByIdentifier
/**
* 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;
}
示例6: unserializeArray
/**
* Unserialize an array
*
* @param string $string
*
* @return array|FALSE if error appends
*/
protected function unserializeArray($string)
{
$array = unserialize($string);
if (is_array($array)) {
foreach ($array as &$val) {
if (is_string($val)) {
switch (substr($val, 0, 6)) {
case 'ARR->|':
$val = $this->unserializeArray(substr($val, 6));
if ($val === false) {
return false;
}
break;
case 'DAT->|':
$val = unserialize(substr($val, 6));
break;
case 'OBJ->|':
list($className, $reference) = explode('|', substr($val, 6));
if (strlen($className) > 0 && strlen($reference) > 0) {
$val = $this->persistenceManager->getObjectByIdentifier($reference, $className);
if ($val === false) {
return false;
}
}
break;
}
}
}
return $array;
}
return false;
}
示例7: getResourcePointerForHash
/**
* 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;
}
示例8: importResourcesCommand
/**
* Import resources to asset management
*
* This command detects Flow "Resource" objects 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
* Resource object.
*
* @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'], 'TYPO3\\Flow\\Resource\\Resource');
if ($resource === null) {
$this->outputLine('Warning: Resource 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: Resource 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()));
}
}
}
}
示例9: fetchObjectFromPersistence
/**
* 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;
}
示例10: fetchObjectFromPersistence
/**
* Fetch an object from persistence layer.
*
* @param mixed $identity
* @param string $targetType
* @return object
* @throws \TYPO3\Flow\Property\Exception\TargetNotFoundException
* @throws \TYPO3\Flow\Property\Exception\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 \TYPO3\Flow\Property\Exception\InvalidSourceException('The identity property "' . $identity . '" is neither a string nor an array.', 1297931020);
}
return $object;
}
示例11: fetchObjectFromPersistence
/**
* 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;
}
示例12: fetchObjectFromPersistence
/**
* Fetch an object from persistence layer.
*
* @param mixed $identity
* @param string $targetType
* @return object
* @throws \TYPO3\Flow\Property\Exception\TargetNotFoundException
* @throws \TYPO3\Flow\Property\Exception\InvalidSourceException
*/
protected function fetchObjectFromPersistence($identity, $targetType)
{
if ($targetType === 'TYPO3\\Media\\Domain\\Model\\Thumbnail') {
$object = $this->persistenceManager->getObjectByIdentifier($identity, $targetType);
} elseif (is_string($identity)) {
$object = $this->assetRepository->findByIdentifier($identity);
} else {
throw new \TYPO3\Flow\Property\Exception\InvalidSourceException('The identity property "' . $identity . '" is not a string.', 1415817618);
}
return $object;
}
示例13: decodeObjectReferences
/**
* 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']);
}
}
}
示例14: findByIdentifier
/**
* 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;
}
示例15: convertFrom
/**
* Converts the given string or array to a ResourcePointer object.
*
* If the input format is an array, this method assumes the resource to be a
* fresh file upload and imports the temporary upload file through the
* resource manager.
*
* @param array $source The upload info (expected keys: error, name, tmp_name)
* @param string $targetType
* @param array $convertedChildProperties
* @param \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration
* @return \TYPO3\Flow\Resource\Resource|TYPO3\Flow\Error\Error if the input format is not supported or could not be converted for other reasons
*/
public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration = NULL)
{
if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) {
if (isset($source['submittedFile']) && isset($source['submittedFile']['filename']) && isset($source['submittedFile']['resourcePointer'])) {
$resourcePointer = $this->persistenceManager->getObjectByIdentifier($source['submittedFile']['resourcePointer'], 'TYPO3\\Flow\\Resource\\ResourcePointer');
if ($resourcePointer) {
$resource = new Resource();
$resource->setFilename($source['submittedFile']['filename']);
$resource->setResourcePointer($resourcePointer);
return $resource;
}
}
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 \TYPO3\Flow\Error\Error(\TYPO3\Flow\Utility\Files::getUploadErrorMessage($source['error']), 1264440823);
default:
$this->systemLogger->log(sprintf('A server error occurred while converting an uploaded resource: "%s"', \TYPO3\Flow\Utility\Files::getUploadErrorMessage($source['error'])), LOG_ERR);
return new \TYPO3\Flow\Error\Error('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']];
}
$resource = $this->resourceManager->importUploadedResource($source);
if ($resource === FALSE) {
return new \TYPO3\Flow\Error\Error('The resource manager could not create a Resource instance.', 1264517906);
} else {
$this->convertedResources[$source['tmp_name']] = $resource;
return $resource;
}
}