本文整理汇总了PHP中TYPO3\Flow\Persistence\PersistenceManagerInterface::isNewObject方法的典型用法代码示例。如果您正苦于以下问题:PHP PersistenceManagerInterface::isNewObject方法的具体用法?PHP PersistenceManagerInterface::isNewObject怎么用?PHP PersistenceManagerInterface::isNewObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\Flow\Persistence\PersistenceManagerInterface
的用法示例。
在下文中一共展示了PersistenceManagerInterface::isNewObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderHiddenIdentityField
/**
* 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 \TYPO3\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);
}
示例2: uploadAssetAction
/**
* Upload a new image, and return its metadata.
*
* Depending on the $metadata argument it will return asset metadata for the AssetEditor
* or image metadata for the ImageEditor
*
* @param Asset $asset
* @param string $metadata Type of metadata to return ("Asset" or "Image")
* @return string
*/
public function uploadAssetAction(Asset $asset, $metadata)
{
$this->response->setHeader('Content-Type', 'application/json');
/** @var Site $currentSite */
$currentSite = $this->siteRepository->findOneByNodeName($this->request->getInternalArgument('__siteNodeName'));
if ($currentSite !== NULL && $currentSite->getAssetCollection() !== NULL) {
$currentSite->getAssetCollection()->addAsset($asset);
$this->assetCollectionRepository->update($currentSite->getAssetCollection());
}
switch ($metadata) {
case 'Asset':
$result = $this->getAssetProperties($asset);
if ($this->persistenceManager->isNewObject($asset)) {
$this->assetRepository->add($asset);
}
break;
case 'Image':
$result = $this->getImageInterfacePreviewData($asset);
if ($this->persistenceManager->isNewObject($asset)) {
$this->imageRepository->add($asset);
}
break;
default:
$this->response->setStatus(400);
$result = array('error' => 'Invalid "metadata" type: ' . $metadata);
}
return json_encode($result);
}
示例3: processObject
/**
* @param object $object
* @param string $parentIdentifier
* @return array
*/
protected function processObject($object, $parentIdentifier)
{
if (isset($this->classSchemata[get_class($object)]) && $this->classSchemata[get_class($object)]->isAggregateRoot() && !$this->persistenceManager->isNewObject($object)) {
return array('identifier' => $this->persistenceSession->getIdentifierByObject($object));
} else {
return array('identifier' => $this->persistObject($object, $parentIdentifier));
}
}
示例4: shutdownObject
/**
* Checks if recently imported resources really have been persisted - and if not, removes its data from the
* respective storage.
*
* @return void
*/
public function shutdownObject()
{
foreach ($this->resourceRepository->getAddedResources() as $resource) {
if ($this->persistenceManager->isNewObject($resource)) {
$this->deleteResource($resource, FALSE);
}
}
}
示例5: refreshThumbnail
/**
* Refreshes a thumbnail and persists the thumbnail
*
* @param Thumbnail $thumbnail
* @return void
*/
public function refreshThumbnail(Thumbnail $thumbnail)
{
$thumbnail->refresh();
$this->persistenceManager->whiteListObject($thumbnail);
if (!$this->persistenceManager->isNewObject($thumbnail)) {
$this->thumbnailRepository->update($thumbnail);
}
}
示例6: createImageVariantAction
/**
* Generate a new image variant from given data.
*
* @param ImageVariant $asset
* @return string
*/
public function createImageVariantAction(ImageVariant $asset)
{
if ($this->persistenceManager->isNewObject($asset)) {
$this->assetRepository->add($asset);
}
$propertyMappingConfiguration = new PropertyMappingConfiguration();
// This will not be sent as "application/json" as we need the JSON string and not the single variables.
return json_encode($this->entityToIdentityConverter->convertFrom($asset, 'array', [], $propertyMappingConfiguration));
}
示例7: persistEntities
/**
* 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);
}
}
}
}
示例8: encodeObjectReferences
/**
* 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_object($value) || is_object($value) && $value instanceof \TYPO3\Flow\Object\DependencyInjection\DependencyProxy) {
continue;
}
$propertyClassName = get_class($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, 'TYPO3\\Flow\\Annotations\\Entity') || $this->reflectionService->isClassAnnotatedWith($propertyClassName, 'TYPO3\\Flow\\Annotations\\ValueObject') || $this->reflectionService->isClassAnnotatedWith($propertyClassName, 'Doctrine\\ORM\\Mapping\\Entity'))) {
$value = array('__flow_object_type' => $propertyClassName, '__identifier' => $this->persistenceManager->getIdentifierByObject($value));
}
}
}
示例9: encodeObjectReferences
/**
* 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)];
}
}
}
示例10: getThumbnail
/**
* Returns a thumbnail of the given asset
*
* If the maximum width / height is not specified or exceeds the original asset's dimensions, the width / height of
* the original asset is used.
*
* @param AssetInterface $asset The asset to render a thumbnail for
* @param ThumbnailConfiguration $configuration
* @return Thumbnail
* @throws \Exception
*/
public function getThumbnail(AssetInterface $asset, ThumbnailConfiguration $configuration)
{
$assetIdentifier = $this->persistenceManager->getIdentifierByObject($asset);
$configurationHash = $configuration->getHash();
if (!isset($this->thumbnailCache[$assetIdentifier])) {
$this->thumbnailCache[$assetIdentifier] = [];
}
if (isset($this->thumbnailCache[$assetIdentifier][$configurationHash])) {
$thumbnail = $this->thumbnailCache[$assetIdentifier][$configurationHash];
} else {
$thumbnail = $this->thumbnailRepository->findOneByAssetAndThumbnailConfiguration($asset, $configuration);
$this->thumbnailCache[$assetIdentifier][$configurationHash] = $thumbnail;
}
$async = $configuration->isAsync();
if ($thumbnail === null) {
try {
$thumbnail = new Thumbnail($asset, $configuration, $async);
// If the thumbnail strategy failed to generate a valid thumbnail
if ($async === false && $thumbnail->getResource() === null && $thumbnail->getStaticResource() === null) {
$this->thumbnailRepository->remove($thumbnail);
return null;
}
if (!$this->persistenceManager->isNewObject($asset)) {
$this->thumbnailRepository->add($thumbnail);
}
$asset->addThumbnail($thumbnail);
// Allow thumbnails to be persisted even if this is a "safe" HTTP request:
$this->persistenceManager->whiteListObject($thumbnail);
$this->thumbnailCache[$assetIdentifier][$configurationHash] = $thumbnail;
} catch (NoThumbnailAvailableException $exception) {
$this->systemLogger->logException($exception);
return null;
}
$this->persistenceManager->whiteListObject($thumbnail);
$this->thumbnailCache[$assetIdentifier][$configurationHash] = $thumbnail;
} elseif ($thumbnail->getResource() === null && $async === false) {
$this->refreshThumbnail($thumbnail);
}
return $thumbnail;
}
示例11: importNodeProperty
/**
* Sets the given $nodePropertyXml on the $node instance
*
* @param \SimpleXMLElement $nodePropertyXml
* @param NodeInterface $node
* @return void
*/
protected function importNodeProperty(\SimpleXMLElement $nodePropertyXml, NodeInterface $node)
{
if (!isset($nodePropertyXml['__type'])) {
$node->setProperty($nodePropertyXml->getName(), (string) $nodePropertyXml);
return;
}
switch ($nodePropertyXml['__type']) {
case 'boolean':
$node->setProperty($nodePropertyXml->getName(), (string) $nodePropertyXml === '1');
break;
case 'reference':
$targetIdentifier = (string) $nodePropertyXml->node['identifier'] === '' ? null : (string) $nodePropertyXml->node['identifier'];
$node->setProperty($nodePropertyXml->getName(), $targetIdentifier);
break;
case 'references':
$referencedNodeIdentifiers = array();
foreach ($nodePropertyXml->node as $referenceNodeXml) {
if ((string) $referenceNodeXml['identifier'] !== '') {
$referencedNodeIdentifiers[] = (string) $referenceNodeXml['identifier'];
}
}
$node->setProperty($nodePropertyXml->getName(), $referencedNodeIdentifiers);
break;
case 'array':
$entries = array();
foreach ($nodePropertyXml->children() as $childNodeXml) {
$entry = null;
if (!isset($childNodeXml['__classname']) || !in_array($childNodeXml['__classname'], array('TYPO3\\Media\\Domain\\Model\\Image', 'TYPO3\\Media\\Domain\\Model\\Asset'))) {
// Only arrays of asset objects are supported now
continue;
}
$entryClassName = (string) $childNodeXml['__classname'];
if (isset($childNodeXml['__identifier'])) {
if ($entryClassName === 'TYPO3\\Media\\Domain\\Model\\Image') {
$entry = $this->imageRepository->findByIdentifier((string) $childNodeXml['__identifier']);
} else {
$entry = $this->assetRepository->findByIdentifier((string) $childNodeXml['__identifier']);
}
}
if ($entry === null) {
$resourceXml = $childNodeXml->xpath('resource');
$resourceHash = $resourceXml[0]->xpath('hash');
$content = $resourceXml[0]->xpath('content');
$filename = $resourceXml[0]->xpath('filename');
$resource = $this->importResource(!empty($filename) ? (string) $filename[0] : null, !empty($resourceHash) ? (string) $resourceHash[0] : null, !empty($content) ? (string) $content[0] : null, isset($resourceXml[0]['__identifier']) ? (string) $resourceXml[0]['__identifier'] : null);
$entry = new $entryClassName($resource);
if (isset($childNodeXml['__identifier'])) {
ObjectAccess::setProperty($entry, 'Persistence_Object_Identifier', (string) $childNodeXml['__identifier'], true);
}
}
$propertiesXml = $childNodeXml->xpath('properties/*');
foreach ($propertiesXml as $propertyXml) {
if (!isset($propertyXml['__type'])) {
ObjectAccess::setProperty($entry, $propertyXml->getName(), (string) $propertyXml);
continue;
}
switch ($propertyXml['__type']) {
case 'boolean':
ObjectAccess::setProperty($entry, $propertyXml->getName(), (bool) $propertyXml);
break;
case 'string':
ObjectAccess::setProperty($entry, $propertyXml->getName(), (string) $propertyXml);
break;
case 'object':
ObjectAccess::setProperty($entry, $propertyXml->getName(), $this->xmlToObject($propertyXml));
}
}
/**
* During the persist Doctrine calls the serialize() method on the asset for the ObjectArray
* object, during this serialize the resource property gets lost.
* The AssetList node type has a custom implementation to work around this bug.
* @see NEOS-121
*/
$repositoryAction = $this->persistenceManager->isNewObject($entry) ? 'add' : 'update';
if ($entry instanceof Image) {
$this->imageRepository->{$repositoryAction}($entry);
} else {
$this->assetRepository->{$repositoryAction}($entry);
}
$entries[] = $entry;
}
$node->setProperty($nodePropertyXml->getName(), $entries);
break;
case 'object':
$node->setProperty($nodePropertyXml->getName(), $this->xmlToObject($nodePropertyXml));
break;
}
}
示例12: persistRelatedEntities
/**
* 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);
}
}
}
示例13: treatAction
/**
* @param \DLigo\Animaltool\Domain\Model\Animal $animal
* @param array $treatment
* @param string $tag
* @param string $passId
* @param string $contunue
* @param string $release
* @param string $extern
* @param string $newextern
* @param string $dead
* @param string $origRFID
* @param string $origEarTag
* @Flow\Validate (argumentName="$treatment", type="\DLigo\Animaltool\Validation\Validator\TreatmentValidator")
* @Flow\Validate (argumentName="$animal.healthCondition",type="NotEmpty")
* @Flow\Validate (argumentName="$animal.photo", type="NotEmpty")
* @return void
*/
public function treatAction(Animal $animal, $treatment, $tag = '', $passId = '', $continue = null, $release = null, $extern = null, $newextern = null, $dead = null, $origRFID = '', $origEarTag = '')
{
$duplicate = false;
// \TYPO3\Flow\var_dump($this->request);
$done = false;
$mergeMessage = '';
$merge = '';
$tr = $animal->getOpenTreatment();
if (!$tr) {
$tr = new \DLigo\Animaltool\Domain\Model\Treatment();
$tr->setStartDate(new \DateTime('now'));
$tr->setAnimal($animal);
// $tr->setDoctor($this->session->getUser());
$animal->getTreatments()->add($tr);
}
$did = isset($treatment['doctor']['__identity']) ? $treatment['doctor']['__identity'] : $treatment['doctor'];
$tr->setDoctor($this->userRepository->findByIdentifier($did));
$therapies = new \Doctrine\Common\Collections\ArrayCollection();
$extras = new \Doctrine\Common\Collections\ArrayCollection();
if (is_array($treatment['therapies'])) {
foreach ($treatment['therapies'] as $thid) {
$therapy = $this->therapyRepository->findByIdentifier($thid);
if ($therapy->getHasExtraData()) {
$extra = $this->treatmentExtraRepository->findByTherapyAndTreatment($thid, $tr)->getFirst();
if (!$extra) {
$extra = new \DLigo\Animaltool\Domain\Model\TreatmentExtra();
$extra->setTreatment($tr);
$extra->setTherapy($therapy);
}
$extra->setValue($treatment['treatmentExtra'][$thid]);
unset($treatment['treatmentExtra'][$thid]);
$extras->add($extra);
}
$therapies->add($therapy);
}
}
$tr->setTherapies($therapies);
$tr->setTreatmentExtras($extras);
$tr->setComment($treatment['comment']);
if ($this->persistenceManager->isNewObject($tr)) {
$this->treatmentRepository->add($tr);
} else {
$this->treatmentRepository->update($tr);
}
if (isset($treatment['treatmentExtra']) && is_array($treatment['treatmentExtra'])) {
foreach ($treatment['treatmentExtra'] as $thid => $value) {
$extra = $this->treatmentExtraRepository->findByTherapyAndTreatment($thid, $tr)->getFirst();
if ($extra != null) {
$this->treatmentExtraRepository->remove($extra);
}
}
}
if ($continue) {
$animal->setStayStatus(Animal::THERAPY);
$animal->setTherapyStatus(Animal::OPERATION);
$animal->stopOpenExternals();
$animal->stopOpenTreatments();
} elseif ($release) {
$animal->setStayStatus(Animal::RELEASING);
$animal->setTherapyStatus(Animal::READY);
$animal->stopOpenExternals();
$animal->stopOpenTreatments();
$animal->getLastAction()->setReleaseDate(new \DateTime('now'));
} elseif ($extern) {
if ($animal->getStayStatus() == Animal::CATCHED) {
$animal->setStayStatus(Animal::THERAPY);
}
if ($animal->getTherapyStatus() == Animal::WAIT) {
$animal->setTherapyStatus(Animal::OPERATION);
}
$animal->stopOpenTreatments();
} elseif ($newextern) {
$animal->stopOpenExternals();
$animal->stopOpenTreatments();
} elseif ($dead) {
$animal->setStayStatus(Animal::RELEASED);
$animal->setTherapyStatus(Animal::DEAD);
$animal->stopOpenExternals();
$animal->stopOpenTreatments();
}
$oldAnimal = null;
if ($animal->getIsPrivate()) {
$animal->setRFID($tag);
//.........这里部分代码省略.........
示例14: serializeObjectAsPropertyArray
/**
* 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 = array();
foreach ($this->reflectionService->getClassPropertyNames($className) as $propertyName) {
if ($this->reflectionService->isPropertyTaggedWith($className, $propertyName, 'transient')) {
continue;
}
$propertyReflection = new \TYPO3\Flow\Reflection\PropertyReflection($className, $propertyName);
$propertyValue = $propertyReflection->getValue($object);
if (is_object($propertyValue) && $propertyValue instanceof \TYPO3\Flow\Object\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] = array();
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, \TYPO3\Flow\Annotations\Entity::class) || $this->reflectionService->isClassAnnotatedWith($propertyClassName, \TYPO3\Flow\Annotations\ValueObject::class) || $this->reflectionService->isClassAnnotatedWith($propertyClassName, 'Doctrine\\ORM\\Mapping\\Entity'))) {
$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) === \TYPO3\Flow\Object\Configuration\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)] = array(self::CLASSNAME => $className, self::PROPERTIES => $propertyArray);
if ($isTopLevelItem) {
return $this->objectsAsArray;
}
}
示例15: assertUnpersisted
public function assertUnpersisted($entity)
{
$this->test->assertTrue($this->persistenceManager->isNewObject($entity), 'The Entity of type ' . get_class($entity) . ' is still persisted.');
return $this;
}