generated from yii-tools/template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d81dda
commit 8c746a2
Showing
18 changed files
with
837 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
return [ | ||
'yii-tools/middleware' => [ | ||
'locale' => [ | ||
'languages' => [], | ||
'ignoredUrls' => [], | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Yii\Middleware\Guest; | ||
use Yiisoft\Definitions\DynamicReference; | ||
use Yiisoft\User\CurrentUser; | ||
|
||
return [ | ||
Guest::class => [ | ||
'__construct()' => [ | ||
'isGuest' => DynamicReference::to(static fn (CurrentUser $currentUser): bool => $currentUser->isGuest()), | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Yii\Middleware\Locale; | ||
|
||
/** @var array $params */ | ||
|
||
return [ | ||
Locale::class => [ | ||
'__construct()' => [ | ||
'languages' => $params['yii-tools/middleware']['locale']['languages'], | ||
'ignoredUrls' => $params['yii-tools/middleware']['locale']['ignoredUrls'], | ||
], | ||
], | ||
]; |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Testing | ||
|
||
## Checking dependencies | ||
|
||
This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if all dependencies are correctly defined in `composer.json`. | ||
|
||
To run the checker, execute the following command: | ||
|
||
```shell | ||
composer run check-dependencies | ||
``` | ||
|
||
## Mutation testing | ||
|
||
Mutation testing is checked with [Infection](https://infection.github.io/). To run it: | ||
|
||
```shell | ||
composer run mutation | ||
``` | ||
|
||
## Static analysis | ||
|
||
The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis: | ||
|
||
```shell | ||
composer run psalm | ||
``` | ||
|
||
## Unit tests | ||
|
||
The code is tested with [PHPUnit](https://phpunit.de/). To run tests: | ||
|
||
``` | ||
composer run test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<phpunit | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
stopOnFailure="false" | ||
verbose="true" | ||
> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" cacheDirectory=".phpunit.cache"> | ||
<php> | ||
<ini name="error_reporting" value="-1" /> | ||
<ini name="error_reporting" value="-1"/> | ||
</php> | ||
|
||
<coverage> | ||
<coverage/> | ||
<testsuites> | ||
<testsuite name="Template"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory>./src</directory> | ||
</include> | ||
<exclude> | ||
<directory>./vendor</directory> | ||
</exclude> | ||
</coverage> | ||
|
||
<testsuites> | ||
<testsuite name="Template"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</source> | ||
</phpunit> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yii\Middleware; | ||
|
||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use Yiisoft\Http\Header; | ||
use Yiisoft\Http\Status; | ||
|
||
/** | ||
* Middleware that checks if the user is a guest. | ||
*/ | ||
final class Guest implements MiddlewareInterface | ||
{ | ||
public function __construct( | ||
private readonly bool $isGuest, | ||
private readonly ResponseFactoryInterface $responseFactory | ||
) { | ||
} | ||
|
||
/** | ||
* Process a server request and return a response. | ||
*/ | ||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
if ($this->isGuest === false) { | ||
return $this->responseFactory->createResponse(Status::FOUND)->withHeader(Header::LOCATION, '/'); | ||
} | ||
|
||
return $handler->handle($request); | ||
} | ||
} |
Oops, something went wrong.