| @@ 13-53 (lines=41) @@ | ||
| 10 | * @package Thruster\Component\HttpModifier |
|
| 11 | * @author Aurimas Niekis <[email protected]> |
|
| 12 | */ |
|
| 13 | class MessageModifierCollection extends BaseModifierCollection implements MessageModifierInterface |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @param MessageModifierInterface[] $modifiers |
|
| 17 | */ |
|
| 18 | public function __construct(array $modifiers = []) |
|
| 19 | { |
|
| 20 | parent::__construct(); |
|
| 21 | ||
| 22 | $this->collection = (function (MessageModifierInterface ...$modifiers) { |
|
| 23 | return $modifiers; |
|
| 24 | })(...$modifiers); |
|
| 25 | } |
|
| 26 | ||
| 27 | /*** |
|
| 28 | * @param MessageModifierInterface $modifier |
|
| 29 | * |
|
| 30 | * @return $this |
|
| 31 | */ |
|
| 32 | public function add(MessageModifierInterface $modifier) |
|
| 33 | { |
|
| 34 | $this->collection[] = $modifier; |
|
| 35 | ||
| 36 | return $this; |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param MessageInterface $message |
|
| 41 | * |
|
| 42 | * @return MessageInterface |
|
| 43 | */ |
|
| 44 | public function modify(MessageInterface $message) : MessageInterface |
|
| 45 | { |
|
| 46 | /** @var MessageModifierInterface $modifier */ |
|
| 47 | foreach ($this->collection as $modifier) { |
|
| 48 | $message = $modifier->modify($message); |
|
| 49 | } |
|
| 50 | ||
| 51 | return $message; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 13-53 (lines=41) @@ | ||
| 10 | * @package Thruster\Component\HttpModifier |
|
| 11 | * @author Aurimas Niekis <[email protected]> |
|
| 12 | */ |
|
| 13 | class ResponseModifierCollection extends BaseModifierCollection implements ResponseModifierInterface |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @param ResponseModifierInterface[] $modifiers |
|
| 17 | */ |
|
| 18 | public function __construct(array $modifiers = []) |
|
| 19 | { |
|
| 20 | parent::__construct(); |
|
| 21 | ||
| 22 | $this->collection = (function (ResponseModifierInterface ...$modifiers) { |
|
| 23 | return $modifiers; |
|
| 24 | })(...$modifiers); |
|
| 25 | } |
|
| 26 | ||
| 27 | /*** |
|
| 28 | * @param ResponseModifierInterface $modifier |
|
| 29 | * |
|
| 30 | * @return $this |
|
| 31 | */ |
|
| 32 | public function add(ResponseModifierInterface $modifier) |
|
| 33 | { |
|
| 34 | $this->collection[] = $modifier; |
|
| 35 | ||
| 36 | return $this; |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param ResponseInterface $response |
|
| 41 | * |
|
| 42 | * @return ResponseInterface |
|
| 43 | */ |
|
| 44 | public function modify(ResponseInterface $response) : ResponseInterface |
|
| 45 | { |
|
| 46 | /** @var ResponseModifierInterface $modifier */ |
|
| 47 | foreach ($this->collection as $modifier) { |
|
| 48 | $response = $modifier->modify($response); |
|
| 49 | } |
|
| 50 | ||
| 51 | return $response; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||