Neos\Flow\Persistence\Generic\Session::getIdentifierByObject PHP Method

getIdentifierByObject() public method

Note: this returns an UUID 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 ) : string
$object object
return string
    public function getIdentifierByObject($object)
    {
        if ($this->hasObject($object)) {
            return $this->objectMap[$object];
        }
        $idPropertyNames = $this->reflectionService->getPropertyNamesByTag(get_class($object), 'id');
        if (count($idPropertyNames) === 1) {
            $idPropertyName = $idPropertyNames[0];
            return ObjectAccess::getProperty($object, $idPropertyName, true);
        } elseif (property_exists($object, 'Persistence_Object_Identifier')) {
            return ObjectAccess::getProperty($object, 'Persistence_Object_Identifier', true);
        }
        return null;
    }

Usage Example

 /**
  * Checks whether the given object is contained in the array. This checks
  * for object identity in terms of the persistence layer, i.e. the UUID,
  * when comparing entities.
  *
  * @param array $array
  * @param object $object
  * @param string $identifier
  * @return boolean
  */
 protected function arrayContainsObject(array $array, $object, $identifier)
 {
     if (in_array($object, $array, true) === true) {
         return true;
     }
     foreach ($array as $value) {
         if ($value instanceof $object && $this->persistenceSession->getIdentifierByObject($value) === $identifier) {
             return true;
         }
     }
     return false;
 }
All Usage Examples Of Neos\Flow\Persistence\Generic\Session::getIdentifierByObject