コード例 #1
0
 public static function generate($ver = 4, $node = null, $clockSeq = null, $ns = null, $name = null)
 {
     $uuid = null;
     /* Create a new UUID based on provided data. */
     switch ((int) $ver) {
         case 1:
             $uuid = Uuid::uuid1($node, $clockSeq);
             break;
         case 2:
             // Version 2 is not supported
             throw new \RuntimeException('UUID version 2 is unsupported.');
         case 3:
             $uuid = Uuid::uuid3($ns, $name);
             break;
         case 4:
             $uuid = Uuid::uuid4();
             break;
         case 5:
             $uuid = Uuid::uuid5($ns, $name);
             break;
         default:
             throw new \RuntimeException('Selected UUID version is invalid or unsupported.');
     }
     if (function_exists('gmp_strval')) {
         return gmp_strval(gmp_init($uuid->getHex(), 16), 62);
     }
     return Base62::encode((string) $uuid->getInteger());
 }
コード例 #2
0
ファイル: Uuid.php プロジェクト: absolvent/php-guid
 /**
  * {@inheritDoc}
  */
 public function generateUniqueId($name = null)
 {
     if (empty($name)) {
         $name = uniqid($name, $moreEnthropy = true);
     }
     return RhumsaaUuid::uuid5(RhumsaaUuid::NAMESPACE_OID, $name)->toString();
 }
コード例 #3
0
 public function testUuidToBinary()
 {
     $uuid = Uuid::uuid5(Uuid::NAMESPACE_OID, 1);
     $binary = UuidConverter::uuidToBinary($uuid->toString());
     $finalUuid = Uuid::fromBytes($binary);
     $this->assertSame($uuid->toString(), $finalUuid->toString());
 }
コード例 #4
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;
 }
コード例 #5
0
ファイル: UuidTest.php プロジェクト: thefox/phpchat
 public function testId()
 {
     #$id = (string)Uuid::uuid4();
     #$id = (string)Uuid::uuid5(Uuid::NAMESPACE_DNS, 'php.net');
     $key = sslKeyPubClean(static::SSL_KEY_PUB1);
     $keyBin = base64_decode($key);
     $id = (string) Uuid::uuid5(Uuid::NAMESPACE_X500, $keyBin);
     $this->assertEquals('d4773c00-6a11-540a-b72c-ed106ef8309b', $id);
     $id = (string) Uuid::uuid5(Uuid::NAMESPACE_X500, static::SSL_KEY_PUB1);
     $this->assertEquals('91a3d7b5-28fe-52d1-a56d-b09093c63c84', $id);
     $id = (string) Uuid::uuid5(Uuid::NAMESPACE_X500, 'hello world');
     $this->assertEquals('dbd9b896-6d7c-5852-895c-ecc5735cf874', $id);
     $id = (string) Uuid::uuid5(Uuid::NAMESPACE_DNS, 'hello world');
     $this->assertEquals('823a2f73-a936-56c3-b8b4-03641bd74f35', $id);
     $id = (string) Uuid::uuid5(Uuid::NAMESPACE_X500, 'my_name');
     $this->assertEquals('045fe53e-72be-5a76-8f58-783aed5c99d5', $id);
     $this->assertTrue(Uuid::isValid('91a3d7b5-28fe-52d1-a56d-b09093c63c84'));
     $this->assertFalse(Uuid::isValid('x1a3d7b5-28fe-52d1-a56d-b09093c63c84'));
     $id = '00000000-0000-4000-8000-000000000000';
     $this->assertTrue(Uuid::isValid($id));
     $id = '00000000-0000-4000-8000-00000000000x';
     $this->assertFalse(Uuid::isValid($id));
     $id = '00000000-0000-4000-8000-0000000000';
     $this->assertFalse(Uuid::isValid($id));
     $id = '00000000-0000-0000-0000-000000000000';
     $this->assertTrue(Uuid::isValid($id));
     $id = 'badfood0-0000-4000-a000-000000000000';
     $this->assertFalse(Uuid::isValid($id));
     $id = 'cafed00d-2131-4159-8e11-0b4dbadb1738';
     $this->assertTrue(Uuid::isValid($id));
 }
コード例 #6
0
ファイル: PhotoTest.php プロジェクト: tmciver/gallerylib
 public function testEventPublish()
 {
     $eventBus = new EventBus();
     $listener = new PhotoTestEventListener();
     $eventBus->subscribe($listener);
     $uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, 'photo1');
     new Photo("/some/file/path.img", $uuid->toString(), $eventBus);
     $this->assertTrue($listener->handled());
 }
