Skip to content

Commit

Permalink
Merge branch '2.9' into update-rector-01213
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster authored Jan 26, 2022
2 parents 57fd298 + 2724356 commit b78e5c4
Show file tree
Hide file tree
Showing 113 changed files with 1,158 additions and 393 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.0] # Note: This workflow requires only the LATEST version of PHP
php: ['8.0'] # Note: This workflow requires only the LATEST version of PHP
os: [ubuntu-latest]

steps:
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.0] # Note: This workflow requires only the LATEST version of PHP
php: ['8.0'] # Note: This workflow requires only the LATEST version of PHP
os: [ubuntu-latest]

steps:
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.0] # Note: This workflow requires only the LATEST version of PHP
php: ['8.0'] # Note: This workflow requires only the LATEST version of PHP
os: [ubuntu-latest]

steps:
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', '7.4', '8.0']
php: ['7.2', '7.3', '7.4', '8.0', '8.1']
os: [ubuntu-latest]
stability: [prefer-lowest, prefer-stable]

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
- **Medium Impact Changes**
- Component `spiral/annotations` is deprecated. Use `spiral/attributes` instead
- A minimal version of `doctrine/annotations` increased to `^1.12`
- [spiral/validation] Error messages for 'number::lower' and
'number::higher' rules were changed to reflect that these checks are in
fact 'lower or equal' and 'higher or equal'. You may need to adjust
translations file accordingly.
- **Other Features**
- [spiral/validation] Add array::count, array::range, array::shorter and array::longer rules (#435)
- **Bug Fixes**

## v2.8.0 - 2021-06-03
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"defuse/php-encryption": "^2.2",
"doctrine/annotations": "^1.12",
"doctrine/inflector": "^1.4|^2.0",
"laminas/laminas-diactoros": "^2.4",
"league/flysystem": "^2.0",
"monolog/monolog": "^2.2",
"myclabs/deep-copy": "^1.9",
Expand All @@ -39,7 +40,7 @@
"psr/log": "^1.0",
"psr/simple-cache": ">=1.0",
"spiral/composer-publish-plugin": "^1.0",
"symfony/console": "^5.1",
"symfony/console": "^5.3",
"symfony/finder": "^5.1",
"symfony/mailer": "^5.1",
"symfony/polyfill-php73": "^1.22",
Expand Down Expand Up @@ -127,13 +128,13 @@
"cycle/schema-builder": "^1.1",
"guzzlehttp/psr7": "^1.7",
"jetbrains/phpstorm-attributes": "^1.0",
"laminas/laminas-diactoros": "^2.3",
"laminas/laminas-hydrator": "^3.0|^4.0",
"league/flysystem-async-aws-s3": "^2.0",
"league/flysystem-aws-s3-v3": "^2.0",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^8.5|^9.0",
"ramsey/uuid": "^3.9",
"ramsey/uuid": "^4.2",
"rector/rector": "0.12.15",
"spiral/broadcast": "^2.0",
"spiral/broadcast-ws": "^1.0",
Expand Down Expand Up @@ -267,7 +268,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.8.x-dev"
"dev-master": "2.9.x-dev"
}
},
"config": {
Expand Down
5 changes: 3 additions & 2 deletions monorepo-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
],
],
'require' => [
'laminas/laminas-diactoros' => '^2.4',
'spiral/composer-publish-plugin' => '^1.0',
],
'autoload-dev' => [
Expand All @@ -87,14 +88,14 @@
'mockery/mockery' => '^1.3',
'spiral/code-style' => '^1.0',
'spiral/database' => '^2.7.3',
'spiral/migrations' => '^2.1',
'spiral/migrations' => '^2.2',
'spiral/roadrunner' => '^1.9.2',
'spiral/php-grpc' => '^1.4',
'spiral/jobs' => '^2.2',
'spiral/broadcast' => '^2.0',
'spiral/broadcast-ws' => '^1.0',
'cycle/orm' => '^1.2.6',
'laminas/laminas-hydrator' => '^3.0',
'laminas/laminas-hydrator' => '^3.0|^4.0',
'cycle/annotated' => '^2.0.6',
'cycle/migrations' => '^1.0.1',
'cycle/proxy-factory' => '^1.2',
Expand Down
9 changes: 5 additions & 4 deletions src/AnnotatedRoutes/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
],
"require": {
"php": ">=7.2",
"spiral/router": "^2.8",
"spiral/annotations": "^2.8"
"spiral/annotations": "^2.9",
"spiral/attributes": "^2.9",
"spiral/router": "^2.9"
},
"require-dev": {
"phpunit/phpunit": "^8.5|^9.0",
"mockery/mockery": "^1.3",
"laminas/laminas-diactoros": "^2.3"
"laminas/laminas-diactoros": "^2.4"
},
"autoload": {
"psr-4": {
Expand All @@ -36,7 +37,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.8.x-dev"
"dev-master": "2.9.x-dev"
}
},
"config": {
Expand Down
20 changes: 14 additions & 6 deletions src/AnnotatedRoutes/src/Annotation/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
* @Target({"METHOD"})
* @Attributes({
* @Attribute("route", required=true, type="string"),
* @Attribute("name", required=true, type="string"),
* @Attribute("name", type="string"),
* @Attribute("verbs", required=true, type="mixed"),
* @Attribute("defaults", type="array"),
* @Attribute("group", type="string"),
* @Attribute("middleware", type="array")
* @Attribute("middleware", type="array"),
* @Attribute("priority", type="int")
* })
*/
#[\Attribute(\Attribute::TARGET_METHOD), NamedArgumentConstructor]
Expand All @@ -40,7 +41,7 @@ final class Route
public $route;

/**
* @var string
* @var null|string
*/
public $name;

Expand Down Expand Up @@ -70,25 +71,32 @@ final class Route
*/
public $middleware = [];

/**
* @var int
*/
public $priority;

/**
* @psalm-param non-empty-string $route
* @psalm-param non-empty-string $name
* @psalm-param non-empty-string|null $name
* @psalm-param non-empty-string|array<string> $methods
* @psalm-param non-empty-string $group
*/
public function __construct(
string $route,
string $name,
string $name = null,
$methods = \Spiral\Router\Route::VERBS,
array $defaults = [],
string $group = self::DEFAULT_GROUP,
array $middleware = []
array $middleware = [],
int $priority = 0
) {
$this->route = $route;
$this->name = $name;
$this->methods = $methods;
$this->defaults = $defaults;
$this->group = $group;
$this->middleware = $middleware;
$this->priority = $priority;
}
}
2 changes: 1 addition & 1 deletion src/AnnotatedRoutes/src/GroupRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getGroup(string $name): RouteGroup
/**
* @return RouteGroup[]|\ArrayIterator
*/
public function getIterator()
public function getIterator(): \Traversable
{
return new \ArrayIterator($this->groups);
}
Expand Down
18 changes: 18 additions & 0 deletions src/AnnotatedRoutes/src/RouteLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function findDeclarations(): array
continue;
}

