Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/softonic/laravel-psr15-bridge
https://github.com/softonic/laravel-psr15-bridge
laravel psr-15
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/softonic/laravel-psr15-bridge
- Owner: softonic
- License: other
- Created: 2019-01-24T17:36:42.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T08:58:21.000Z (10 months ago)
- Last Synced: 2024-11-28T17:48:42.766Z (2 months ago)
- Topics: laravel, psr-15
- Language: PHP
- Size: 85 KB
- Stars: 9
- Watchers: 7
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
Laravel PSR-15 Middleware Bridge
=====[![Latest Version](https://img.shields.io/github/release/softonic/laravel-psr15-bridge.svg?style=flat-square)](https://github.com/softonic/laravel-psr15-bridge/releases)
[![Software License](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/travis/softonic/laravel-psr15-bridge/master.svg?style=flat-square)](https://travis-ci.org/softonic/laravel-psr15-bridge)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/softonic/laravel-psr15-bridge.svg?style=flat-square)](https://scrutinizer-ci.com/g/softonic/laravel-psr15-bridge/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/softonic/laravel-psr15-bridge.svg?style=flat-square)](https://scrutinizer-ci.com/g/softonic/laravel-psr15-bridge)
[![Total Downloads](https://img.shields.io/packagist/dt/softonic/laravel-psr15-bridge.svg?style=flat-square)](https://packagist.org/packages/softonic/laravel-psr15-bridge)This package provides a Laravel middleware bridge for [PSR-15][PSR-15] inspired in [jshannon63/laravel-psr15-middleware](https://github.com/jshannon63/laravel-psr15-middleware).
Installation
-------To install, use composer:
```
composer require softonic/laravel-psr15-bridge
```You are ready to use it!
Usage
-------The bridge adapter receive a [PSR-15][PSR-15] middleware via injection, so the bridge is transparent for Laravel and you can use
it as any other middleware.Example based on [OpenApi Validation Middleware](https://github.com/hkarlstrom/openapi-validation-middleware):
Wrapping [OpenApi Validation Middleware](https://github.com/hkarlstrom/openapi-validation-middleware) within the bridge.
```php
// app/Providers/AppServiceProvider.phpuse Softonic\Laravel\Middleware\Psr15Bridge\Psr15MiddlewareAdapter;
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(OpenApiValidation::class, function () {// Setup your PSR-15 middleware here
$validator = new \HKarlstrom\Middleware\OpenApiValidation('schema.json');
// Return it wrapped in the adapter to make Laravel accept it
return Psr15MiddlewareAdapter::adapt($validator);
});
}
```Now you can use it anywhere or for example generate an alias.
```php
// app/Http/Kernel.phpprotected $routeMiddleware = [
...
'openapi-validation' => OpenApiValidation::class,
];
```Check [laravel middleware](https://laravel.com/docs/9.x/middleware) for more information.
How it works
------------In the next diagram you can see the request and response flow.
![psr-15 bridge flow](doc/bridge_flow.png)
As you can see, when you execute `Psr15MiddlewareAdapter::adapt($validator);`, you are adding an envelop to the PSR-15
middleware that converts the request and response transparently for the middleware format Laravel expects.Testing
-------`softonic/laravel-psr15-bridge` has a [PHPUnit](https://phpunit.de) test suite and a coding style compliance test suite using [PHP CS Fixer](http://cs.sensiolabs.org/).
To run the tests, run the following command from the project folder.
``` bash
$ docker-compose run test
```License
-------The Apache 2.0 license. Please see [LICENSE](LICENSE) for more information.
[PSR-15]: http://www.php-fig.org/psr/psr-15/