generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add debug stuff to application's fallback handler (#145)
* Wrap application's fallback handler to provider debug headers * Apply fixes from StyleCI * Ignore class * Fix tests * Refactor * Fix test * Add workaround for Subfolder middleware * Fix tests * Fix tests * Add middleware dispatcher --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
cbb26ce
commit 9e86aa5
Showing
9 changed files
with
130 additions
and
5 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
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\Debug\Api\Debug\Http; | ||
|
||
use Closure; | ||
use Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher; | ||
use Yiisoft\Yii\Debug\Api\Debug\Middleware\MiddlewareDispatcherMiddleware; | ||
use Yiisoft\Yii\Http\Application; | ||
|
||
final readonly class HttpApplicationWrapper | ||
{ | ||
public function __construct( | ||
private MiddlewareDispatcher $middlewareDispatcher, | ||
private array $middlewareDefinitions, | ||
) { | ||
} | ||
|
||
public function wrap(Application $application): void | ||
Check failure on line 20 in src/Debug/Http/HttpApplicationWrapper.php GitHub Actions / psalm / PHP 8.1-ubuntu-latestUndefinedClass
Check failure on line 20 in src/Debug/Http/HttpApplicationWrapper.php GitHub Actions / psalm / PHP 8.2-ubuntu-latestUndefinedClass
Check failure on line 20 in src/Debug/Http/HttpApplicationWrapper.php GitHub Actions / psalm / PHP 8.3-ubuntu-latestUndefinedClass
|
||
{ | ||
$middlewareDispatcher = $this->middlewareDispatcher; | ||
$middlewareDefinitions = $this->middlewareDefinitions; | ||
|
||
$closure = Closure::bind(static function (Application $application) use ( | ||
$middlewareDispatcher, | ||
$middlewareDefinitions, | ||
) { | ||
$application->dispatcher = $middlewareDispatcher->withMiddlewares([ | ||
...$middlewareDefinitions, | ||
['class' => MiddlewareDispatcherMiddleware::class, '$middlewareDispatcher' => $application->dispatcher], | ||
]);; | ||
}, null, $application); | ||
|
||
$closure($application); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\Debug\Api\Debug\Http; | ||
|
||
use Yiisoft\Router\RouteCollectorInterface; | ||
|
||
final class RouteCollectorWrapper | ||
{ | ||
public function __construct( | ||
private array $middlewareDefinitions, | ||
) { | ||
} | ||
|
||
public function wrap(RouteCollectorInterface $routeCollector): void | ||
{ | ||
$routeCollector->prependMiddleware(...$this->middlewareDefinitions); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\Debug\Api\Debug\Middleware; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher; | ||
|
||
final class MiddlewareDispatcherMiddleware implements MiddlewareInterface | ||
{ | ||
public function __construct( | ||
public MiddlewareDispatcher $middlewareDispatcher | ||
) { | ||
} | ||
|
||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
return $this->middlewareDispatcher->dispatch($request, $handler); | ||
} | ||
} |
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