GridBuilder::createBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Boduch\Grid;
4
5
use Illuminate\Contracts\Container\Container;
6
7
class GridBuilder
8
{
9
    /**
10
     * @var Container
11
     */
12
    protected $container;
13
14
    /**
15
     * @param Container  $container
16
     */
17
    public function __construct(Container $container)
18
    {
19
        $this->container = $container;
20
    }
21
22
    /**
23
     * @param string $gridClass
24
     * @return Grid
25
     */
26
    public function createGrid($gridClass)
27
    {
28
        if (!class_exists($gridClass)) {
29
            throw new \InvalidArgumentException(
30
                'Grid class with name ' . $gridClass . ' does not exist.'
31
            );
32
        }
33
34
        /** @var Grid $grid */
35
        $grid = $this->container->make($gridClass);
36
37
        if (method_exists($grid, 'boot')) {
38
            // call method boot() if exists
39
            $this->container->call([&$grid, 'boot']);
40
        }
41
42
        $grid->buildGrid();
43
44
        return $grid;
45
    }
46
47
    /**
48
     * @return Grid
49
     */
50
    public function createBuilder()
51
    {
52
        return $this->createGrid(Grid::class);
53
    }
54
}
55