/**
  * @param string $guid
  * @return bool
  */
 public static function isValid($guid)
 {
     if (!Uuid::isValid($guid) || !preg_match('/' . self::UUID4_PATTERN . '/', $guid)) {
         return false;
     }
     return true;
 }
 /**
  * @param string $value
  */
 public function __construct(string $value)
 {
     if (!\Ramsey\Uuid\Uuid::isValid($value)) {
         throw new \InvalidArgumentException(sprintf('%s is not a valid Uuid.', $value));
     }
     $this->value = \Ramsey\Uuid\Uuid::fromString($value);
 }
 /**
  * @param string $uuidString
  * @return \Ramsey\Uuid\UuidInterface
  */
 private function deserializeUuidValue($uuidString)
 {
     if (!Uuid::isValid($uuidString)) {
         throw new \Mhujer\JmsSerializer\Uuid\InvalidUuidException($uuidString);
     }
     return Uuid::fromString($uuidString);
 }
Beispiel #4
0
 /**
  * @covers Alchemy\Phrasea\Border\File::getUUID
  */
 public function testNewUuid()
 {
     $file = __DIR__ . '/../../../../files/temporay.jpg';
     if (file_exists($file)) {
         unlink($file);
     }
     copy(__DIR__ . '/../../../../files/p4logo.jpg', $file);
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $uuid = $borderFile->getUUID(true, false);
     $this->assertTrue(Uuid::isValid($uuid));
     $this->assertEquals($uuid, $borderFile->getUUID());
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $newuuid = $borderFile->getUUID(true, true);
     $this->assertTrue(Uuid::isValid($newuuid));
     $this->assertNotEquals($uuid, $newuuid);
     $this->assertEquals($newuuid, $borderFile->getUUID());
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $uuid = $borderFile->getUUID();
     $this->assertTrue(Uuid::isValid($uuid));
     $this->assertEquals($uuid, $newuuid);
     $this->assertEquals($uuid, $borderFile->getUUID());
     if (file_exists($file)) {
         unlink($file);
     }
 }
Beispiel #5
0
 /**
  * @param string $entity_id
  */
 public function __construct($entity_id = null)
 {
     if (is_null($entity_id) || false === Uuid::isValid($entity_id)) {
         $entity_id = Uuid::uuid4();
     }
     $this->entity_id = $entity_id;
 }
Beispiel #6
0
 public function testGenerate()
 {
     $id = UuidIdentifier::generate();
     $this->assertTrue(Uuid::isValid($id));
     $uuid = Uuid::fromString($id->toString());
     $this->assertTrue($uuid->getVersion() == 4);
 }
Beispiel #7
0
 public static function fromString(string $uuid)
 {
     if (!Uuid::isValid($uuid)) {
         throw new \InvalidArgumentException(sprintf('%s is not valid uuid', $uuid));
     }
     return new Id(Uuid::fromString($uuid)->toString());
 }
 /**
  * @param string $string
  *
  * @throws OrmException
  *
  * @return $this
  */
 public function setUuidFromString($string)
 {
     if (!Uuid::isValid($string)) {
         throw OrmException::create()->setMessage('Invalid Uuid string provided.');
     }
     $this->uuid = Uuid::fromString($string);
     return $this;
 }
Beispiel #9
0
 public function getMatchers()
 {
     return ['beValidUUID' => function ($uuid) {
         return Uuid::isValid($uuid);
     }, 'beEqualUUID' => function ($uuid, $value) {
         return Uuid::fromString($uuid)->equals(Uuid::fromString($uuid));
     }];
 }
Beispiel #10
0
 /**
  * {@inheritDoc}
  */
 public function isValid($value)
 {
     if (!UuidImpl::isValid($value)) {
         $this->error(self::INVALID_UUID);
         return false;
     }
     $this->setValue($value);
     return true;
 }