コード例 #7
0
ファイル: UUID.php プロジェクト: tourze/security
 /**
  * 基于名字的SHA-1散列值,与v3一样,区别是使用哈希算法换了sha1
  *
  * @param  string $namespace
  * @param  string $name
  * @return string
  */
 public static function v5($namespace = VendorUUID::NAMESPACE_DNS, $name = 'php.net')
 {
     try {
         $uuid5 = VendorUUID::uuid5($namespace, $name);
         return $uuid5->toString();
     } catch (UnsatisfiedDependencyException $e) {
         return false;
     }
 }
コード例 #8
0
 /**
  * Get token value with UUID5 string.
  *
  * @param  \App\Application $app
  * @return string|null
  */
 private function getUUID5Token(Application $app)
 {
     try {
         $uuid5 = Uuid::uuid5(Uuid::NAMESPACE_DNS, time() . $app->name . $app->type);
         return $uuid5->toString();
     } catch (UnsatisfiedDependencyException $e) {
         return null;
     }
 }
コード例 #9
0
 public function execute()
 {
     // see if a photo with this file path already exists in the system; do
     // nothing if it does
     // generate a uuid using the photo file path as the 'name' parameter
     $uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, $this->filePath);
     // create the photo object.  This should cause some kind of 'photo added
     // event'
     // add it to the media repository
 }
