hkinnoteam / zmiddleware
There is no license information available for the latest version (1.0.2) of this package.
1.0.2
2021-01-07 15:20 UTC
Requires
- doctrine/annotations: ^1.11
- doctrine/cache: ^1.10
This package is auto-updated.
Last update: 2024-11-07 23:41:53 UTC
README
Install
composer require "hkinnoteam/zmidlleware"
Implementation
- create a class which implement ZMiddleware\Contract\MiddlewareInterface
use ZMiddleware\Contract\MiddlewareInterface; class AssignResultMiddleware implements MiddlewareInterface { public function handle($pass, \Closure $next) { // before request $validate = true; if ($validate){ return 'not allow'; } // request method $number = $next($pass); //after request $number->total_qty = 100; return $number; } }
Add annotation into your api method
use AssignResultMiddleware; use ZMiddleware\Annotations\Middleware; class Foo { /** * single middleware * * @Middleware(AssignResultMiddleware::class) * @return object */ public static function Foo(): object { $foo = new \stdClass(); return $foo; } }
you can also assign multiple middlewares
use AssignBooMiddleware; use AssignFooMiddleware; use ZMiddleware\Annotations\Middlewares; use ZMiddleware\Annotations\Middleware; class Foo { /** * multiple middlewares * * @Middlewares({ * @Middleware(AssignBooMiddleware::class) * @Middleware(AssignFooMiddleware::class) * }) * @return object */ public static function Foo(): object { $foo = new \stdClass(); return $foo; } }