Skip to content

Commit 96e69dc

Browse files
committed
Update ramsey/uuid to 3.*
1 parent f86a306 commit 96e69dc

10 files changed

+150
-136
lines changed

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,33 @@ To generate request id you need to use implementation of `PhpMiddleware\RequestI
5454

5555
Simple generator using [uniqid](http://php.net/manual/en/function.uniqid.php) function.
5656

57-
#### `RhumsaaUuid1Generator`
57+
#### `RamseyUuid1Generator`
5858

59-
[UUID](https://tools.ietf.org/html/rfc4122)1 implementations of [Rhumsaa\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.
59+
[UUID](https://tools.ietf.org/html/rfc4122)1 implementations of [Ramsey\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.
6060

61-
#### `RhumsaaUuid3Generator`
61+
#### `RamseyUuid3Generator`
6262

63-
[UUID](https://tools.ietf.org/html/rfc4122)3 implementations of [Rhumsaa\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.
63+
[UUID](https://tools.ietf.org/html/rfc4122)3 implementations of [Ramsey\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.
6464

65-
#### `RhumsaaUuid4Generator`
65+
#### `RamseyUuid4Generator`
6666

67-
[UUID](https://tools.ietf.org/html/rfc4122)4 implementations of [Rhumsaa\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.
67+
[UUID](https://tools.ietf.org/html/rfc4122)4 implementations of [Ramsey\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.
6868

69-
#### `RhumsaaUuid5Generator`
69+
#### `RamseyUuid4StaticGenerator`
7070

71-
[UUID](https://tools.ietf.org/html/rfc4122)5 implementations of [Rhumsaa\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.
71+
Generates Uuid4 like `RamseyUuid4Generator` however it's not require any dependency (it use static factory method).
72+
73+
#### `RamseyUuid5Generator`
74+
75+
[UUID](https://tools.ietf.org/html/rfc4122)5 implementations of [Ramsey\Uuid](https://github.com/ramsey/uuid). To use it you need to add `ramsey/uuid` dependency to your `composer.json`.
76+
77+
#### `PrefixedGenerator`
78+
79+
Adds prefix to generated request id.
80+
81+
#### `Md5Generator`
82+
83+
This generator converts generated request id to md5 hash.
7284

7385
## It's just works with any modern php framework!
7486

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
},
1515
"require-dev": {
1616
"phpunit/phpunit": "^4.8.6",
17-
"ramsey/uuid": "^2.8",
17+
"ramsey/uuid": "^3.0",
1818
"zendframework/zend-diactoros": "^1.1.3"
1919
},
2020
"suggest": {
21-
"ramsey/uuid": "To use Rhumsaa\\Uuid generator"
21+
"ramsey/uuid": "To use Ramsey\\Uuid 3.0 generator"
2222
},
2323
"autoload": {
2424
"psr-4": {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace PhpMiddleware\RequestId\Generator;
4+
5+
use Ramsey\Uuid\UuidFactoryInterface;
6+
7+
final class RamseyUuid1Generator implements GeneratorInterface
8+
{
9+
private $node;
10+
11+
private $clockSeq;
12+
13+
private $factory;
14+
15+
/**
16+
* @param UuidFactoryInterface $factory
17+
* @param int|string $node
18+
* @param int $clockSeq
19+
*/
20+
public function __construct(UuidFactoryInterface $factory, $node = null, $clockSeq = null)
21+
{
22+
$this->factory = $factory;
23+
$this->node = $node;
24+
$this->clockSeq = $clockSeq;
25+
}
26+
27+
/**
28+
* @return string
29+
*/
30+
public function generateRequestId()
31+
{
32+
return $this->factory->uuid1($this->node, $this->clockSeq)->toString();
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace PhpMiddleware\RequestId\Generator;
4+
5+
use Ramsey\Uuid\UuidFactoryInterface;
6+
7+
final class RamseyUuid3Generator implements GeneratorInterface
8+
{
9+
private $ns;
10+
11+
private $name;
12+
13+
private $factory;
14+
15+
/**
16+
* @param UuidFactoryInterface $factory
17+
* @param string $ns
18+
* @param string $name
19+
*/
20+
public function __construct(UuidFactoryInterface $factory, $ns, $name)
21+
{
22+
$this->factory = $factory;
23+
$this->ns = $ns;
24+
$this->name = $name;
25+
}
26+
27+
/**
28+
* @return string
29+
*/
30+
public function generateRequestId()
31+
{
32+
return $this->factory->uuid3($this->ns, $this->name)->toString();
33+
}
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace PhpMiddleware\RequestId\Generator;
4+
5+
use Ramsey\Uuid\UuidFactoryInterface;
6+
7+
final class RamseyUuid4Generator implements GeneratorInterface
8+
{
9+
private $factory;
10+
11+
public function __construct(UuidFactoryInterface $factory)
12+
{
13+
$this->factory = $factory;
14+
}
15+
16+
/**
17+
* @return string
18+
*/
19+
public function generateRequestId()
20+
{
21+
return $this->factory->uuid4()->toString();
22+
}
23+
}

src/Generator/RhumsaaUuid4Generator.php renamed to src/Generator/RamseyUuid4StaticGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace PhpMiddleware\RequestId\Generator;
44

5-
use Rhumsaa\Uuid\Uuid;
5+
use Ramsey\Uuid\Uuid;
66

7-
final class RhumsaaUuid4Generator implements GeneratorInterface
7+
final class RamseyUuid4StaticGenerator implements GeneratorInterface
88
{
99
/**
1010
* @return string
1111
*/
1212
public function generateRequestId()
1313
{
14-
return (string) Uuid::uuid4();
14+
return Uuid::uuid4()->toString();
1515
}
1616
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace PhpMiddleware\RequestId\Generator;
4+
5+
use Ramsey\Uuid\UuidFactoryInterface;
6+
7+
final class RamseyUuid5Generator implements GeneratorInterface
8+
{
9+
private $ns;
10+
11+
private $name;
12+
13+
private $factory;
14+
15+
/**
16+
* @param UuidFactoryInterface $factory
17+
* @param string $ns
18+
* @param string $name
19+
*/
20+
public function __construct(UuidFactoryInterface $factory, $ns, $name)
21+
{
22+
$this->factory = $factory;
23+
$this->ns = $ns;
24+
$this->name = $name;
25+
}
26+
27+
/**
28+
* @return string
29+
*/
30+
public function generateRequestId()
31+
{
32+
return $this->factory->uuid5($this->ns, $this->name)->toString();
33+
}
34+
}

src/Generator/RhumsaaUuid1Generator.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/Generator/RhumsaaUuid3Generator.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/Generator/RhumsaaUuid5Generator.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)