| Total Complexity | 7 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | class PriorityQueueDispatcher extends QueueDispatcher{ |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @inheritDoc |
||
| 23 | */ |
||
| 24 | public function addStack(iterable $middlewareStack):QueueDispatcher{ |
||
| 25 | |||
| 26 | foreach($middlewareStack as $middleware){ |
||
| 27 | |||
| 28 | if(!$middleware instanceof MiddlewareInterface){ |
||
| 29 | throw new MiddlewareException('invalid middleware'); |
||
| 30 | } |
||
| 31 | |||
| 32 | if(!$middleware instanceof PriorityMiddlewareInterface){ |
||
| 33 | $middleware = new PriorityMiddleware($middleware); |
||
| 34 | } |
||
| 35 | |||
| 36 | $this->middlewareStack[] = $middleware; |
||
| 37 | } |
||
| 38 | |||
| 39 | $this->sortMiddleware(); |
||
| 40 | |||
| 41 | return $this; |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @inheritDoc |
||
| 46 | */ |
||
| 47 | public function add(MiddlewareInterface $middleware):QueueDispatcher{ |
||
| 48 | |||
| 49 | if(!$middleware instanceof PriorityMiddlewareInterface){ |
||
| 50 | $middleware = new PriorityMiddleware($middleware); |
||
| 51 | } |
||
| 52 | |||
| 53 | $this->middlewareStack[] = $middleware; |
||
| 54 | |||
| 55 | $this->sortMiddleware(); |
||
| 56 | |||
| 57 | return $this; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * |
||
| 62 | */ |
||
| 63 | protected function sortMiddleware():void{ |
||
| 67 | ); |
||
| 68 | } |
||
| 69 | |||
| 71 |