當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Uuid::isValid方法代碼示例

本文整理匯總了PHP中Rhumsaa\Uuid\Uuid::isValid方法的典型用法代碼示例。如果您正苦於以下問題:PHP Uuid::isValid方法的具體用法?PHP Uuid::isValid怎麽用?PHP Uuid::isValid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Rhumsaa\Uuid\Uuid的用法示例。


在下文中一共展示了Uuid::isValid方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testId

 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));
 }
開發者ID:thefox,項目名稱:phpchat,代碼行數:31,代碼來源:UuidTest.php

示例2: String

 /**
  */
 function __construct($uuid)
 {
     if (FALSE === UuidGenerator::isValid($uuid)) {
         throw new \InvalidArgumentException("Provided string '{$uuid}' is not valid UUID");
     }
     $this->_uuid = new String($uuid);
 }
開發者ID:agmakonts,項目名稱:ddd-bricks,代碼行數:9,代碼來源:AbstractUuid.php

示例3: testNewUuid

 /**
  * @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);
     }
 }
開發者ID:nlegoff,項目名稱:Phraseanet,代碼行數:28,代碼來源:FileTest.php

示例4: testId

 /**
  * @test
  */
 public function testId()
 {
     $name = 'Douglas';
     $player = new HangmanPlayer(null, $name);
     $this->assertTrue(Uuid::isValid((string) $player->getId()));
     $this->assertEquals($name, $player->getName());
     $this->assertEquals(6, $player->getRemainingLives());
     $this->assertNull($player->getGame());
 }
開發者ID:remi-san,項目名稱:hangman,代碼行數:12,代碼來源:HangmanPlayerTest.php

示例5: delete

 /**
  * Delete object from database
  * @param  string $document_id Identifier to delete document
  * @return boolean             Return TRUE if delete, else, FALSE
  */
 public function delete($document_id)
 {
     if (is_null($document_id) || !Uuid::isValid($document_id)) {
         return false;
     }
     if (file_exists($file = $this->dataPath . DIRECTORY_SEPARATOR . $document_id)) {
         return unlink($file);
     }
     return false;
 }
開發者ID:wallacesilva,項目名稱:phpjsonlite,代碼行數:15,代碼來源:JSONlite.php

示例6: __construct

 /**
  * @param string
  */
 public final function __construct($uuid)
 {
     if (!is_string($uuid)) {
         throw new InvalidArgumentException('Uuid expected a string.');
     }
     if (!\Rhumsaa\Uuid\Uuid::isValid($uuid)) {
         throw new InvalidArgumentException('Invalid Uuid format.');
     }
     $this->uuid = \Rhumsaa\Uuid\Uuid::fromString($uuid);
 }
開發者ID:rayrutjes,項目名稱:domain,代碼行數:13,代碼來源:Uuid.php

示例7: convertToDatabaseValue

 /**
  * {@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 (string) $value;
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
開發者ID:tunandras,項目名稱:webtrees,代碼行數:16,代碼來源:UuidType.php

示例8: setUuidAttribute

 /**
  * Mutator for uuid attribute
  *
  * @throw InvalidUuidFormatException
  * @return string
  */
 public function setUuidAttribute($value)
 {
     //If it's a instance of Uuid, convert to string
     if ($value instanceof Uuid) {
         $value = $value->toString();
     }
     //If the uuid is not valid
     if (!Uuid::isValid($value)) {
         throw new InvalidUuidFormatException('The format of the uuid ' . $value . ' is not valid');
     }
     $this->attributes['uuid'] = UuidConverter::uuidToBinary($value);
 }
開發者ID:ellipsesynergie,項目名稱:backend-skeleton,代碼行數:18,代碼來源:AbstractEntity.php

示例9: findByIdentifier

 /**
  * @param string $id article_id or permalink
  * @return Article
  * @throws ModelNotFoundException
  */
 public function findByIdentifier($id)
 {
     //if the id is a uuid, try that or fail.
     if (Uuid::isValid($id)) {
         return parent::findOrFail($id);
     }
     //otherwise attempt treat the id as a permalink and first try the model, then try the history
     try {
         return $this->where('permalink', '=', $id)->firstOrFail();
     } catch (ModelNotFoundException $e) {
         //id or permalink not found, try permalink history
         return ArticlePermalink::findOrFail($id)->article;
     }
 }
開發者ID:TFidryForks,項目名稱:spira,代碼行數:19,代碼來源:Article.php

示例10: isApiKeyUserPassValid

 /**
  * check if API-Key and WWW-Authorization valid
  * @param $token
  * @param $authentication
  * @return bool
  */
 public function isApiKeyUserPassValid($token, $authentication)
 {
     try {
         if (Uuid::isValid($token)) {
             $check = $this->getDB()->query()->where('email', '=', base64_decode($authentication))->where('token', '=', $token)->get()->count();
             if (!$check) {
                 return false;
             }
             return true;
         }
     } catch (\Exception $e) {
         $this->writeToJSON(['errmsg' => 'service unavailable'], 503);
     }
     return false;
 }
開發者ID:jeins,項目名稱:bellmasjid,代碼行數:21,代碼來源:APITokenAuth.php

