public function getUUID($generate = false, $write = false)
    {
        if ($this->uuid && !$write) {
            return $this->uuid;
        }

        $availableUUIDs = [
            'XMP-exif:ImageUniqueID',
            'SigmaRaw:ImageUniqueID',
            'IPTC:UniqueDocumentID',
            'ExifIFD:ImageUniqueID',
            'Canon:ImageUniqueID',
            'XMP-xmpMM:DocumentID',
        ];

        if (!$this->uuid) {
            $metadatas = $this->media->getMetadatas();

            $uuid = null;

            foreach ($availableUUIDs as $meta) {
                if ($metadatas->containsKey($meta)) {
                    $candidate = $metadatas->get($meta)->getValue()->asString();
                    if(in_array($meta, self::$xmpTag)){
                        $candidate = self::sanitizeXmpUuid($candidate);
                    }
                    if (Uuid::isValid($candidate)) {
                        $uuid = $candidate;
                        break;
                    }
                }
            }

            if (!$uuid && $generate) {
                $uuid = Uuid::uuid4();
            }

            $this->uuid = $uuid;
        }

        if ($write) {
            $value = new MonoValue($this->uuid);
            $metadatas = new ExiftoolMetadataBag();

            foreach ($availableUUIDs as $tagname) {
                $metadatas->add(new Metadata(TagFactory::getFromRDFTagname($tagname), $value));
            }

            try {
                $writer = $this->app['exiftool.writer'];
                $writer->reset();
                $writer->write($this->getFile()->getRealPath(), $metadatas);
            } catch (PHPExiftoolException $e) {
                // PHPExiftool throws exception on some files not supported
            }
        }

        return $this->uuid;
    }
public function getUUID($generate = false, $write = false)
    {
        if ($this->uuid && !$write) {
            return $this->uuid;
        }

        $availableUUIDs = [
            'XMP-exif:ImageUniqueID',
            'SigmaRaw:ImageUniqueID',
            'IPTC:UniqueDocumentID',
            'ExifIFD:ImageUniqueID',
            'Canon:ImageUniqueID',
            'XMP-xmpMM:DocumentID',
        ];

        if (!$this->uuid) {
            $metadatas = $this->media->getMetadatas();

            $uuid = null;

            foreach ($availableUUIDs as $meta) {
                if ($metadatas->containsKey($meta)) {
                    $candidate = $metadatas->get($meta)->getValue()->asString();
                    if(in_array($meta, self::$xmpTag)){
                        $candidate = self::sanitizeXmpUuid($candidate);
                    }
                    if (Uuid::isValid($candidate)) {
                        $uuid = $candidate;
                        break;
                    }
                }
            }

            if (!$uuid && $generate) {
                $uuid = Uuid::uuid4();
            }

            $this->uuid = $uuid;
        }

        if ($write) {
            $value = new MonoValue($this->uuid);
            $metadatas = new ExiftoolMetadataBag();

            foreach ($availableUUIDs as $tagname) {
                $metadatas->add(new Metadata(TagFactory::getFromRDFTagname($tagname), $value));
            }

            try {
                $writer = $this->app['exiftool.writer'];
                $writer->reset();
                $writer->write($this->getFile()->getRealPath(), $metadatas);
            } catch (PHPExiftoolException $e) {
                // PHPExiftool throws exception on some files not supported
            }
        }

        return $this->uuid;
    }
public function getUUID ( $ generate = false , $ write = false ) { if ( $ this -> uuid && ! $ write ) { return $ this -> uuid ; } $ availableUUIDs = [ 'XMP-exif:ImageUniqueID' , 'SigmaRaw:ImageUniqueID' , 'IPTC:UniqueDocumentID' , 'ExifIFD:ImageUniqueID' , 'Canon:ImageUniqueID' , 'XMP-xmpMM:DocumentID' , ] ; if ( ! $ this -> uuid ) { $ metadatas = $ this -> media -> getMetadatas ( ) ; $ uuid = null ; foreach ( $ availableUUIDs as $ meta ) { if ( $ metadatas -> containsKey ( $ meta ) ) { $ candidate = $ metadatas -> get ( $ meta ) -> getValue ( ) -> asString ( ) ; if ( in_array ( $ meta , self :: $ xmpTag ) ) { $ candidate = self :: sanitizeXmpUuid ( $ candidate ) ; } if ( Uuid :: isValid ( $ candidate ) ) { $ uuid = $ candidate ; break ; } } } if ( ! $ uuid && $ generate ) { $ uuid = Uuid :: uuid4 ( ) ; } $ this -> uuid = $ uuid ; } if ( $ write ) { $ value = new MonoValue ( $ this -> uuid ) ; $ metadatas = new ExiftoolMetadataBag ( ) ; foreach ( $ availableUUIDs as $ tagname ) { $ metadatas -> add ( new Metadata ( TagFactory :: getFromRDFTagname ( $ tagname ) , $ value ) ) ; } try { $ writer = $ this -> app [ 'exiftool.writer' ] ; $ writer -> reset ( ) ; $ writer -> write ( $ this -> getFile ( ) -> getRealPath ( ) , $ metadatas ) ; } catch ( PHPExiftoolException $ e ) { // PHPExiftool throws exception on some files not supported } } return $ this -> uuid ; }
Checks for UUID in metadatas

@todo Check if a file exists with the same checksum
@todo Check if an UUID is contained in the attributes, replace It if
necessary

@param  boolean $generate if true, if no uuid found, a valid one is generated
@param  boolean $write    if true, writes uuid in all available metadatas
@return File
Checks for UUID in metadatas