| Total Complexity | 14 |
| Total Lines | 96 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class Middleware |
||
| 6 | { |
||
| 7 | /** @var array */ |
||
| 8 | protected $globalMiddleware = []; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Middleware constructor. |
||
| 12 | */ |
||
| 13 | 1 | public function __construct() |
|
| 18 | ]; |
||
| 19 | 1 | } |
|
| 20 | |||
| 21 | /** |
||
| 22 | * Get registered middleware. |
||
| 23 | * |
||
| 24 | * @return array |
||
| 25 | */ |
||
| 26 | 4 | public function list() : array |
|
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Get before middleware. |
||
| 33 | * |
||
| 34 | * @return array |
||
| 35 | */ |
||
| 36 | 1 | public function before() : array |
|
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Get after middleware. |
||
| 51 | * |
||
| 52 | * @return array |
||
| 53 | */ |
||
| 54 | 1 | public function after() : array |
|
| 55 | { |
||
| 56 | 1 | $after = []; |
|
| 57 | |||
| 58 | 1 | foreach ($this->globalMiddleware as $m) { |
|
| 59 | 1 | if ( ! $m->before()) { |
|
| 60 | 1 | $after[] = $m; |
|
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | 1 | return $after; |
|
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Set middleware. |
||
| 69 | * |
||
| 70 | * @param array $middleware |
||
| 71 | * |
||
| 72 | * @return Middleware |
||
| 73 | */ |
||
| 74 | 1 | public function add(...$middleware) : self |
|
| 75 | { |
||
| 76 | 1 | foreach ($middleware as $m) { |
|
| 77 | 1 | if ($m instanceof TusMiddlewareInterface) { |
|
| 78 | 1 | $this->globalMiddleware[get_class($m)] = $m; |
|
| 79 | 1 | } else if (is_string($m)) { |
|
| 80 | 1 | $this->globalMiddleware[$m] = new $m; |
|
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | 1 | return $this; |
|
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Skip middleware. |
||
| 89 | * |
||
| 90 | * @param array ...$middleware |
||
| 91 | * |
||
| 92 | * @return Middleware |
||
| 93 | */ |
||
| 94 | 1 | public function skip(...$middleware) : self |
|
| 101 | } |
||
| 102 | } |
||
| 103 |