示例11: fetch

 /**
  * Fetch a resource
  *
  * @param  mixed $id
  * @return ApiProblem|mixed
  */
 public function fetch($id)
 {
     try {
         if (!Uuid::isValid($id)) {
             return new ApiProblem(400, 'Invalid identifier');
         }
         $repository = $this->entityManager->getRepository('Application\\V1\\Entity\\Pages');
         /* @var $pagesEntity PagesEntity */
         $pagesEntity = $repository->findOneByUuid($id);
         if (is_null($pagesEntity)) {
             return new ApiProblem(404, 'Requested site not found');
         }
         return $pagesEntity;
     } catch (\Exception $e) {
         return new ApiProblem(500, $e->getMessage());
     }
 }
開發者ID:spalax,項目名稱:eu-webchalange-download-images-api,代碼行數:23,代碼來源:PagesResource.php

示例12: fetchAll

 /**
  * Fetch all or a subset of resources
  *
  * @param  array $params
  * @return ApiProblem|mixed
  */
 public function fetchAll($params = array())
 {
     $pageId = $this->getEvent()->getRouteMatch()->getParam('page_id', null);
     if (!Uuid::isValid($pageId)) {
         return new ApiProblem(400, 'Invalid identifier');
     }
     /* @var $pageEntity PagesEntity */
     $pageEntity = $this->entityManager->getRepository('Application\\V1\\Entity\\Pages')->findOneByUuid($pageId);
     if (is_null($pageEntity)) {
         return new ApiProblem(404, 'Not found result of missed page');
     }
     if ($pageEntity->getStatusNumeric() !== PageInterface::STATUS_DONE) {
         return new ApiProblem(428, 'Not all images downloaded yet');
     }
     $qb = $this->entityManager->getRepository('Application\\V1\\Entity\\Images')->createQueryBuilder('i');
     $qb->where('i.page = :page')->setParameter('page', $pageEntity);
     return new Paginator(new DoctrineAdapter(new DoctrinePaginator($qb->getQuery())));
 }
開發者ID:spalax,項目名稱:eu-webchalange-download-images-api,代碼行數:24,代碼來源:ImagesResource.php

示例13: execute

 /**
  * {@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->getHelperSet()->get('table');
     $table->setLayout(TableHelper::LAYOUT_BORDERLESS);
     $table->addRows(array(array('encode:', 'STR:', (string) $uuid), array('', 'INT:', (string) $uuid->getInteger())));
     if ($uuid->getVariant() != Uuid::RFC_4122) {
         $table->addRows(array(array('decode:', 'variant:', 'Not an RFC 4122 UUID')));
         $table->render($output);
         return;
     }
     switch ($uuid->getVersion()) {
         case 1:
             $version = '1 (time and node based)';
             break;
         case 2:
             $version = '2 (DCE security based)';
             break;
         case 3:
             $version = '3 (name based, MD5)';
             break;
         case 4:
             $version = '4 (random data based)';
             break;
         case 5:
             $version = '5 (name based, SHA-1)';
             break;
     }
     $table->addRows(array(array('decode:', 'variant:', 'RFC 4122'), array('', 'version:', $version)));
     if ($uuid->getVersion() == 1) {
         $table->addRows(array(array('', 'content:', 'time:  ' . $uuid->getDateTime()->format('c')), array('', '', 'clock: ' . $uuid->getClockSequence() . ' (usually random)'), array('', '', 'node:  ' . substr(chunk_split($uuid->getNodeHex(), 2, ':'), 0, -1))));
     }
     if ($uuid->getVersion() == 4) {
         $table->addRows(array(array('', 'content:', substr(chunk_split($uuid->getHex(), 2, ':'), 0, -1)), array('', '', '(no semantics: random data only)')));
     }
     if ($uuid->getVersion() == 3 || $uuid->getVersion() == 5) {
         $table->addRows(array(array('', 'content:', substr(chunk_split($uuid->getHex(), 2, ':'), 0, -1)), array('', '', '(not decipherable: MD5 message digest only)')));
     }
     $table->render($output);
 }
開發者ID:brambravo,項目名稱:webtrees,代碼行數:49,代碼來源:DecodeCommand.php

示例14: evaluateGoodStory

 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(V1::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(V1::OBJECT_TYPE_STORY_METADATA_BAG, $story['metadatas']['@entity@']);
     foreach ($story['records'] as $record) {
         $this->evaluateGoodRecord($record);
     }
 }
開發者ID:nlegoff,項目名稱:Phraseanet,代碼行數:48,代碼來源:ApiTestCase.php

示例15: testExecuteForUuidSpecifyVersion5WithCount

 /**
  * @covers Rhumsaa\Uuid\Console\Command\GenerateCommand::execute
  * @covers Rhumsaa\Uuid\Console\Command\GenerateCommand::createUuid
  * @covers Rhumsaa\Uuid\Console\Command\GenerateCommand::validateNamespace
  */
 public function testExecuteForUuidSpecifyVersion5WithCount()
 {
     $generate = new GenerateCommand();
     $input = new StringInput('5 ns:DNS "python.org" -c 21', $generate->getDefinition());
     $output = new TestOutput();
     $this->execute->invoke($generate, $input, $output);
     $this->assertCount(21, $output->messages);
     foreach ($output->messages as $uuid) {
         $this->assertTrue(Uuid::isValid($uuid));
         $this->assertEquals(5, Uuid::fromString($uuid)->getVersion());
         $this->assertEquals('886313e1-3b8a-5372-9b90-0c9aee199e5d', $uuid);
     }
 }
開發者ID:joemar-tagpuno,項目名稱:uuid,代碼行數:18,代碼來源:GenerateCommandTest.php


注:本文中的Rhumsaa\Uuid\Uuid::isValid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。