예제 #1
0
 /**
  * Generate ID
  * @return String
  */
 public function generateId($version = 4, $includeDash = false)
 {
     try {
         switch ($version) {
             case 1:
                 $uuid = Uuid::uuid1();
                 break;
             case 3:
                 $uuid = Uuid::uuid3(Uuid::NAMESPACE_DNS, php_uname('n'));
                 break;
             case 5:
                 $uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, php_uname('n'));
                 break;
             default:
                 $uuid = Uuid::uuid4();
                 break;
         }
         return $includeDash ? $uuid->toString() : str_replace('-', '', $uuid->toString());
     } catch (UnsatisfiedDependencyException $e) {
         // Some dependency was not met. Either the method cannot be called on a
         // 32-bit system, or it can, but it relies on Moontoast\Math to be present.
         echo 'Caught exception: ' . $e->getMessage() . "\n";
         exit;
     }
 }
예제 #2
0
파일: UUID.php 프로젝트: tododo/pimcore
 /**
  * @return mixed
  * @throws \Exception
  */
 public function createUuid()
 {
     if (!$this->getInstanceIdentifier()) {
         throw new \Exception("No instance identifier specified.");
     }
     $uuid = \Ramsey\Uuid\Uuid::uuid5(\Ramsey\Uuid\Uuid::NAMESPACE_DNS, $this->getInstanceIdentifier());
     return $uuid;
 }
예제 #3
0
 /**
  * Quick way to set variables for a new lease.
  *
  * @param $resourceId
  * @param null $userId
  * @param null $duration
  * @return array
  */
 public static function stub($resourceId, $userId = null, $duration = null)
 {
     $duration = is_null($duration) ? 60 : $duration;
     $userId = is_null($userId) ? Auth::user()->id : $userId;
     $leaseParams = ['resource_id' => $resourceId, 'user_id' => $userId, 'duration' => $duration, 'expires_at' => Carbon::create()->addMinutes($duration)];
     $leaseParams['uuid'] = Uuid::uuid5(Uuid::NAMESPACE_DNS, $leaseParams['resource_id'] . $leaseParams['user_id']);
     return $leaseParams;
 }
예제 #4
0
 /**
  * Registering uuid listeners
  */
 public static function bootUuidModel()
 {
     static::creating(function ($model) {
         $model->uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, sprintf('%s.%s.%s.%s', rand(0, time()), time(), static::class, config('modelutils.namespace')))->toString();
     });
     static::saving(function ($model) {
         $originalUuid = $model->getOriginal('uuid');
         // Preventing lateral modifying uuid
         if ($originalUuid !== $model->uuid) {
             $model->uuid = $originalUuid;
         }
     });
 }
예제 #5
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();
     }
 }
예제 #6
0
 public static function generateGuid($reference = null)
 {
     if (isset($reference)) {
         $uuid = Uuid::uuid5(Uuid::NAMESPACE_OID, $reference);
     } else {
         $uuid = Uuid::uuid4();
     }
     return '{' . $uuid->toString() . '}';
 }
 /**
  * Unique cache key for this Container.
  *
  * @return string
  */
 public function getCacheKey()
 {
     //Return Key
     return 'PersonalityInsights-' . Uuid::uuid5(Uuid::NAMESPACE_DNS, collect(['contentItems' => $this->toArray()])->toJson())->toString();
 }
 /**
  * @param string $namespace
  * @param string $name
  *
  * @return $this
  */
 public function generateUuid5($namespace, $name)
 {
     $this->uuid = Uuid::uuid5($namespace, $name);
     return $this;
 }
예제 #9
0
 /**
  * Calculates a UUID for a passed string.
  *
  * @param string $input The input to calculate the UUID for.
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return string The UUID
  */
 protected function calculateUuid($input)
 {
     try {
         // Generate a version 5 (name-based and hashed with SHA1) UUID object
         $uuid5 = Uuid::uuid5(Uuid::NAMESPACE_DNS, $input);
         $uuid = $uuid5->toString();
     } catch (UnsatisfiedDependencyException $e) {
         $uuid = sha1($input);
     }
     return $uuid;
 }
예제 #10
0
 /**
  * Generate and return a UUID.
  *
  * If the $name parameter is provided, set the namespace to the provided
  * name and generate a UUID.
  *
  * @param string $name
  * @return string
  */
 public function uuid($name = null)
 {
     if (is_null($name)) {
         $uuid = Uuid::uuid4();
     } else {
         if (stristr($name, 'http') == false) {
             $uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, $name);
         } else {
             $uuid = Uuid::uuid5(Uuid::NAMESPACE_URL, $name);
         }
     }
     return $this->encode($uuid);
 }
 public function testShouldAcceptUuid5()
 {
     $uuid = new Uuid(BaseUuid::uuid5(BaseUuid::NAMESPACE_DNS, 'user'));
     $this->assertInstanceOf('App\\Domain\\Identity\\Uuid', $uuid);
 }
