| 1 | <?php |
||
| 9 | final class EndpointRouteLoader extends Loader |
||
| 10 | { |
||
| 11 | /** @var bool */ |
||
| 12 | private $loaded = false; |
||
| 13 | /** @var array */ |
||
| 14 | private $endpoints = []; |
||
| 15 | |||
| 16 | /** {@inheritdoc} */ |
||
| 17 | 2 | public function load($resource, $type = null) |
|
| 18 | { |
||
| 19 | 2 | if ($this->loaded) { |
|
| 20 | 1 | throw new \LogicException('Endpoint loader is already loaded'); |
|
| 21 | } |
||
| 22 | |||
| 23 | 2 | $collection = new RouteCollection(); |
|
| 24 | 2 | foreach ($this->endpoints as $name => $endpoint) { |
|
| 25 | // prepare a new route |
||
| 26 | 2 | $path = $endpoint['path']; |
|
| 27 | 2 | $defaults = $endpoint['defaults']; |
|
| 28 | 2 | $route = new Route($path, $defaults); |
|
| 29 | 2 | $route->setMethods('POST'); |
|
| 30 | |||
| 31 | 2 | $collection->add($name, $route); |
|
| 32 | 2 | } |
|
| 33 | |||
| 34 | 2 | $this->loaded = true; |
|
| 35 | |||
| 36 | 2 | return $collection; |
|
| 37 | } |
||
| 38 | |||
| 39 | /** {@inheritdoc} */ |
||
| 40 | 2 | public function supports($resource, $type = null) |
|
| 44 | |||
| 45 | 2 | public function addEndpoint($name, array $endpoint) |
|
| 53 | } |
||
| 54 |