mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-15 16:07:55 +03:00
Merge pull request #162 from garak/specific-exception
add a specific exception for invalid UUID string
This commit is contained in:
@@ -16,6 +16,7 @@ namespace Ramsey\Uuid\Codec;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Ramsey\Uuid\Builder\UuidBuilderInterface;
|
||||
use Ramsey\Uuid\Exception\InvalidUuidStringException;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
@@ -139,7 +140,7 @@ class StringCodec implements CodecInterface
|
||||
$nameParsed = implode('-', $components);
|
||||
|
||||
if (!Uuid::isValid($nameParsed)) {
|
||||
throw new InvalidArgumentException('Invalid UUID string: ' . $encodedUuid);
|
||||
throw new InvalidUuidStringException('Invalid UUID string: ' . $encodedUuid);
|
||||
}
|
||||
|
||||
return $components;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the ramsey/uuid library
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
|
||||
* @license http://opensource.org/licenses/MIT MIT
|
||||
* @link https://benramsey.com/projects/ramsey-uuid/ Documentation
|
||||
* @link https://packagist.org/packages/ramsey/uuid Packagist
|
||||
* @link https://github.com/ramsey/uuid GitHub
|
||||
*/
|
||||
|
||||
namespace Ramsey\Uuid\Exception;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that the parsed UUID string is invalid.
|
||||
*/
|
||||
class InvalidUuidStringException extends \InvalidArgumentException
|
||||
{
|
||||
}
|
||||
+1
-1
@@ -80,7 +80,7 @@ class UuidTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedException \Ramsey\Uuid\Exception\InvalidUuidStringException
|
||||
* @expectedExceptionMessage Invalid UUID string:
|
||||
*/
|
||||
public function testFromStringWithInvalidUuidString()
|
||||
|
||||
Reference in New Issue
Block a user