Passed
Push — 1.0.0-alpha ( 268be3...1f7cc7 )
by Alex
02:54
created

Router::jsonApiResources()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Huntie\JsonApi\Routing;
4
5
class Router extends \Illuminate\Routing\Router
6
{
7
    /**
8
     * Register an array of JSON API resource controllers.
9
     *
10
     * @param array $resources
11
     */
12
    public function jsonApiResources(array $resources)
13
    {
14
        foreach ($resources as $name => $controller) {
15
            $this->resource($name, $controller);
16
        }
17
    }
18
19
    /**
20
     * Route a JSON API resource to a controller.
21
     *
22
     * @param string $name
23
     * @param string $controller
24
     * @param array  $options
25
     */
26
    public function jsonApiResource($name, $controller, array $options = [])
27
    {
28
        if ($this->container && $this->container->bound(ResourceRegistrar::class)) {
29
            $registrar = $this->container->make(ResourceRegistrar::class);
30
        } else {
31
            $registrar = new ResourceRegistrar($this);
32
        }
33
34
        $registrar->register($name, $controller, $options);
35
    }
36
}
37