예제 #12
0
파일: Uuid.php 프로젝트: websharks/core
 /**
  * UUID v5 generator.
  *
  * @since 150424 Initial release.
  *
  * @param string $namespace  Namespace.
  * @param string $identifier Identifier.
  * @param bool   $optimize   Optimize?
  *
  * @return string Version 5 UUID (32 bytes optimized).
  *                Or 36 bytes unoptimized; i.e., w/ dashes.
  */
 public function v5(string $namespace, string $identifier, bool $optimize = true) : string
 {
     switch ($namespace) {
         case 'dns':
             $namespace = UuidGen::NAMESPACE_DNS;
             break;
             // Stop here.
         // Stop here.
         case 'url':
             $namespace = UuidGen::NAMESPACE_URL;
             break;
             // Stop here.
         // Stop here.
         case 'oid':
             $namespace = UuidGen::NAMESPACE_OID;
             break;
             // Stop here.
         // Stop here.
         case 'x500':
             $namespace = UuidGen::NAMESPACE_X500;
             break;
             // Stop here.
         // Stop here.
         default:
             throw $this->c::issue('Invalid namespace.');
     }
     $uuid = UuidGen::uuid5($namespace, $identifier)->toString();
     return $optimize ? str_replace('-', '', $uuid) : $uuid;
 }
예제 #13
0
 public function uuidProvider()
 {
     return array(array(Uuid::uuid1()), array(Uuid::uuid3(Uuid::NAMESPACE_DNS, 'php.net')), array(Uuid::uuid4()), array(Uuid::uuid5(Uuid::NAMESPACE_DNS, 'php.net')), array(Uuid::fromString(self::UUID_SAMPLE)));
 }
예제 #14
0
 /**
  * Generates a hash based on page identifier
  *
  * @param string $identifier
  * @param null|integer $id
  * @return string
  */
 private static function pageId($identifier, $id = null)
 {
     $uuid5 = Uuid::uuid5(Uuid::NAMESPACE_DNS, $identifier);
     if ($id) {
         $uuid5 = Uuid::uuid5(Uuid::NAMESPACE_DNS, $identifier . '-' . $id);
     }
     return $uuid5;
 }
예제 #15
0
 /**
  * Creates the requested UUID
  *
  * @param int $version
  * @param string $namespace
  * @param string $name
  * @return Uuid
  */
 protected function createUuid($version, $namespace = null, $name = null)
 {
     switch ((int) $version) {
         case 1:
             $uuid = Uuid::uuid1();
             break;
         case 4:
             $uuid = Uuid::uuid4();
             break;
         case 3:
         case 5:
             $ns = $this->validateNamespace($namespace);
             if (empty($name)) {
                 throw new Exception('The name argument is required for version 3 or 5 UUIDs');
             }
             if ($version == 3) {
                 $uuid = Uuid::uuid3($ns, $name);
             } else {
                 $uuid = Uuid::uuid5($ns, $name);
             }
             break;
         default:
             throw new Exception('Invalid UUID version. Supported are version "1", "3", "4", and "5".');
     }
     return $uuid;
 }
예제 #16
0
 /**
  * Generate a version 5 UUID based on the SHA-1 hash of a namespace
  * identifier (which is a UUID) and a name (which is a string) and shorten it.
  *
  * @param string $ns The UUID namespace in which to create the named UUID
  * @param string $name The name to create a UUID for
  *
  * @return string
  */
 public static function uuid5($ns, $name)
 {
     $uuid = Uuid::uuid5($ns, $name);
     $shortUuid = new self();
     return $shortUuid->encode($uuid);
 }
예제 #17
0
 function uuid5($ns, $name)
 {
     $uuid = Uuid::uuid5($ns, $name);
     return $uuid->toString();
 }
예제 #18
0
 public static function p2uuid5($subDomain = self::SUBDOMAIN_UUID)
 {
     return Uuid::uuid5(Uuid::uuid4(), self::fullReverseDomain($subDomain));
 }
예제 #19
0
파일: Uuid.php 프로젝트: compufour/uuid
 public function generate(int $name) : string
 {
     $generated = UuidLibrary::fromBytes($this->getIdentifier());
     return UuidLibrary::uuid5($generated, $name);
 }
예제 #20
0
파일: Uuid.php 프로젝트: ollieday/yii2-uuid
 /**
  * @see \Ramsey\Uuid\Uuid::uuid5()
  *
  * @param string $ns
  * @param string $name
  * @return \Ramsey\Uuid\UuidInterface
  */
 public function uuid5($ns, $name)
 {
     return \Ramsey\Uuid\Uuid::uuid5($ns, $name);
 }
예제 #21
0
 public static function uuid5($ns, $name)
 {
     return self::fromRamseyUuid(parent::uuid5($ns, $name));
 }