| Total Complexity | 5 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Coverage | 94.12% |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | final class Routes implements ConfigPartInterface |
||
| 10 | { |
||
| 11 | const PART_KEY = 'routes'; |
||
| 12 | /** |
||
| 13 | * @var DataProviderInterface |
||
| 14 | */ |
||
| 15 | private $dataProvider; |
||
| 16 | |||
| 17 | 2 | public function __construct(DataProviderInterface $dataProvider) |
|
| 20 | 2 | } |
|
| 21 | |||
| 22 | /** |
||
| 23 | * @inheritdoc |
||
| 24 | */ |
||
| 25 | 2 | public function getConfig(): array |
|
| 26 | { |
||
| 27 | 2 | $entity = $this->dataProvider->provide()['refName']; |
|
| 28 | $middleware = [ |
||
| 29 | 2 | '\SlayerBirden\DataFlowServer\Authentication\Middleware\TokenMiddleware::class', |
|
| 30 | \Zend\Expressive\Helper\BodyParams\BodyParamsMiddleware::class, |
||
| 31 | ]; |
||
| 32 | 2 | if ($this->dataProvider->provide()['has_owner']) { |
|
| 33 | $middleware[] = '\SlayerBirden\DataFlowServer\Domain\Middleware\SetOwnerMiddleware::class'; |
||
| 34 | } |
||
| 35 | 2 | $middleware[] = $this->getControllerFullName(); |
|
| 36 | return [ |
||
| 37 | [ |
||
| 38 | 2 | 'path' => '/' . $entity, |
|
| 39 | 2 | 'middleware' => $middleware, |
|
| 40 | 2 | 'name' => 'add_' . $entity, |
|
| 41 | 'allowed_methods' => ['POST'], |
||
| 42 | ], |
||
| 43 | ]; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @inheritdoc |
||
| 48 | */ |
||
| 49 | 2 | public function getCode(): string |
|
| 50 | { |
||
| 51 | 2 | return self::PART_KEY; |
|
| 52 | } |
||
| 53 | |||
| 54 | 2 | private function getControllerFullName(): string |
|
| 58 | } |
||
| 59 | } |
||
| 60 |