本文整理汇总了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));
}
示例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);
}
示例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);
}
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
}
示例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;
}
示例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());
}
}
示例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())));
}
示例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);
}
示例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);
}
}
示例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);
}
}