Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for PHP 7 #327

Open
wants to merge 3 commits into
base: 6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- uses: shivammathur/setup-php@v2
with:
php-version: 7.2
php-version: 8.0
extensions: curl, mbstring
coverage: none
tools: composer:v2, cs2pr
Expand All @@ -27,16 +27,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.2', '7.3', '7.4']
php: ['8.0', '8.1', '8.2']
coverage: [true]
composer-flags: ['']
include:
- php: '8.0'
coverage: false
composer-flags: '--ignore-platform-req=php'
- php: '7.2'
coverage: false
composer-flags: '--prefer-lowest'

steps:
- uses: actions/checkout@v2
Expand All @@ -52,10 +49,6 @@ jobs:

- run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: "Use PHPUnit 9.3+ on PHP 8"
run: composer require --no-update --dev phpunit/phpunit:^9.3
if: "matrix.php == '8.0'"

- run: composer update --no-progress ${{ matrix.composer-flags }}

- run: vendor/bin/phpunit --no-coverage
Expand All @@ -76,7 +69,7 @@ jobs:

- uses: shivammathur/setup-php@v2
with:
php-version: 7.2
php-version: 8.0
extensions: curl, mbstring
coverage: none
tools: composer:v2
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"php": "^8.0",
"nikic/fast-route": "^1.3",
"psr/container": "^1.0|^2.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0.1",
"psr/http-server-handler": "^1.0.1",
"psr/http-server-middleware": "^1.0.1",
"opis/closure": "^3.5.5",
"psr/simple-cache": "^1.0"
"psr/simple-cache": "^2.0|^3.0"
},
"require-dev": {
"laminas/laminas-diactoros": "^2.3",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^8.5",
"roave/security-advisories": "dev-master",
"scrutinizer/ocular": "^1.8",
Expand Down
16 changes: 2 additions & 14 deletions src/Cache/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,11 @@

class FileCache implements CacheInterface
{
/**
* @var string
*/
protected $cacheFilePath;

/**
* @var integer
*/
protected $ttl;

public function __construct(string $cacheFilePath, int $ttl)
public function __construct(protected string $cacheFilePath, protected int $ttl)
{
$this->cacheFilePath = $cacheFilePath;
$this->ttl = $ttl;
}

public function get($key, $default = null)
public function get(string $key, mixed $default = null): mixed
{
return ($this->has($key)) ? file_get_contents($this->cacheFilePath) : $default;
}
Expand Down
19 changes: 2 additions & 17 deletions src/Cache/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,11 @@ class Router
*/
protected $builder;

/**
* @var CacheInterface
*/
protected $cache;

/**
* @var integer
*/
protected $ttl;

/**
* @var bool
*/
protected $cacheEnabled;
protected int $ttl;

public function __construct(callable $builder, CacheInterface $cache, bool $cacheEnabled = true)
public function __construct(callable $builder, protected CacheInterface $cache, protected bool $cacheEnabled = true)
{
$this->builder = $builder;
$this->cache = $cache;
$this->cacheEnabled = $cacheEnabled;
}

public function dispatch(ServerRequestInterface $request): ResponseInterface
Expand Down
5 changes: 1 addition & 4 deletions src/ContainerAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

trait ContainerAwareTrait
{
/**
* @var ?ContainerInterface
*/
protected $container;
protected ?ContainerInterface $container = null;

public function getContainer(): ?ContainerInterface
{
Expand Down
27 changes: 4 additions & 23 deletions src/Http/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,13 @@

class Exception extends \Exception implements HttpExceptionInterface
{
/**
* @var array
*/
protected $headers = [];

/**
* @var string
*/
protected $message;

/**
* @var integer
*/
protected $status;

public function __construct(
int $status,
string $message = null,
protected int $status,
protected $message = null,
\Exception $previous = null,
array $headers = [],
protected array $headers = [],
int $code = 0
) {
$this->headers = $headers;
$this->message = $message;
$this->status = $status;

parent::__construct($message, $code, $previous);
}

Expand All @@ -61,7 +42,7 @@ public function buildJsonResponse(ResponseInterface $response): ResponseInterfac
$response->getBody()->write(json_encode([
'status_code' => $this->status,
'reason_phrase' => $this->message
]));
], JSON_THROW_ON_ERROR));
}

return $response->withStatus($this->status, $this->message);
Expand Down
5 changes: 1 addition & 4 deletions src/Http/Response/Decorator/DefaultHeaderDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class DefaultHeaderDecorator
{
/**
* @var array
*/
protected $headers = [];
protected array $headers = [];

public function __construct(array $headers = [])
{
Expand Down
5 changes: 1 addition & 4 deletions src/Middleware/MiddlewareAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

trait MiddlewareAwareTrait
{
/**
* @var array
*/
protected $middleware = [];
protected array $middleware = [];

public function getMiddlewareStack(): iterable
{
Expand Down
26 changes: 4 additions & 22 deletions src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,20 @@ class Route implements
*/
protected $handler;

/**
* @var RouteGroup
*/
protected $group;

/**
* @var string
*/
protected $method;
protected ?RouteGroup $group = null;

/**
* @var string
*/
protected $path;

/**
* @var array
*/
protected $vars = [];
protected array $vars = [];

public function __construct(string $method, string $path, $handler)
public function __construct(protected string $method, protected string $path, $handler)
{
$this->method = $method;
$this->path = $path;
$this->handler = $handler;
}

public function getCallable(?ContainerInterface $container = null): callable
{
$callable = $this->handler;

if (is_string($callable) && strpos($callable, '::') !== false) {
if (is_string($callable) && str_contains($callable, '::')) {
$callable = explode('::', $callable);
}

Expand Down
26 changes: 7 additions & 19 deletions src/RouteConditionHandlerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,13 @@

trait RouteConditionHandlerTrait
{
/**
* @var ?string
*/
protected $host;

/**
* @var ?string
*/
protected $name;

/**
* @var ?int
*/
protected $port;

/**
* @var ?string
*/
protected $scheme;
protected ?string $host = null;

protected ?string $name = null;

protected ?int $port = null;

protected ?string $scheme = null;

public function getHost(): ?string
{
Expand Down
13 changes: 2 additions & 11 deletions src/RouteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,11 @@ class RouteGroup implements
*/
protected $callback;

/**
* @var RouteCollectionInterface
*/
protected $collection;

/**
* @var string
*/
protected $prefix;
protected string $prefix;

public function __construct(string $prefix, callable $callback, RouteCollectionInterface $collection)
public function __construct(string $prefix, callable $callback, protected RouteCollectionInterface $collection)
{
$this->callback = $callback;
$this->collection = $collection;
$this->prefix = sprintf('/%s', ltrim($prefix, '/'));
}

Expand Down
39 changes: 12 additions & 27 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,35 @@ class Router implements
/**
* @var RouteGroup[]
*/
protected $groups = [];
protected array $groups = [];

/**
* @var Route[]
*/
protected $namedRoutes = [];
protected array $namedRoutes = [];

/**
* @var array
*/
protected $patternMatchers = [
protected array $patternMatchers = [
'/{(.+?):number}/' => '{$1:[0-9]+}',
'/{(.+?):word}/' => '{$1:[a-zA-Z]+}',
'/{(.+?):alphanum_dash}/' => '{$1:[a-zA-Z0-9-_]+}',
'/{(.+?):slug}/' => '{$1:[a-z0-9-]+}',
'/{(.+?):uuid}/' => '{$1:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}+}'
];

/**
* @var RouteCollector
*/
protected $routeCollector;

/**
* @var Route[]
*/
protected $routes = [];
protected array $routes = [];

/**
* @var bool
*/
protected $routesPrepared = false;
protected bool $routesPrepared = false;

/**
* @var array
*/
protected $routesData = [];
protected array $routesData = [];

public function __construct(?RouteCollector $routeCollector = null)
public function __construct(protected RouteCollector $routeCollector = new RouteCollector(
new RouteParser\Std(),
new DataGenerator\GroupCountBased()
))
{
$this->routeCollector = $routeCollector ?? new RouteCollector(
new RouteParser\Std(),
new DataGenerator\GroupCountBased()
);
}

public function addPatternMatcher(string $alias, string $regex): self
Expand Down Expand Up @@ -150,7 +135,7 @@ public function prepareRoutes(ServerRequestInterface $request): void
$this->processGroups($request);
$this->buildNameIndex();

$routes = array_merge(array_values($this->routes), array_values($this->namedRoutes));
$routes = [...array_values($this->routes), ...array_values($this->namedRoutes)];
$options = [];

/** @var Route $route */
Expand Down Expand Up @@ -249,7 +234,7 @@ protected function processGroups(ServerRequestInterface $request): void
// route is not matched so exceptions are handled correctly
if (
$group->getStrategy() !== null
&& strncmp($activePath, $group->getPrefix(), strlen($group->getPrefix())) === 0
&& str_starts_with($activePath, $group->getPrefix())
) {
$this->setStrategy($group->getStrategy());
}
Expand Down
5 changes: 1 addition & 4 deletions src/Strategy/AbstractStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

abstract class AbstractStrategy implements StrategyInterface
{
/**
* @var array
*/
protected $responseDecorators = [];
protected array $responseDecorators = [];

public function addResponseDecorator(callable $decorator): StrategyInterface
{
Expand Down
Loading