$route->name = $route->name ?? $this->generateName($route);
$result[$route->name] = [
'pattern' => $route->route,
'controller' => $class->getName(),
Expand All @@ -48,10 +49,27 @@ public function findDeclarations(): array
'verbs' => (array) $route->methods,
'defaults' => $route->defaults,
'middleware' => (array) $route->middleware,
'priority' => $route->priority,
];
}
}

\uasort($result, static function (array $route1, array $route2) {
return $route1['priority'] <=> $route2['priority'];
});

return $result;
}

/**
* Generates route name based on declared methods and route.
*/
private function generateName(Route $route): string
{
$methods = \is_array($route->methods)
? \implode(',', $route->methods)
: $route->methods;

return \mb_strtolower(\sprintf('%s:%s', $methods, $route->route));
}
}
6 changes: 6 additions & 0 deletions src/AnnotatedRoutes/tests/App/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public function method()
{
return 'method';
}

#[Route(route: '/attribute', name: 'attribute', methods: 'GET', group: 'test')]
public function attribute()
{
return 'attribute';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* Spiral Framework.
*
* @license MIT
* @author Vladislav Gorenkin (vladgorenkin)
*/

declare(strict_types=1);

namespace Spiral\Tests\Router\App\Controller;

use Spiral\Router\Annotation\Route;

class NamelessRoutesController
{
/**
* @Route(route="/nameless", methods="GET")
*/
public function index()
{
return 'index';
}

/**
* @Route(route="/nameless", methods="POST")
*/
public function method()
{
return 'method';
}

/**
* @Route(route="/nameless/route", methods={"GET", "POST"})
*/
public function route()
{
return 'route';
}
}
26 changes: 26 additions & 0 deletions src/AnnotatedRoutes/tests/App/Controller/PageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Spiral\Tests\Router\App\Controller;

use Spiral\Router\Annotation\Route;

final class PageController
{
/**
* @Route("/page/<page>", name="page_get", methods="GET")
*/
public function get($page)
{
return 'page-'.$page;
}

/**
* @Route("/page/about", name="page_about", methods="GET", priority=-1)
*/
public function about()
{
return 'about';
}
}
36 changes: 0 additions & 36 deletions src/AnnotatedRoutes/tests/App/runtime/cache/routes.php

This file was deleted.

Loading

0 comments on commit b78e5c4

Please sign in to comment.