Conditions | 3 |
Paths | 3 |
Total Lines | 42 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Tests | 29 |
CRAP Score | 3 |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
1 | <?php |
||
25 | 8 | public function load($resource, $type = null) |
|
26 | { |
||
27 | 8 | if ($this->loaded === true) { |
|
28 | 2 | throw new \LogicException( |
|
29 | 'Do not add the "innmind_rest" loader twice' |
||
30 | 2 | ); |
|
31 | } |
||
32 | |||
33 | 8 | $routes = $this->loader->load($resource, $type); |
|
34 | |||
35 | 8 | foreach ($routes as $route) { |
|
36 | $route |
||
37 | 8 | ->setDefault( |
|
38 | 8 | '_controller', |
|
39 | 8 | sprintf( |
|
40 | 8 | 'innmind_rest.server.controller:%sAction', |
|
41 | 8 | $route->getDefault(RouteKeys::ACTION) |
|
42 | 8 | ) |
|
43 | 8 | ); |
|
44 | 8 | } |
|
45 | |||
46 | 8 | $serverRoutes = new RouteCollection; |
|
47 | 8 | $serverRoutes->addCollection($routes); |
|
48 | |||
49 | 8 | $capabilities = new Route('/*'); |
|
50 | 8 | $capabilities |
|
51 | 8 | ->setMethods('OPTIONS') |
|
52 | 8 | ->setDefault( |
|
53 | 8 | '_controller', |
|
54 | 'innmind_rest.server.controller:capabilitiesAction' |
||
55 | 8 | ) |
|
56 | 8 | ->setDefault( |
|
57 | 8 | RouteKeys::ACTION, |
|
58 | 'capabilities' |
||
59 | 8 | ); |
|
60 | 8 | $serverRoutes->add('innmind_rest_server_capabilities', $capabilities); |
|
61 | |||
62 | 8 | $this->loaded = true; |
|
63 | 8 | $this->routes = $routes; |
|
64 | |||
65 | 8 | return $serverRoutes; |
|
66 | } |
||
67 | |||
76 |