isNewObject() public method

Checks if the given object has ever been persisted.
public isNewObject ( object $object ) : boolean
$object object The object to check
return boolean TRUE if the object is new, FALSE if the object exists in the repository
 /**
  * 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);
 }
 /**
  * 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);
     }
 }
 /**
  * @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 ['identifier' => $this->persistenceSession->getIdentifierByObject($object)];
     } else {
         return ['identifier' => $this->persistObject($object, $parentIdentifier)];
     }
 }
 /**
  * Checks if recently imported resources really have been persisted - and if not, removes its data from the
  * respective storage.
  *
  * @return void
  */
 public function shutdownObject()
 {
     /** @var PersistentResource $resource */
     foreach ($this->resourceRepository->getAddedResources() as $resource) {
         if ($this->persistenceManager->isNewObject($resource)) {
             $this->deleteResource($resource, false);
         }
     }
 }
 /**
  * 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));
 }
 /**
  * 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 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);
             }
         }
     }
 }
 /**
  * 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)];
         }
     }
 }
 /**
  * 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;
     }
 }
 /**
  * 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);
         }
     }
 }