Skip to content

Commit

Permalink
Merge 6.x prep branch
Browse files Browse the repository at this point in the history
  • Loading branch information
philipobenito committed Nov 9, 2024
1 parent b66c107 commit da65872
Show file tree
Hide file tree
Showing 32 changed files with 214 additions and 382 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 4
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Author](https://img.shields.io/badge/[email protected]?style=flat-square)](https://twitter.com/philipobenito)
[![Latest Version](https://img.shields.io/github/release/thephpleague/route.svg?style=flat-square)](https://github.com/thephpleague/route/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/thephpleague/route/master.svg?style=flat-square)](https://travis-ci.org/thephpleague/route)
[![Tests](https://github.com/thephpleague/route/actions/workflows/test.yml/badge.svg)](https://github.com/thephpleague/route/actions/workflows/test.yml)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/thephpleague/route.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/route/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/thephpleague/route.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/route)
[![Total Downloads](https://img.shields.io/packagist/dt/league/route.svg?style=flat-square)](https://packagist.org/packages/league/route)
Expand All @@ -29,10 +29,10 @@ $ composer require league/route

The following versions of PHP are supported by this version.

* PHP 7.2
* PHP 7.3
* PHP 7.4
* PHP 8.0
* PHP 8.1
* PHP 8.2
* PHP 8.3
* PHP 8.4

## Documentation

Expand Down
23 changes: 12 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@
"authors": [
{
"name": "Phil Bennett",
"email": "[email protected]",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": "^7.2 || ^8.0",
"php": "^8.1",
"nikic/fast-route": "^1.3",
"psr/container": "^1.0|^2.0",
"psr/container": "^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"
"opis/closure": "^3.6.3",
"psr/simple-cache": "^3.0"
},
"require-dev": {
"laminas/laminas-diactoros": "^2.3",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpunit/phpunit": "^8.5",
"roave/security-advisories": "dev-master",
"laminas/laminas-diactoros": "^2.10",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^10.2",
"roave/security-advisories": "dev-latest",
"scrutinizer/ocular": "^1.8",
"squizlabs/php_codesniffer": "^3.5"
"squizlabs/php_codesniffer": "^3.7"
},
"replace": {
"orno/route": "~1.0",
Expand All @@ -58,6 +58,7 @@
"extra": {
"branch-alias": {
"dev-master": "5.x-dev",
"dev-6.x": "6.x-dev",
"dev-5.x": "5.x-dev",
"dev-4.x": "4.x-dev",
"dev-3.x": "3.x-dev",
Expand Down
58 changes: 34 additions & 24 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="League Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
testdox="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="League Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
30 changes: 9 additions & 21 deletions src/Cache/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,30 @@

namespace League\Route\Cache;

use Psr\SimpleCache\CacheInterface;
use Psr\SimpleCache\{CacheInterface, InvalidArgumentException};

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;
}

public function set($key, $value, $ttl = null): bool
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool
{
return (bool) file_put_contents($this->cacheFilePath, $value);
}

public function has($key): bool
public function has(string $key): bool
{
return file_exists($this->cacheFilePath) && time() - filemtime($this->cacheFilePath) < $this->ttl;
}

public function delete($key): bool
public function delete(string $key): bool
{
return unlink($this->cacheFilePath);
}
Expand All @@ -49,17 +37,17 @@ public function clear(): bool
return $this->delete($this->cacheFilePath);
}

public function getMultiple($keys, $default = null): iterable
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
return [];
}

public function setMultiple($values, $ttl = null): bool
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool
{
return false;
}

public function deleteMultiple($keys): bool
public function deleteMultiple(iterable $keys): bool
{
return false;
}
Expand Down
19 changes: 5 additions & 14 deletions src/Cache/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,17 @@ class Router
*/
protected $builder;

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

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

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

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
2 changes: 1 addition & 1 deletion src/ContainerAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
interface ContainerAwareInterface
{
public function getContainer(): ?ContainerInterface;
public function setContainer(ContainerInterface $container): ContainerAwareInterface;
public function setContainer(ContainerInterface $container): self;
}
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
4 changes: 2 additions & 2 deletions src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Dispatcher extends GroupCountBasedDispatcher implements
public function dispatchRequest(ServerRequestInterface $request): ResponseInterface
{
$method = $request->getMethod();
$uri = $request->getUri()->getPath();
$match = $this->dispatch($method, $uri);
$uri = $request->getUri()->getPath();
$match = $this->dispatch($method, $uri);

switch ($match[0]) {
case FastRoute::NOT_FOUND:
Expand Down
29 changes: 5 additions & 24 deletions src/Http/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,14 @@

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 = '',
\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);
parent::__construct($this->message, $code, $previous);
}

public function getStatusCode(): int
Expand All @@ -59,7 +40,7 @@ public function buildJsonResponse(ResponseInterface $response): ResponseInterfac

if ($response->getBody()->isWritable()) {
$response->getBody()->write(json_encode([
'status_code' => $this->status,
'status_code' => $this->status,
'reason_phrase' => $this->message
]));
}
Expand Down
16 changes: 16 additions & 0 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace League\Route\Http;

final class Request
{
public const METHOD_GET = 'GET';
public const METHOD_POST = 'POST';
public const METHOD_PUT = 'PUT';
public const METHOD_PATCH = 'PATCH';
public const METHOD_DELETE = 'DELETE';
public const METHOD_HEAD = 'HEAD';
public const METHOD_OPTIONS = 'OPTIONS';
}
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
2 changes: 1 addition & 1 deletion src/Middleware/MiddlewareAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait MiddlewareAwareTrait
/**
* @var array
*/
protected $middleware = [];
protected array $middleware = [];

public function getMiddlewareStack(): iterable
{
Expand Down
Loading

0 comments on commit da65872

Please sign in to comment.