Example #1
0
 /**
  * mutator method for trailUuid
  * @param string $newTrailUuid value given for trail submissions
  * @throws InvalidArgumentException if $newTrailUuid is not a string or insecure
  * @throws RangeException If $newTrailUuid is not equal to 22 characters
  **/
 public function setTrailUuid($newTrailUuid)
 {
     // base case if trail uuid is null, this is a new trail submission
     if ($newTrailUuid === null) {
         $this->trailUuid = null;
         return;
     }
     // base case if a new UUID is requested, make one
     if ($newTrailUuid === "CREATE-NEW-UUID") {
         $this->trailUuid = ShortUuid::uuid4();
         return;
     }
     // verify the trail UUID is valid $newTrailUuid = trim($newTrailUuid);
     $newTrailUuid = trim($newTrailUuid);
     $newTrailUuid = filter_var($newTrailUuid, FILTER_SANITIZE_STRING);
     if ($newTrailUuid === false) {
         throw new InvalidArgumentException("uuid is empty of insecure");
     }
     if (strlen($newTrailUuid) === 36) {
         // encode trail uuid to short form
         $uuid = Uuid::fromString($newTrailUuid);
         $shortUuid = new ShortUuid();
         $this->trailUuid = $shortUuid->encode($uuid);
     } else {
         if (strlen($newTrailUuid) === 22) {
             $this->trailUuid = $newTrailUuid;
         } else {
             // throw an Range Exception
             throw new RangeException("trail uuid is not the correct length for the data base");
         }
     }
 }
Example #2
0
 /**
  * @test
  */
 public function it_should_generate_a_short_uuid5()
 {
     $shortUuid = ShortUuid::uuid5(Uuid::NAMESPACE_DNS, 'ticketswap.com');
     $this->assertEquals(22, strlen($shortUuid));
 }
Example #3
0
 protected function longUuidToShortUuid($longUuid)
 {
     $uuid = Uuid::fromString($longUuid);
     $shortUuid = new ShortUuid();
     return (string) $shortUuid->encode($uuid);
 }