Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into route-attr
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
  • Loading branch information
vjik committed Jan 28, 2024
2 parents cf774cf + 5bc9a72 commit bf17649
Show file tree
Hide file tree
Showing 27 changed files with 672 additions and 478 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ name: rector
jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
secrets:
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
['8.2']
11 changes: 10 additions & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'phpunit.xml.dist'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -28,4 +29,12 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1']
['8.1', '8.2', '8.3']
psalm80:
uses: yiisoft/actions/.github/workflows/psalm.yml@master
with:
psalm-config: psalm80.xml
os: >-
['ubuntu-latest']
php: >-
['8.0']
9 changes: 4 additions & 5 deletions .phpstorm.meta.php/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
'host',
'hosts',
'corsMiddleware',
'items',
'middlewareDefinitions',
'hasDispatcher',
'hasCorsMiddleware'
'routes',
'hasCorsMiddleware',
'enabledMiddlewares',
);
}
}
11 changes: 5 additions & 6 deletions .phpstorm.meta.php/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
registerArgumentsSet(
'routeDataKeys',
'name',
'pattern',
'host',
'hosts',
'pattern',
'methods',
'override',
'defaults',
'dispatcherWithMiddlewares',
'hasDispatcher',
'hasMiddlewares'
'override',
'hasMiddlewares',
'enabledMiddlewares',
);
}
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- New #195: Add debug collector for `yiisoft/yii-debug` (@xepozz)
- Chg #207: Replace two `RouteCollectorInterface` methods `addRoute()` and `addGroup()` to single `addRoute()` (@vjik)
- Enh #202: Add support for `psr/http-message` version `^2.0` (@vjik)
- Chg #222: Make `Route`, `Group` and `MatchingResult` dispatcher-independent (@rustamwin, @vjik)
- Enh #229: Add URL arguments' psalm type in `UrlGeneratorInterface` (@vjik)

## 3.0.0 February 17, 2023

Expand Down
34 changes: 34 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Upgrading Instructions for Yii Router

This file contains the upgrade notes for the Yii Router.
These notes highlight changes that could break your application when you upgrade it from one major version to another.

## 4.0.0

In this release classes `Route`, `Group` and `MatchingResult` are made dispatcher-independent. Now you don't can inject
own middleware dispatcher to group or to route.

The following backward incompatible changes have been made.

### `Route`

- Removed parameter `$dispatcher` from `Route` creating methods: `get()`, `post()`, `put()`, `delete()`, `patch()`,
`head()`, `options()`, `methods()`.
- Removed methods `Route::injectDispatcher()` and `Route::withDispatcher()`.
- `Route::getData()` changes:
- removed elements `dispatcherWithMiddlewares` and `hasDispatcher`;
- added element `enabledMiddlewares`.

### `Group`

- Removed parameter `$dispatcher` from `Group::create()` method.
- Removed method `Group::withDispatcher()`.
- `Group::getData()` changes:
- removed element `hasDispatcher`;
- key `items` renamed to `routes`;
- key `middlewareDefinitions` renamed to `enabledMiddlewares`.

### `MatchingResult`

- Removed `MatchingResult` implementation from `MiddlewareInterface`, so it is no longer middleware.
- Removed method `MatchingResult::process()`.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
"nyholm/psr7": "^1.5",
"phpunit/phpunit": "^9.5",
"psr/container": "^1.1|^2.0",
"rector/rector": "^0.18.3",
"rector/rector": "^0.19.0",
"roave/infection-static-analysis-plugin": "^1.18",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.6",
"vimeo/psalm": "^4.30|^5.20",
"yiisoft/di": "^1.0",
"yiisoft/dummy-provider": "^1.0.0",
"yiisoft/yii-debug": "dev-master",
"yiisoft/hydrator": "dev-master as 1.0",
"yiisoft/test-support": "^3.0"
"yiisoft/hydrator": "dev-master",
"yiisoft/test-support": "^3.0",
"yiisoft/yii-debug": "dev-master|dev-php80"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 5 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor"/>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
<RiskyTruthyFalsyComparison errorLevel="suppress" />
</issueHandlers>
</psalm>
19 changes: 19 additions & 0 deletions psalm80.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
</issueHandlers>
</psalm>
8 changes: 4 additions & 4 deletions src/Debug/DebugRoutesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$data = $route->__debugInfo();
$action = '';
$middlewares = [];
if (!empty($data['middlewareDefinitions'])) {
$middlewareDefinitions = $data['middlewareDefinitions'];
if (!empty($data['enabledMiddlewares'])) {
$middlewareDefinitions = $data['enabledMiddlewares'];
$action = array_pop($middlewareDefinitions);
$middlewares = $middlewareDefinitions;
}
Expand Down Expand Up @@ -91,8 +91,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($this->routeCollection->getRoutes() as $route) {
$data = $route->__debugInfo();
$action = '';
if (!empty($data['middlewareDefinitions'])) {
$middlewareDefinitions = $data['middlewareDefinitions'];
if (!empty($data['enabledMiddlewares'])) {
$middlewareDefinitions = $data['enabledMiddlewares'];
$action = array_pop($middlewareDefinitions);
}
$rows[] = [
Expand Down
13 changes: 4 additions & 9 deletions src/Debug/RouterCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,10 @@ private function getMiddlewaresAndAction(?Route $route): array
if ($route === null) {
return [[], null];
}
$reflection = new ReflectionObject($route);

$reflectionProperty = $reflection->getProperty('middlewareDefinitions');
$reflectionProperty->setAccessible(true);
/**
* @var array[]|callable[]|string[] $middlewareDefinitions
*/
$middlewareDefinitions = $reflectionProperty->getValue($route);
$action = array_pop($middlewareDefinitions);
return [$middlewareDefinitions, $action];
$middlewares = $route->getData('enabledMiddlewares');
$action = array_pop($middlewares);

return [$middlewares, $action];
}
}
6 changes: 4 additions & 2 deletions src/Debug/UrlMatcherInterfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

final class UrlMatcherInterfaceProxy implements UrlMatcherInterface
{
public function __construct(private UrlMatcherInterface $urlMatcher, private RouterCollector $routerCollector)
{
public function __construct(
private UrlMatcherInterface $urlMatcher,
private RouterCollector $routerCollector
) {
}

public function match(ServerRequestInterface $request): MatchingResult
Expand Down
Loading

0 comments on commit bf17649

Please sign in to comment.