本文整理汇总了PHP中Ramsey\Uuid\Uuid::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP Uuid::isValid方法的具体用法?PHP Uuid::isValid怎么用?PHP Uuid::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ramsey\Uuid\Uuid
的用法示例。
在下文中一共展示了Uuid::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValid
/**
* @param string $guid
* @return bool
*/
public static function isValid($guid)
{
if (!Uuid::isValid($guid) || !preg_match('/' . self::UUID4_PATTERN . '/', $guid)) {
return false;
}
return true;
}
示例2: __construct
/**
* @param string $value
*/
public function __construct(string $value)
{
if (!\Ramsey\Uuid\Uuid::isValid($value)) {
throw new \InvalidArgumentException(sprintf('%s is not a valid Uuid.', $value));
}
$this->value = \Ramsey\Uuid\Uuid::fromString($value);
}
示例3: deserializeUuidValue
/**
* @param string $uuidString
* @return \Ramsey\Uuid\UuidInterface
*/
private function deserializeUuidValue($uuidString)
{
if (!Uuid::isValid($uuidString)) {
throw new \Mhujer\JmsSerializer\Uuid\InvalidUuidException($uuidString);
}
return Uuid::fromString($uuidString);
}
示例4: 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);
}
}
示例5: __construct
/**
* @param string $entity_id
*/
public function __construct($entity_id = null)
{
if (is_null($entity_id) || false === Uuid::isValid($entity_id)) {
$entity_id = Uuid::uuid4();
}
$this->entity_id = $entity_id;
}
示例6: testGenerate
public function testGenerate()
{
$id = UuidIdentifier::generate();
$this->assertTrue(Uuid::isValid($id));
$uuid = Uuid::fromString($id->toString());
$this->assertTrue($uuid->getVersion() == 4);
}
示例7: fromString
public static function fromString(string $uuid)
{
if (!Uuid::isValid($uuid)) {
throw new \InvalidArgumentException(sprintf('%s is not valid uuid', $uuid));
}
return new Id(Uuid::fromString($uuid)->toString());
}
示例8: setUuidFromString
/**
* @param string $string
*
* @throws OrmException
*
* @return $this
*/
public function setUuidFromString($string)
{
if (!Uuid::isValid($string)) {
throw OrmException::create()->setMessage('Invalid Uuid string provided.');
}
$this->uuid = Uuid::fromString($string);
return $this;
}
示例9: getMatchers
public function getMatchers()
{
return ['beValidUUID' => function ($uuid) {
return Uuid::isValid($uuid);
}, 'beEqualUUID' => function ($uuid, $value) {
return Uuid::fromString($uuid)->equals(Uuid::fromString($uuid));
}];
}
示例10: isValid
/**
* {@inheritDoc}
*/
public function isValid($value)
{
if (!UuidImpl::isValid($value)) {
$this->error(self::INVALID_UUID);
return false;
}
$this->setValue($value);
return true;
}
示例11: getAccessToken
/**
* {@inheritdoc}
*/
public function getAccessToken($grant, array $options = [])
{
if (!isset($options['guid']) || !Uuid::isValid($options['guid'])) {
throw new \RuntimeException(sprintf('%s requires a "guid" option with a valid v4 UUID.', __METHOD__));
}
// Temporarily fake an access token for Local provider.
$defaultOptions = ['access_token' => Uuid::uuid4()->toString(), 'resource_owner_id' => $options['guid'], 'refresh_token' => Uuid::uuid4()->toString(), 'expires' => 86400];
return new AccessToken(array_merge($defaultOptions, $options));
}
示例12: convertToDatabaseValue
/**
* {@inheritdoc}
*
* @param mixed $value
* @param AbstractPlatform $platform
*
* @throws ConversionException
*
* @return null|string
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (empty($value)) {
return null;
}
if ($value instanceof Uuid || Uuid::isValid($value)) {
return (string) $value;
}
throw OrmTypeConversionException::create()->with($value, self::NAME);
}
示例13: 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 $value->getBytes();
}
throw ConversionException::conversionFailed($value, self::NAME);
}
示例14: convertToDatabaseValue
/**
* Converts a value from its PHP representation to its database representation of this type.
*
* @param mixed $value The value to convert.
*
* @return string
*/
public function convertToDatabaseValue($value)
{
if (null === $value) {
return null;
}
if ($value instanceof Uuid || Uuid::isValid($value)) {
return (string) $value;
}
throw ConversionException::conversionFailed($value, self::NAME);
}
示例15: 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->createTable($output);
$this->setTableLayout($table);
(new UuidFormatter())->write($table, $uuid);
$table->render($output);
}