Skip to content

Commit c363f19

Browse files
committed
Full psr-15 support, php 7.1 as minimum
1 parent 3936e46 commit c363f19

23 files changed

+69
-257
lines changed

.scrutinizer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ checks:
33
build:
44
environment:
55
php:
6-
version: 5.6.16
6+
version: 7.3
77
tests:
88
override:
99
-

.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
language: php
22

33
php:
4-
- 5.6
5-
- 7.0
64
- 7.1
75
- 7.2
6+
- 7.3
87

98
env:
109
- DEPS=lowest
1110
- DEPS=latest
1211

1312
before_script:
1413
- phpenv config-rm xdebug.ini
15-
- composer self-update
1614
- if [[ $DEPS == 'lowest' ]]; then composer update --prefer-stable --no-interaction --prefer-lowest ; fi
1715
- if [[ $DEPS == 'latest' ]]; then composer update --prefer-stable --no-interaction ; fi
1816

README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ This middleware provide framework-agnostic possibility to generate and add to re
1111

1212
## Installation
1313

14-
```json
15-
{
16-
"require": {
17-
"php-middleware/request-id": "^3.0.0"
18-
}
19-
}
14+
```bash
15+
composer require php-middleware/request-id
2016
```
2117

2218
## Usage

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
"request-id"
1111
],
1212
"require": {
13-
"php": "^5.6 || ^7.0",
13+
"php": "^7.1",
1414
"psr/http-message": "^1.0",
15-
"php-middleware/double-pass-compatibility": "^1.0",
16-
"http-interop/http-middleware": "^0.4.1"
15+
"psr/http-server-handler": "^1.0",
16+
"psr/http-server-middleware": "^1.0"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^5.7.27 || ^6.1.3",
2019
"ramsey/uuid": "^3.0",
21-
"zendframework/zend-diactoros": "^1.1.3"
20+
"zendframework/zend-diactoros": "^2.0",
21+
"phpunit/phpunit": "^7.5.13"
2222
},
2323
"suggest": {
2424
"ramsey/uuid": "To use Ramsey\\Uuid 3.0 generator"

src/Generator/GeneratorInterface.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44

55
interface GeneratorInterface
66
{
7-
/**
8-
* @return string unique value
9-
*/
10-
public function generateRequestId();
7+
public function generateRequestId(): string;
118
}

src/Generator/Md5Generator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function __construct(GeneratorInterface $generator)
1111
$this->generator = $generator;
1212
}
1313

14-
public function generateRequestId()
14+
public function generateRequestId(): string
1515
{
1616
return md5($this->generator->generateRequestId());
1717
}

src/Generator/PhpUniqidGenerator.php

+4-17
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,19 @@
44

55
final class PhpUniqidGenerator implements GeneratorInterface
66
{
7-
/**
8-
* @var string
9-
*/
107
protected $prefix;
11-
12-
/**
13-
* @var bool
14-
*/
158
protected $moreEntropy;
169

1710
/**
18-
* @param string $prefix
19-
* @param bool $moreEntropy
20-
*
2111
* @link http://php.net/manual/en/function.uniqid.php
2212
*/
23-
public function __construct($prefix = '', $moreEntropy = false)
13+
public function __construct(string $prefix = '', bool $moreEntropy = false)
2414
{
25-
$this->prefix = (string) $prefix;
26-
$this->moreEntropy = (bool) $moreEntropy;
15+
$this->prefix = $prefix;
16+
$this->moreEntropy = $moreEntropy;
2717
}
2818

29-
/**
30-
* @return string
31-
*/
32-
public function generateRequestId()
19+
public function generateRequestId(): string
3320
{
3421
return uniqid($this->prefix, $this->moreEntropy);
3522
}

src/Generator/PrefixedGenerator.php

+3-10
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,13 @@ final class PrefixedGenerator implements GeneratorInterface
77
private $prefix;
88
private $generator;
99

10-
/**
11-
* @param string $prefix
12-
* @param GeneratorInterface $generator
13-
*/
14-
public function __construct($prefix, GeneratorInterface $generator)
10+
public function __construct(string $prefix, GeneratorInterface $generator)
1511
{
16-
$this->prefix = (string) $prefix;
12+
$this->prefix = $prefix;
1713
$this->generator = $generator;
1814
}
1915

20-
/**
21-
* @return string
22-
*/
23-
public function generateRequestId()
16+
public function generateRequestId(): string
2417
{
2518
return $this->prefix . $this->generator->generateRequestId();
2619
}

src/Generator/RamseyUuid1Generator.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,20 @@
77
final class RamseyUuid1Generator implements GeneratorInterface
88
{
99
private $node;
10-
1110
private $clockSeq;
12-
1311
private $factory;
1412

1513
/**
16-
* @param UuidFactoryInterface $factory
1714
* @param int|string $node
18-
* @param int $clockSeq
1915
*/
20-
public function __construct(UuidFactoryInterface $factory, $node = null, $clockSeq = null)
16+
public function __construct(UuidFactoryInterface $factory, $node = null, int $clockSeq = null)
2117
{
2218
$this->factory = $factory;
2319
$this->node = $node;
2420
$this->clockSeq = $clockSeq;
2521
}
2622

27-
/**
28-
* @return string
29-
*/
30-
public function generateRequestId()
23+
public function generateRequestId(): string
3124
{
3225
return $this->factory->uuid1($this->node, $this->clockSeq)->toString();
3326
}

src/Generator/RamseyUuid3Generator.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,17 @@
77
final class RamseyUuid3Generator implements GeneratorInterface
88
{
99
private $ns;
10-
1110
private $name;
12-
1311
private $factory;
1412

15-
/**
16-
* @param UuidFactoryInterface $factory
17-
* @param string $ns
18-
* @param string $name
19-
*/
20-
public function __construct(UuidFactoryInterface $factory, $ns, $name)
13+
public function __construct(UuidFactoryInterface $factory, string $ns, string $name)
2114
{
2215
$this->factory = $factory;
2316
$this->ns = $ns;
2417
$this->name = $name;
2518
}
2619

27-
/**
28-
* @return string
29-
*/
30-
public function generateRequestId()
20+
public function generateRequestId(): string
3121
{
3222
return $this->factory->uuid3($this->ns, $this->name)->toString();
3323
}

src/Generator/RamseyUuid4Generator.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ public function __construct(UuidFactoryInterface $factory)
1313
$this->factory = $factory;
1414
}
1515

16-
/**
17-
* @return string
18-
*/
19-
public function generateRequestId()
16+
public function generateRequestId(): string
2017
{
2118
return $this->factory->uuid4()->toString();
2219
}

src/Generator/RamseyUuid4StaticGenerator.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
final class RamseyUuid4StaticGenerator implements GeneratorInterface
88
{
9-
/**
10-
* @return string
11-
*/
12-
public function generateRequestId()
9+
public function generateRequestId(): string
1310
{
1411
return Uuid::uuid4()->toString();
1512
}

src/Generator/RamseyUuid5Generator.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,17 @@
77
final class RamseyUuid5Generator implements GeneratorInterface
88
{
99
private $ns;
10-
1110
private $name;
12-
1311
private $factory;
1412

15-
/**
16-
* @param UuidFactoryInterface $factory
17-
* @param string $ns
18-
* @param string $name
19-
*/
20-
public function __construct(UuidFactoryInterface $factory, $ns, $name)
13+
public function __construct(UuidFactoryInterface $factory, string $ns, string $name)
2114
{
2215
$this->factory = $factory;
2316
$this->ns = $ns;
2417
$this->name = $name;
2518
}
2619

27-
/**
28-
* @return string
29-
*/
30-
public function generateRequestId()
20+
public function generateRequestId(): string
3121
{
3222
return $this->factory->uuid5($this->ns, $this->name)->toString();
3323
}

src/MonologProcessor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function __construct(RequestIdProviderInterface $requestIdProvider)
1515
$this->requestIdProvider = $requestIdProvider;
1616
}
1717

18-
public function __invoke(array $record)
18+
public function __invoke(array $record): array
1919
{
2020
try {
2121
$requestId = $this->requestIdProvider->getRequestId();

src/OverridePolicy/OverridePolicyInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
interface OverridePolicyInterface
88
{
9-
public function isAllowToOverride(ServerRequestInterface $request);
9+
public function isAllowToOverride(ServerRequestInterface $request): bool;
1010
}

src/RequestDecorator.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@ final class RequestDecorator
99
protected $requestIdProvider;
1010
protected $headerName;
1111

12-
public function __construct(RequestIdProviderInterface $requestIdProvider, $headerName = RequestIdMiddleware::DEFAULT_RESPONSE_HEADER)
12+
public function __construct(RequestIdProviderInterface $requestIdProvider, string $headerName = RequestIdMiddleware::DEFAULT_RESPONSE_HEADER)
1313
{
1414
$this->requestIdProvider = $requestIdProvider;
1515
$this->headerName = $headerName;
1616
}
1717

1818
/**
1919
* Adds request id to request and return new instance
20-
*
21-
* @param RequestInterface $request
22-
*
23-
* @return RequestInterface
2420
*/
25-
public function decorate(RequestInterface $request)
21+
public function decorate(RequestInterface $request): RequestInterface
2622
{
2723
return $request->withHeader($this->headerName, $this->requestIdProvider->getRequestId());
2824
}

0 commit comments

Comments
 (0)