コード例 #10
0
ファイル: UuidGenerator.php プロジェクト: gdpro/gdpro-tool
 /**
  * Create a UUID v5sudos
  *
  * @return string
  * @throws \Exception
  */
 public static function v5()
 {
     try {
         $uuid = RhumsaaUuid::uuid5(RhumsaaUuid::NAMESPACE_DNS, 'php.net');
         $uuidString = $uuid->toString();
     } catch (UnsatisfiedDependencyException $exc) {
         throw new \Exception(__METHOD__ . ': Some dependency was not met or the method cannot be called on a 32 bit
         system.', $exc);
     }
     return $uuidString;
 }
コード例 #11
0
ファイル: WmsImport.php プロジェクト: areinert/metador2
 /**
  * @param $url
  * @return bool|string
  */
 public function convertUrlToUuid($url)
 {
     try {
         $urlArray = parse_url(strtolower(trim($url)));
         $urlArray['query'] = isset($urlArray['query']) ? explode("&", $urlArray['query']) : array();
         sort($urlArray['query']);
         $string = $urlArray['host'] . $urlArray['path'] . implode("", $urlArray['query']);
         $string = str_replace("/", "", $string);
         return Uuid::uuid5(Uuid::NAMESPACE_DNS, $string)->toString();
     } catch (UnsatisfiedDependencyException $e) {
         return false;
     }
 }
コード例 #12
0
ファイル: AbstractDAO.php プロジェクト: blockjon/octopus
 /**
  * Create a model.
  * 
  * @param type $model
  * @return void
  * @throws \Exception
  */
 public function create(AbstractModel $model)
 {
     $currentTime = time();
     if ($model->getId() === null) {
         $uuid = (string) Uuid::uuid5(Uuid::NAMESPACE_DNS, uniqid('', true));
         $model->setId($uuid);
     }
     if ($model->getDateCreated() === null) {
         $model->setDateCreated($currentTime);
     }
     $model->setDateLastUpdated($currentTime);
     // Loop over each of the write strategies executing the create method.
     $this->writeDataChange($model, self::METHOD_CREATE);
 }
 public function createPlan(array $plan)
 {
     $em = $this->doctrineBoot->getEntityManager();
     $id = Uuid::uuid5(Uuid::NAMESPACE_OID, $plan['name'])->toString();
     $repo = $em->getRepository(Plan::class);
     $planObject = $repo->find($id);
     $free = !isset($service['free']) || $service['free'] ? true : false;
     if ($planObject === null) {
         $planObject = new Plan($id, $plan['name'], $plan['description']);
     }
     if (isset($plan['metadata'])) {
         $planObject->setMetadata($this->createMetadata($plan['metadata']));
     }
     $planObject->setFree($free);
     $em->persist($planObject);
     return $planObject;
 }
コード例 #14
0
 /**
  * Run seeder
  */
 public function run()
 {
     $accounts = [['uuid' => UuidConverter::uuidToBinary(Uuid::uuid5(Uuid::NAMESPACE_OID, 'account_1')->toString()), 'owner_id' => 1, 'custom_domain' => null, 'name' => 'Account 1', 'slug' => 'account', 'language' => 'en', 'timezone' => 'America/Toronto', 'created_at' => Carbon::now()->subDays(365)]];
     DB::table('accounts')->insert($accounts);
 }
コード例 #15
0
ファイル: Uuid.php プロジェクト: kpacha/sifo-uuid-plugin
 public static function uuid5($ns, $name)
 {
     return BaseUuid::uuid5($ns, $name);
 }
コード例 #16
0
ファイル: Keygen.php プロジェクト: xpressengine/xpressengine
 /**
  * generate name base and hashed sha1 uuid
  *
  * @param string $namespace base name
  * @return string
  */
 protected function createIdVersion5($namespace)
 {
     return Uuid::uuid5(Uuid::NAMESPACE_DNS, $namespace)->toString();
 }
コード例 #17
0
ファイル: Counter.php プロジェクト: rafalradomski/Counter
 /**
  * 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;
 }
コード例 #18
0
ファイル: Uuid.php プロジェクト: wartron/yii2-uuid
 public static function uuid5($ns, $name)
 {
     return self::bin(BaseUuid::uuid5($ns, $name));
 }
コード例 #19
0
ファイル: AbstractId.php プロジェクト: Rybbow/x-blog
 /**
  *
  */
 public function __construct()
 {
     $this->value = Uuid::uuid5($this->getScopeUuid(), $this->getScope());
 }
コード例 #20
0
 /**
  * Run seeder
  */
 public function run()
 {
     $users = [['uuid' => UuidConverter::uuidToBinary(Uuid::uuid5(Uuid::NAMESPACE_OID, 'user_1')->toString()), 'account_id' => 1, 'role' => User::OWNER_ROLE, 'activation_code' => null, 'firstname' => 'Maxime', 'lastname' => 'Beaudoin', 'email' => '*****@*****.**', 'password' => Hash::make('123123123'), 'reset_password_code' => null, 'timezone' => 'America/Toronto', 'activated_at' => Carbon::now()->subDays(15), 'created_at' => Carbon::now()->subDays(15), 'updated_at' => Carbon::now()->subDays(15)]];
     DB::table('users')->insert($users);
 }
コード例 #21
0
ファイル: APITokenAuth.php プロジェクト: jeins/bellmasjid
 /**
  * generate random api-key
  * @param $mixed
  * @return string
  */
 private function generateUUID($mixed)
 {
     return Uuid::uuid5(Uuid::uuid4(), $mixed)->toString();
 }
コード例 #22
0
ファイル: Node.php プロジェクト: thefox/phpchat
 public static function genIdHexStr($key)
 {
     $key = sslKeyPubClean($key);
     $keyBin = base64_decode($key);
     try {
         $id = (string) Uuid::uuid5(Uuid::NAMESPACE_X500, $keyBin);
         return $id;
     } catch (UnsatisfiedDependencyException $e) {
         return null;
     }
     // @codeCoverageIgnoreEnd
 }
コード例 #23
0
ファイル: Uuid.php プロジェクト: tshafer/laravel-support
 /**
  * Generate a version 5 (name-based and hashed with SHA1) UUID object.
  *
  * @param string $ns
  * @param string $name
  *
  * @return string
  */
 function uuid5($ns, $name)
 {
     $uuid = Uuid::uuid5($ns, $name);
     return $uuid->toString();
 }
コード例 #24
0
ファイル: routes.php プロジェクト: dwolf555/auth-token
<?php

use Rhumsaa\Uuid\Uuid;
use Rhumsaa\Uuid\Exception\UnsatisfiedDependencyException;
// Login route
Route::post('/login', function () {
    // Gather inputs
    $email = Input::get('email', false);
    $username = Input::get('username', false);
    $password = Input::get('password');
    // Make sure username or password was entered
    if ($email === false and $username === false) {
        return Response::make('Unauthorized', 401);
    }
    // Determine whether to use email or username as identifier
    $identifier = $email === false ? $username : $email;
    $identifierColumn = $email === false ? 'username' : 'email';
    // Find user
    $userQuery = DB::table('users');
    $userQuery = $userQuery->where($identifierColumn, $identifier);
    $user = $userQuery->first(array('uuid', 'password'));
    // Make sure password is valid
    if (!Hash::check($password, $user->password)) {
        return Response::make('Unauthorized', 401);
    }
    // Update uuid
    $uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, $email . date('Ymd'))->toString();
    $userQuery->update(array('uuid' => $uuid));
    // Return UUID
    return Response::json(array('key' => $uuid));
});
コード例 #25
0
ファイル: EndomondoOld.php プロジェクト: fabulator/endomondo
 public function __construct()
 {
     $this->deviceId = (string) Uuid::uuid5(Uuid::NAMESPACE_DNS, gethostname());
     $this->userAgent = sprintf("Dalvik/1.4.0 (Linux; U; %s %s; %s Build/GINGERBREAD)", $this->os, $this->osVersion, $this->model);
     $this->httpclient = new Client(['base_url' => 'https://api.mobile.endomondo.com']);
 }