Skip to content

Commit

Permalink
Merge pull request #45 from gsteel/PHP-8.2
Browse files Browse the repository at this point in the history
Add PHP 8.2 Support, Drop PHP 7.4 Support
  • Loading branch information
Ocramius authored Oct 10, 2022
2 parents 0843f71 + a2eeb00 commit 84aa104
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ignore_php_platform_requirements": {
"8.1": true
}
"ignore_php_platform_requirements": {
"8.2": true
}
}
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"config": {
"sort-packages": true,
"platform": {
"php": "7.4.99"
"php": "8.0.99"
},
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
Expand All @@ -31,17 +31,17 @@
}
},
"require": {
"php": "^7.4 || ~8.0.0 || ~8.1.0",
"php": "~8.0.0 || ~8.1.0 || ~8.2.0",
"laminas/laminas-http": "^2.15",
"laminas/laminas-servicemanager": "^3.14.0",
"laminas/laminas-stdlib": "^3.10.1"
},
"require-dev": {
"laminas/laminas-coding-standard": "~2.4.0",
"laminas/laminas-i18n": "^2.15.0",
"phpunit/phpunit": "^9.5.5",
"laminas/laminas-i18n": "^2.17",
"phpunit/phpunit": "^9.5.25",
"psalm/plugin-phpunit": "^0.17.0",
"vimeo/psalm": "^4.24.0"
"vimeo/psalm": "^4.28"
},
"suggest": {
"laminas/laminas-i18n": "^2.15.0 if defining translatable HTTP path segments"
Expand Down
20 changes: 10 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.24.0@06dd975cb55d36af80f242561738f16c5f58264f">
<files psalm-version="4.28.0@52e96bea381e6cb07a672aefec791a5817694a26">
<file src="src/Http/Chain.php">
<InvalidReturnStatement occurrences="1"/>
<InvalidReturnType occurrences="1">
Expand Down Expand Up @@ -1111,6 +1111,9 @@
<code>testSetRoutesWithInvalidArgument</code>
<code>testremoveRouteAsArray</code>
</MissingReturnType>
<NoInterfaceProperties occurrences="1">
<code>$route-&gt;priority</code>
</NoInterfaceProperties>
<PossiblyNullReference occurrences="4">
<code>getParam</code>
<code>getParam</code>
Expand Down
8 changes: 8 additions & 0 deletions src/Http/Hostname.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ class Hostname implements RouteInterface
*/
protected $assembledParams = [];

/**
* @internal
* @deprecated Since 3.9.0 This property will be removed or made private in version 4.0
*
* @var int|null
*/
public $priority;

/**
* Create a new hostname route.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Http/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class Method implements RouteInterface
*/
protected $defaults;

/**
* @internal
* @deprecated Since 3.9.0 This property will be removed or made private in version 4.0
*
* @var int|null
*/
public $priority;

/**
* Create a new method route.
*
Expand Down
10 changes: 0 additions & 10 deletions src/Http/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ class Part extends TreeRouteStack implements RouteInterface
*/
protected $childRoutes;

/**
* Priority.
*
* @internal For internal classes only. Not designed for general use.
* @deprecated Since 3.9.0 This property will be removed or made private in version 4.0
*
* @var int|null
*/
public $priority;

/**
* Create a new part route.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Http/Placeholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class Placeholder implements RouteInterface
{
private array $defaults;

/**
* @internal
* @deprecated Since 3.9.0 This property will be removed or made private in version 4.0
*
* @var int|null
*/
public $priority;

public function __construct(array $defaults)
{
$this->defaults = $defaults;
Expand Down
8 changes: 8 additions & 0 deletions src/Http/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class Regex implements RouteInterface
*/
protected $assembledParams = [];

/**
* @internal
* @deprecated Since 3.9.0 This property will be removed or made private in version 4.0
*
* @var int|null
*/
public $priority;

/**
* Create a new regex route.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Http/Scheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class Scheme implements RouteInterface
*/
protected $defaults;

/**
* @internal
* @deprecated Since 3.9.0 This property will be removed or made private in version 4.0
*
* @var int|null
*/
public $priority;

/**
* Create a new scheme route.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Http/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ class Segment implements RouteInterface
*/
protected $translationKeys = [];

/**
* @internal
* @deprecated Since 3.9.0 This property will be removed or made private in version 4.0
*
* @var int|null
*/
public $priority;

/**
* Create a new regex route.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Http/TreeRouteStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class TreeRouteStack extends SimpleRouteStack
*/
protected $prototypes;

/**
* @internal
* @deprecated Since 3.9.0 This property will be removed or made private in version 4.0
*
* @var int|null
*/
public $priority;

/**
* factory(): defined by RouteInterface interface.
*
Expand Down
3 changes: 1 addition & 2 deletions src/RoutePluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Psr\Container\ContainerInterface;

use function array_merge;
use function get_class;
use function gettype;
use function is_object;
use function sprintf;
Expand Down Expand Up @@ -83,7 +82,7 @@ public function validate($instance)
if (! $instance instanceof $this->instanceOf) {
throw new InvalidServiceException(sprintf(
'Plugin of type %s is invalid; must implement %s',
is_object($instance) ? get_class($instance) : gettype($instance),
is_object($instance) ? $instance::class : gettype($instance),
RouteInterface::class
));
}
Expand Down
3 changes: 3 additions & 0 deletions test/Http/PartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ public function testPartRouteMarkedAsMayTerminateButWithQueryRouteChildWillMatch
$request->setQuery($query);
$query = $request->getQuery();

/** @link https://github.com/laminas/laminas-router/commit/66ebd439067d9e25a6f7941de4b9ebc9c52524f5 */
$this->markTestSkipped('This test fails and has been skipped because the Query route has been deprecated (?)');

/*
$match = $route->match($request);
$this->assertInstanceOf(\Laminas\Router\RouteMatch::class, $match);
Expand Down
115 changes: 115 additions & 0 deletions test/SimpleRouteStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
use ArrayIterator;
use Laminas\Router\Exception\InvalidArgumentException;
use Laminas\Router\Exception\RuntimeException;
use Laminas\Router\Http\Chain;
use Laminas\Router\Http\Hostname;
use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Method;
use Laminas\Router\Http\Placeholder;
use Laminas\Router\Http\Regex;
use Laminas\Router\Http\Scheme;
use Laminas\Router\Http\Segment;
use Laminas\Router\RouteMatch;
use Laminas\Router\RoutePluginManager;
use Laminas\Router\SimpleRouteStack;
Expand Down Expand Up @@ -280,4 +288,111 @@ public function testHasRoute()
$stack->addRoute('foo', new TestAsset\DummyRoute());
$this->assertEquals(true, $stack->hasRoute('foo'));
}

/** @return array<class-string, array{0: array, 1: int}> */
public function routeTypeProvider(): array
{
$routePlugins = new RoutePluginManager(new ServiceManager());
return [
Chain::class => [
[
'type' => Chain::class,
'priority' => 1,
'options' => [
'routes' => [],
'route_plugins' => $routePlugins,
],
],
1,
],
Hostname::class => [
[
'type' => Hostname::class,
'options' => [
'route' => 'www.example.com',
'defaults' => [
'controller' => 'SomeController',
'action' => 'index',
],
],
'priority' => 5,
],
5,
],
Literal::class => [
[
'type' => Literal::class,
'options' => [
'route' => '/blah',
'defaults' => [
'controller' => 'SomeController',
'action' => 'index',
],
],
'priority' => 10,
],
10,
],
Method::class => [
[
'type' => Method::class,
'options' => [
'route' => '/duck',
'verb' => 'QUACK',
],
'priority' => 20,
],
20,
],
Placeholder::class => [
[
'type' => Placeholder::class,
'options' => [],
'priority' => 30,
],
30,
],
Regex::class => [
[
'type' => Regex::class,
'options' => [
'regex' => '/(?<foo>[^/]+)',
'spec' => '/%foo%',
],
'priority' => 40,
],
40,
],
Scheme::class => [
[
'type' => Scheme::class,
'options' => [
'scheme' => 'carrots',
],
'priority' => 50,
],
50,
],
Segment::class => [
[
'type' => Segment::class,
'options' => [
'route' => '/mushrooms',
],
'priority' => 60,
],
60,
],
];
}

/** @dataProvider routeTypeProvider */
public function testSimpleRouteStackSetsPriorityForAllKnownRouteTypes(array $routeSpec, int $expectedPriority): void
{
$router = new SimpleRouteStack();
$router->addRoute('name', $routeSpec);

$route = $router->getRoute('name');
self::assertEquals($expectedPriority, $route->priority);
}
}

0 comments on commit 84aa104

Please sign in to comment.