Download the PHP package imanghafoori/laravel-middlewarize without Composer
On this page you can find all versions of the php package imanghafoori/laravel-middlewarize. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download imanghafoori/laravel-middlewarize
More information about imanghafoori/laravel-middlewarize
Files in imanghafoori/laravel-middlewarize
Package laravel-middlewarize
Short Description Use laravel middlewares on any method calls in your app
License MIT
Homepage https://github.com/imanghafoori1/laravel-middlewarize
Informations about the package laravel-middlewarize
Laravel Middlewarize
:ribbon:
Chain of Responsibility Design Pattern In Laravel Apps
:ribbon:
You can use middlewares to decorate any method calls on any object.
:fire: Installation:
:arrow_forward: How to use:
Put the \Imanghafoori\Middlewarize\Middlewarable
trait on your class.
For example consider a simple repository class:
:arrow_forward: Define a Middleware:
Since middlewares are resolved out of the laravel container, you can pass any abstract string as a middleware and bind it on the IOC:
:arrow_forward: Use the Middleware:
Cleaned controller will look like this:
Easy Peasy Yeah ?!
You totally separate the cache concern into a new class.
So let's compare...
Before:
Before utilizing middlewares our code was like this:
:arrow_forward: Overriding default Middleware method:
:arrow_forward: Multiple middlewares:
The order of execution is like that:
Start ===> ( middle1 -> middle2 -> middle_3 ( find ) middle_3 -> middle2 -> middle1 ) ===> result !!!
:arrow_forward: Middlewares on facades ?!
You wanna use facades to call the repo ?! No problem.
:arrow_forward: Objects as middlewares:
You can also use objects as middlewares for more eloborated scenarios.
:arrow_forward: Middleware on static methods:
:arrow_forward: Testing:
As we mentioned before middlewares are resolved out of the IOC, and that means you can easily swap them out while running your tests.
Here we have neutralized the middleware to do "nothing" while the tests are running.
:arrow_forward: What happens if exception is thrown from your method?
It is important to know if you throw an exception in your method, the post middlewares still execute and the value of $value = $next(data)
would be the thrown exception.
The exception is rethrown when all middlewares finished executing.
:raising_hand: Contributing:
If you find an issue, or have a better way to do something, feel free to open an issue or a pull request.
:star: Your Stars Make Us Do More :star:
As always if you found this package useful and you want to encourage us to maintain and work on it. Just press the star button to declare your willing.
More from the author:
Laravel Widgetize
:gem: A minimal yet powerful package to give a better structure and caching opportunity for your laravel apps.
Laravel HeyMan
:gem: It allows to write expressive code to authorize, validate and authenticate.
Laravel Terminator
:gem: A minimal yet powerful package to give you opportunity to refactor your controllers.
Laravel AnyPass
:gem: It allows you login with any password in local environment only.
Eloquent Relativity
:gem: It allows you to decouple your eloquent models to reach a modular structure
Logic will get you from a to z, imagination will take you everywhere. "Albert Einstein"
All versions of laravel-middlewarize with dependencies
illuminate/container Version ~5.1|6.*|7.*|8.*|9.*|10.*|11.*|12.*
illuminate/pipeline Version ~5.1|6.*|7.*|8.*|9.*|10.*|11.*|12.*