Completed
Push — master ( 14f10a...6ec6b5 )
by Adam
02:31
created

GridHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 13
rs 9.4285
1
<?php
2
3
namespace Boduch\Grid;
4
5
use Collective\Html\HtmlBuilder;
6
use Collective\Html\FormBuilder;
7
use Illuminate\Http\Request;
8
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
9
use Illuminate\Contracts\View\Factory as ViewFactory;
10
11
class GridHelper
12
{
13
    /**
14
     * @var Request
15
     */
16
    protected $request;
17
18
    /**
19
     * @var ViewFactory
20
     */
21
    protected $view;
22
23
    /**
24
     * @var ValidationFactory
25
     */
26
    protected $validator;
27
28
    /**
29
     * @var HtmlBuilder
30
     */
31
    protected $htmlBuilder;
32
33
    /**
34
     * @var FormBuilder
35
     */
36
    protected $formBuilder;
37
38
    /**
39
     * @param Request $request
40
     * @param ValidationFactory $validator
41
     * @param ViewFactory $view
42
     * @param HtmlBuilder $htmlBuilder
43
     * @param FormBuilder $formBuilder
44
     */
45
    public function __construct(
46
        Request $request,
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
47
        ValidationFactory $validator,
48
        ViewFactory $view,
49
        HtmlBuilder $htmlBuilder,
50
        FormBuilder $formBuilder
51
    ) {
52
        $this->request = $request;
53
        $this->view = $view;
54
        $this->validator = $validator;
55
        $this->htmlBuilder = $htmlBuilder;
56
        $this->formBuilder = $formBuilder;
57
    }
58
59
    /**
60
     * @return Request
61
     */
62
    public function getRequest()
63
    {
64
        return $this->request;
65
    }
66
67
    /**
68
     * @return ViewFactory
69
     */
70
    public function getView()
71
    {
72
        return $this->view;
73
    }
74
75
    /**
76
     * @return ValidationFactory
77
     */
78
    public function getValidator()
79
    {
80
        return $this->validator;
81
    }
82
83
    /**
84
     * @return HtmlBuilder
85
     */
86
    public function getHtmlBuilder()
87
    {
88
        return $this->htmlBuilder;
89
    }
90
91
    /**
92
     * @return FormBuilder
93
     */
94
    public function getFormBuilder()
95
    {
96
        return $this->formBuilder;
97
    }
98
99
    /**
100
     * @param $rules array
101
     * @return \Illuminate\Contracts\Validation\Validator
102
     */
103
    public function getValidatorInstance($rules)
104
    {
105
        return $this->validator->make($this->request->all(), $rules);
106
    }
107
108
    /**
109
     * Generate an html tag.
110
     *
111
     * @param string $tag
112
     * @param mixed $content
113
     * @param array  $attributes
114
     *
115
     * @return \Illuminate\Support\HtmlString
116
     */
117
    public function tag($tag, $content, array $attributes = [])
118
    {
119
        return $this->htmlBuilder->tag($tag, $content, $attributes);
120
    }
121
}
122