Beispiel #11
0
 /**
  * {@inheritdoc}
  */
 public function getAccessToken($grant, array $options = [])
 {
     if (!isset($options['guid']) || !Uuid::isValid($options['guid'])) {
         throw new \RuntimeException(sprintf('%s requires a "guid" option with a valid v4 UUID.', __METHOD__));
     }
     // Temporarily fake an access token for Local provider.
     $defaultOptions = ['access_token' => Uuid::uuid4()->toString(), 'resource_owner_id' => $options['guid'], 'refresh_token' => Uuid::uuid4()->toString(), 'expires' => 86400];
     return new AccessToken(array_merge($defaultOptions, $options));
 }
 /**
  * {@inheritdoc}
  *
  * @param mixed            $value
  * @param AbstractPlatform $platform
  *
  * @throws ConversionException
  *
  * @return null|string
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return null;
     }
     if ($value instanceof Uuid || Uuid::isValid($value)) {
         return (string) $value;
     }
     throw OrmTypeConversionException::create()->with($value, self::NAME);
 }
 /**
  * {@inheritdoc}
  *
  * @param Uuid|null                                 $value
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return null;
     }
     if ($value instanceof Uuid || Uuid::isValid($value)) {
         return $value->getBytes();
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
 /**
  * Converts a value from its PHP representation to its database representation of this type.
  *
  * @param mixed $value The value to convert.
  *
  * @return string
  */
 public function convertToDatabaseValue($value)
 {
     if (null === $value) {
         return null;
     }
     if ($value instanceof Uuid || Uuid::isValid($value)) {
         return (string) $value;
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
Beispiel #15
0
 /**
  * {@inheritDoc}
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!Uuid::isValid($input->getArgument('uuid'))) {
         throw new Exception('Invalid UUID (' . $input->getArgument('uuid') . ')');
     }
     $uuid = Uuid::fromString($input->getArgument('uuid'));
     $table = $this->createTable($output);
     $this->setTableLayout($table);
     (new UuidFormatter())->write($table, $uuid);
     $table->render($output);
 }
Beispiel #16
0
 protected function extractComponents($encodedUuid)
 {
     $nameParsed = str_replace(array('urn:', 'uuid:', '{', '}', '-'), '', $encodedUuid);
     // We have stripped out the dashes and are breaking up the string using
     // substr(). In this way, we can accept a full hex value that doesn't
     // contain dashes.
     $components = array(substr($nameParsed, 0, 8), substr($nameParsed, 8, 4), substr($nameParsed, 12, 4), substr($nameParsed, 16, 4), substr($nameParsed, 20));
     $nameParsed = implode('-', $components);
     if (!Uuid::isValid($nameParsed)) {
         throw new InvalidArgumentException('Invalid UUID string: ' . $encodedUuid);
     }
     return $components;
 }
Beispiel #17
0
 /**
  * Generates a v5 UUID.
  *
  * @param string $str
  *   The word to generate the UUID with.
  * @param string $namespace
  *   A namespace
  * @return String   Valid v5 UUID.
  */
 public function generateV5($str, $namespace = NULL)
 {
     // Use default namespace if none is provided.
     if (!empty($namespace)) {
         // Is this a UUID already?
         if (Uuid::isValid($namespace)) {
             return Uuid::uuid5($namespace, $str)->toString();
         } else {
             return Uuid::uuid5(Uuid::uuid5(Uuid::NAMESPACE_DNS, $namespace), $str)->toString();
         }
     } else {
         return Uuid::uuid5($this->namespace, $str)->toString();
     }
 }
Beispiel #18
0
 /**
  * @covers ::__construct
  */
 public function testConstructNoId()
 {
     /**
      * @var Entity $entityMock
      */
     $entityMock = $this->getMockBuilder(Entity::class)->disableOriginalConstructor()->getMockForAbstractClass();
     $modified = new \DateTime();
     $created = new \DateTime();
     $constructor = (new \ReflectionClass(Entity::class))->getConstructor();
     $constructor->invoke($entityMock, null, $modified, $created);
     $this->assertTrue(Uuid::isValid($entityMock->get('id')));
     $this->assertSame($modified, $entityMock->get('modified'));
     $this->assertSame($created, $entityMock->get('created'));
 }
Beispiel #19
0
 /**
  * {@inheritdoc}
  */
 public function isValid($value)
 {
     $this->resetMessages();
     $this->value = $value;
     if (!is_string($value)) {
         $this->addMessage();
         return false;
     }
     if (!UuidImpl::isValid($value)) {
         $this->addMessage();
         return false;
     }
     return true;
 }
Beispiel #20
0
 /**
  * Constructor.
  *
  * @param string                 $guid
  * @param string                 $providerName
  * @param AccessToken            $accessToken
  * @param ResourceOwnerInterface $resourceOwner
  */
 public function __construct($guid, $providerName, AccessToken $accessToken, ResourceOwnerInterface $resourceOwner)
 {
     if (Uuid::isValid($guid) === false) {
         throw new \RuntimeException('Tried to create Transition object with an invalid GUID.');
     }
     $this->guid = $guid;
     $this->accessToken = $accessToken;
     $this->resourceOwner = $resourceOwner;
     $providerEntity = new Entity\Provider();
     $providerEntity->setProvider($providerName);
     $providerEntity->setRefreshToken($accessToken->getRefreshToken());
     $providerEntity->setResourceOwnerId($resourceOwner->getId());
     $providerEntity->setResourceOwner($resourceOwner);
     $this->providerEntity = $providerEntity;
 }
Beispiel #21
0
 /**
  * Method returns models geted by uuid
  * @param  Builder $query
  * @param  array|tring $uuid  uuid or list of uuids
  * @return Collection|Model Single model or collection of models
  */
 public function scopeFindByUuid($query, $uuid)
 {
     if (!is_array($uuid)) {
         if (!Uuid::isValid($uuid)) {
             throw (new ModelNotFoundException())->setModel(get_class($this));
         }
         return $query->where('uuid', $uuid)->first();
     } elseif (is_array($uuid)) {
         array_map(function ($element) {
             if (!Uuid::isValid($element)) {
                 throw (new ModelNotFoundException())->setModel(get_class($this));
             }
         }, $uuid);
         return $query->whereIn('uuid', $uuid)->get();
     }
 }
 /**
  * Converts a value from its PHP representation to its database representation of this type.
  *
  * @param mixed $value The value to convert.
  *
  * @return MongoBinData
  */
 public function convertToDatabaseValue($value)
 {
     if (null === $value) {
         return null;
     }
     if ($value instanceof MongoBinData) {
         return new MongoBinData($value->bin, MongoBinData::UUID_RFC4122);
     }
     if (is_string($value) && Uuid::isValid($value)) {
         $value = Uuid::fromString($value);
     }
     if ($value instanceof Uuid) {
         return new MongoBinData($value->getBytes(), MongoBinData::UUID_RFC4122);
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
 /**
  * {@inheritdoc}
  *
  * @param mixed            $value
  * @param AbstractPlatform $platform
  *
  * @throws ConversionException
  *
  * @return null|string
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return null;
     }
     if ($value instanceof Uuid) {
         return $value->getBytes();
     }
     if (Uuid::isValid($value)) {
         return Uuid::fromString($value)->getBytes();
     }
     try {
         return Uuid::fromBytes($value)->getBytes();
     } catch (\InvalidArgumentException $exception) {
         throw OrmTypeConversionException::create()->with($value, self::NAME);
     }
 }
 public function getMatchers()
 {
     return ['havePublished' => function ($user, $eventClass) {
         $publishedEvents = count(array_filter(AllEventsSubscriber::publishedEvents(), function ($event) use($eventClass) {
             return $eventClass === get_class($event);
         }));
         $recordedEvents = count(array_filter($user->uncommitedEvents(), function ($event) use($eventClass) {
             return $eventClass === get_class($event);
         }));
         return $publishedEvents > 0 && $recordedEvents > 0;
     }, 'haveAValidUserId' => function ($user) {
         return $user->id() instanceof UserId && Uuid::isValid($user->id());
     }, 'havePoints' => function ($user, $expectedNumberOfPoints) {
         return $expectedNumberOfPoints === array_reduce(AllEventsSubscriber::publishedEvents(), function ($total, $event) {
             if ($event instanceof UserEarnedPoints) {
                 $total += $event->earnedPoints();
             }
             return $total;
         }, 0);
     }];
 }
 /**
  * Display a listing of the resource.
  *
  * @param null|string $query
  *
  * @return \Quoterr\Http\Controllers\Response
  * @internal param \Illuminate\Http\Request $request
  *
  */
 public function index($query = null)
 {
     $quote = null;
     $meta = ['title' => 'Quoterr', 'description' => "Quoterr.me is an experience."];
     $api = '/api/quotes?random=1';
     if ($query !== null) {
         if (Uuid::isValid($query)) {
             $type = 'Press ‘space’ for next Quote';
             flash('Copy link from address bar to share this quote.');
             $quote = Quote::with('author')->whereUuid($query)->first();
             $meta['title'] = "A quote by {$quote->author->name} on Quoterr";
             $meta['description'] = "{$quote->content} Read awesome quotes on Quoterr.";
         } else {
             $author = Author::whereSlug($query)->first();
             if ($author) {
                 $type = "Showing quotes by {$author->name}";
                 $quote = $author->quotes()->published()->orderByRandom()->first();
                 $api = '/api/author?id=' . $query;
                 $meta['title'] = "Quotes by {$quote->author->name} on Quoterr";
                 $meta['description'] = "A fine quotation is a diamond in the hand of a man of wit, and a pebble in the hand of a fool. Read awesome quotes on Quoterr.";
             } else {
                 $tag = Tag::whereSlug($query)->first();
                 if ($tag) {
                     $type = "Quotes in {$tag->name} category";
                     $quote = $tag->quotes()->published()->orderByRandom()->first();
                     $api = '/api/tag?id=' . $query;
                 }
             }
         }
     }
     if (!$quote) {
         $type = 'Press ‘space’ for next Quote';
         $quote = Quote::with('author')->published()->orderByRandom()->first();
     }
     return view('welcome', compact('quote', 'api', 'type', 'meta'));
 }
 /**
  * Delete a file from Gringotts.
  *
  * @param string $uuid The file uuid
  * @throws InvalidUuidException
  * @throws UnableToDeleteFileException
  */
 public function delete($uuid)
 {
     try {
         if (!Uuid::isValid($uuid)) {
             throw new InvalidUuidException($uuid);
         }
         $response = $this->client->request('DELETE', "/{$uuid}");
         if ($response->getStatusCode() != 200) {
             throw new UnableToDeleteFileException(Uuid::fromString($uuid));
         }
     } catch (TransferException $e) {
         throw new UnableToDeleteFileException(Uuid::fromString($uuid), $e);
     }
 }
Beispiel #27
0
 protected function evaluateGoodStory($story)
 {
     $this->assertArrayHasKey('databox_id', $story);
     $this->assertTrue(is_int($story['databox_id']));
     $this->assertArrayHasKey('story_id', $story);
     $this->assertTrue(is_int($story['story_id']));
     $this->assertArrayHasKey('updated_on', $story);
     $this->assertDateAtom($story['updated_on']);
     $this->assertArrayHasKey('created_on', $story);
     $this->assertDateAtom($story['created_on']);
     $this->assertArrayHasKey('collection_id', $story);
     $this->assertTrue(is_int($story['collection_id']));
     $this->assertArrayHasKey('thumbnail', $story);
     $this->assertArrayHasKey('uuid', $story);
     $this->assertArrayHasKey('@entity@', $story);
     $this->assertEquals(V1Controller::OBJECT_TYPE_STORY, $story['@entity@']);
     $this->assertTrue(Uuid::isValid($story['uuid']));
     if (!is_null($story['thumbnail'])) {
         $this->assertTrue(is_array($story['thumbnail']));
         $this->assertArrayHasKey('player_type', $story['thumbnail']);
         $this->assertTrue(is_string($story['thumbnail']['player_type']));
         $this->assertArrayHasKey('permalink', $story['thumbnail']);
         $this->assertArrayHasKey('mime_type', $story['thumbnail']);
         $this->assertTrue(is_string($story['thumbnail']['mime_type']));
         $this->assertArrayHasKey('height', $story['thumbnail']);
         $this->assertTrue(is_int($story['thumbnail']['height']));
         $this->assertArrayHasKey('width', $story['thumbnail']);
         $this->assertTrue(is_int($story['thumbnail']['width']));
         $this->assertArrayHasKey('filesize', $story['thumbnail']);
         $this->assertTrue(is_int($story['thumbnail']['filesize']));
     }
     $this->assertArrayHasKey('records', $story);
     $this->assertInternalType('array', $story['records']);
     foreach ($story['metadatas'] as $key => $metadata) {
         if (null !== $metadata) {
             $this->assertInternalType('string', $metadata);
         }
         if ($key === '@entity@') {
             continue;
         }
         $this->assertEquals(0, strpos($key, 'dc:'));
     }
     $this->assertArrayHasKey('@entity@', $story['metadatas']);
     $this->assertEquals(V1Controller::OBJECT_TYPE_STORY_METADATA_BAG, $story['metadatas']['@entity@']);
     foreach ($story['records'] as $record) {
         $this->evaluateGoodRecord($record);
     }
 }
Beispiel #28
0
 /**
  * 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
  */
 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'];
     if (!$this->uuid) {
         $metadatas = $this->media->getMetadatas();
         $uuid = null;
         foreach ($availableUUIDs as $meta) {
             if ($metadatas->containsKey($meta)) {
                 $candidate = $metadatas->get($meta)->getValue()->asString();
                 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));
         }
         /**
          * PHPExiftool throws exception on some files not supported
          */
         try {
             $this->app['exiftool.writer']->reset();
             $this->app['exiftool.writer']->write($this->getFile()->getRealPath(), $metadatas);
         } catch (PHPExiftoolException $e) {
         }
     }
     return $this->uuid;
 }
 public function testGenerate()
 {
     $factory = new DefaultIdentifierFactory();
     $this->assertTrue(Uuid::isValid($factory->generateIdentifier()));
 }
Beispiel #30
0
 /**
  * @param string $guid Member GUID.
  *
  * @return Profile
  */
 private function getEntityProfile($guid = null)
 {
     if ($guid !== null && !Uuid::isValid($guid)) {
         throw new \RuntimeException(sprintf('Invalid GUID value "%s" given.', $guid));
     }
     $account = $this->records->getAccountByGuid($guid);
     $profile = $account ? new Profile($account->toArray()) : new Profile([]);
     $accountMeta = $this->records->getAccountMetaAll($guid);
     if ($accountMeta === false) {
         return $profile;
     }
     /** @var Storage\Entity\AccountMeta $metaEntity */
     foreach ((array) $accountMeta as $metaEntity) {
         if ($profile->has($metaEntity->getMeta())) {
             // Meta shouldn't override
             continue;
         }
         $profile[$metaEntity->getMeta()] = $metaEntity->getValue();
     }
     return $profile;
 }