Completed
Push — master ( 456d28...8408ee )
by Denis
01:27
created
src/DataProviders/BaseDataProvider.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -6,17 +6,17 @@
 block discarded – undo
6 6
 
7 7
 abstract class BaseDataProvider
8 8
 {
9
-    /**
10
-     * Should return total amount of rows
11
-     * @param GridViewRequest $request
12
-     * @return int
13
-     */
14
-    abstract public function getCount(GridViewRequest $request) : int;
9
+	/**
10
+	 * Should return total amount of rows
11
+	 * @param GridViewRequest $request
12
+	 * @return int
13
+	 */
14
+	abstract public function getCount(GridViewRequest $request) : int;
15 15
 
16
-    /**
17
-     * Should return a list of data for current page
18
-     * @param GridViewRequest $request
19
-     * @return mixed
20
-     */
21
-    abstract public function getData(GridViewRequest $request);
16
+	/**
17
+	 * Should return a list of data for current page
18
+	 * @param GridViewRequest $request
19
+	 * @return mixed
20
+	 */
21
+	abstract public function getData(GridViewRequest $request);
22 22
 }
23 23
\ No newline at end of file
Please login to merge, or discard this patch.
src/DataProviders/ArrayDataProvider.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -6,74 +6,74 @@
 block discarded – undo
6 6
 
7 7
 class ArrayDataProvider extends BaseDataProvider
8 8
 {
9
-    /**
10
-     * @var array
11
-     */
12
-    private $data;
9
+	/**
10
+	 * @var array
11
+	 */
12
+	private $data;
13 13
 
14
-    public function __construct(array $data)
15
-    {
16
-        $this->data = $data;
17
-    }
14
+	public function __construct(array $data)
15
+	{
16
+		$this->data = $data;
17
+	}
18 18
 
19
-    /**
20
-     * @param GridViewRequest $request
21
-     * @return array
22
-     */
23
-    protected function processData(GridViewRequest $request) : array
24
-    {
25
-        if (empty($this->data)) {
26
-            return [];
27
-        }
19
+	/**
20
+	 * @param GridViewRequest $request
21
+	 * @return array
22
+	 */
23
+	protected function processData(GridViewRequest $request) : array
24
+	{
25
+		if (empty($this->data)) {
26
+			return [];
27
+		}
28 28
 
29
-        $tmp = collect($this->data);
29
+		$tmp = collect($this->data);
30 30
 
31
-        if (!empty($request->filters)) {
32
-            $tmp = $tmp->filter(function($item) use ($request) {
33
-                foreach ($request->filters as $filterKey => $filterValue) {
31
+		if (!empty($request->filters)) {
32
+			$tmp = $tmp->filter(function($item) use ($request) {
33
+				foreach ($request->filters as $filterKey => $filterValue) {
34 34
 
35
-                    if (!isset($item[$filterKey])) {
36
-                        return false;
37
-                    }
35
+					if (!isset($item[$filterKey])) {
36
+						return false;
37
+					}
38 38
 
39
-                    if (strpos($item[$filterKey], $filterValue) === false) {
40
-                        return false;
41
-                    }
42
-                }
39
+					if (strpos($item[$filterKey], $filterValue) === false) {
40
+						return false;
41
+					}
42
+				}
43 43
 
44
-                return true;
45
-            });
46
-        }
44
+				return true;
45
+			});
46
+		}
47 47
 
48
-        if (!empty($request->sortColumn)) {
49
-            $tmp = $tmp->sortBy(
50
-                $request->sortColumn,
51
-                SORT_REGULAR,
52
-                $request->sortOrder == 'DESC'
53
-            );
54
-        }
48
+		if (!empty($request->sortColumn)) {
49
+			$tmp = $tmp->sortBy(
50
+				$request->sortColumn,
51
+				SORT_REGULAR,
52
+				$request->sortOrder == 'DESC'
53
+			);
54
+		}
55 55
 
56
-        return $tmp->values()->all();
57
-    }
56
+		return $tmp->values()->all();
57
+	}
58 58
 
59
-    /**
60
-     * @inheritdoc
61
-     */
62
-    public function getCount(GridViewRequest $request) : int
63
-    {
64
-        return count($this->processData($request));
65
-    }
59
+	/**
60
+	 * @inheritdoc
61
+	 */
62
+	public function getCount(GridViewRequest $request) : int
63
+	{
64
+		return count($this->processData($request));
65
+	}
66 66
 
67
-    /**
68
-     * @inheritdoc
69
-     */
70
-    public function getData(GridViewRequest $request)
71
-    {
72
-        $tmp = $this->processData($request);
67
+	/**
68
+	 * @inheritdoc
69
+	 */
70
+	public function getData(GridViewRequest $request)
71
+	{
72
+		$tmp = $this->processData($request);
73 73
 
74
-        return array_splice(
75
-            $tmp,
76
-            ($request->page -1) * $request->perPage, $request->perPage
77
-        );
78
-    }
74
+		return array_splice(
75
+			$tmp,
76
+			($request->page -1) * $request->perPage, $request->perPage
77
+		);
78
+	}
79 79
 }
80 80
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
 
74 74
         return array_splice(
75 75
             $tmp,
76
-            ($request->page -1) * $request->perPage, $request->perPage
76
+            ($request->page - 1) * $request->perPage, $request->perPage
77 77
         );
78 78
     }
79 79
 }
80 80
\ No newline at end of file
Please login to merge, or discard this patch.
src/GridViewServiceProvider.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
 
20 20
 		require_once __DIR__ . '/functions.php';
21 21
 
22
-        \Blade::directive('grid', function ($expression) {
22
+        \Blade::directive('grid', function($expression) {
23 23
             return "<?php echo grid($expression) ?>";
24 24
         });
25 25
 
Please login to merge, or discard this patch.
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -19,17 +19,17 @@
 block discarded – undo
19 19
 
20 20
 		require_once __DIR__ . '/functions.php';
21 21
 
22
-        \Blade::directive('grid', function ($expression) {
23
-            return "<?php echo grid($expression) ?>";
24
-        });
22
+		\Blade::directive('grid', function ($expression) {
23
+			return "<?php echo grid($expression) ?>";
24
+		});
25 25
 
26
-        $this->publishes([
27
-            __DIR__ . '/../public' => 'public/vendor/grid-view',
28
-        ], 'public');
26
+		$this->publishes([
27
+			__DIR__ . '/../public' => 'public/vendor/grid-view',
28
+		], 'public');
29 29
 
30
-        if (!File::isDirectory(public_path('vendor/grid-view'))) {
31
-            Artisan::call('vendor:publish', ['--tag' => 'public', '--force' => '']);
32
-        }
30
+		if (!File::isDirectory(public_path('vendor/grid-view'))) {
31
+			Artisan::call('vendor:publish', ['--tag' => 'public', '--force' => '']);
32
+		}
33 33
 	}
34 34
 
35 35
 	public function register()
Please login to merge, or discard this patch.
src/functions.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,5 +7,5 @@
 block discarded – undo
7 7
  * @throws \Woo\GridView\Exceptions\GridViewConfigException
8 8
  */
9 9
 function grid(array $config) {
10
-    return (new \Woo\GridView\GridView($config))->render();
10
+	return (new \Woo\GridView\GridView($config))->render();
11 11
 }
12 12
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/Configurable.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -7,88 +7,88 @@
 block discarded – undo
7 7
 
8 8
 trait Configurable
9 9
 {
10
-    /**
11
-     * Allows to load config into object properties
12
-     * @param array $config
13
-     * @throws GridViewConfigException
14
-     */
15
-    public function loadConfig(array $config)
16
-    {
17
-        foreach ($config as $key => $value) {
18
-
19
-            if (property_exists($this, $key)) {
20
-                $this->$key = $value;
21
-            }
22
-        }
23
-
24
-        $this->testConfig();
25
-    }
26
-
27
-    /**
28
-     * Should specify tests
29
-     * @return array
30
-     */
31
-    abstract protected function configTests() : array;
32
-
33
-    /**
34
-     * Allows to test attributes and types in config
35
-     * @throws GridViewConfigException
36
-     */
37
-    protected function testConfig()
38
-    {
39
-        foreach ($this->configTests() as $property => $tests) {
40
-
41
-            if (!property_exists($this, $property)) {
42
-                throw new GridViewConfigException(
43
-                    'Unable to test ' . get_class($this) . ': property ' . $property . ' does not exist'
44
-                );
45
-            }
46
-
47
-            $testPassed = true;
48
-            $testMessage = 'Validation failed';
49
-
50
-            foreach (explode('|', $tests) as $test) {
51
-
52
-                switch ($test) {
53
-                    case 'int':
54
-                        $testPassed = is_numeric($this->$property);
55
-                        $testMessage = 'Property should be numeric';
56
-                        break;
57
-
58
-                    case 'string':
59
-                        $testPassed = is_string($this->$property);
60
-                        $testMessage = 'Property should be a string';
61
-                        break;
62
-
63
-                    case 'array':
64
-                        $testPassed = is_array($this->$property);
65
-                        $testMessage = 'Property should be an array';
66
-                        break;
67
-
68
-                    case 'closure':
69
-                        $testPassed = $this->$property instanceof Closure;
70
-                        $testMessage = 'Property should be a valid callback (Closure instance)';
71
-                        break;
72
-
73
-                    case 'boolean':
74
-                        $testPassed = is_bool($this->$property);
75
-                        $testMessage = 'Property should be boolean';
76
-                        break;
77
-
78
-                    case 'any':
79
-                        break;
80
-
81
-                    default:
82
-                        $testPassed = $testPassed || is_a($this->$property, $test) || is_subclass_of($this->$property, $test);
83
-                        $testMessage = 'Property should be ' . $test . ' instance/class reference, check ' . $property;
84
-                }
85
-            }
86
-
87
-            if (!$testPassed) {
88
-                throw new GridViewConfigException(
89
-                    'Tests ' . $tests . ' has failed on ' . get_class($this) . '::' . $property . ': ' . $testMessage
90
-                );
91
-            }
92
-        }
93
-    }
10
+	/**
11
+	 * Allows to load config into object properties
12
+	 * @param array $config
13
+	 * @throws GridViewConfigException
14
+	 */
15
+	public function loadConfig(array $config)
16
+	{
17
+		foreach ($config as $key => $value) {
18
+
19
+			if (property_exists($this, $key)) {
20
+				$this->$key = $value;
21
+			}
22
+		}
23
+
24
+		$this->testConfig();
25
+	}
26
+
27
+	/**
28
+	 * Should specify tests
29
+	 * @return array
30
+	 */
31
+	abstract protected function configTests() : array;
32
+
33
+	/**
34
+	 * Allows to test attributes and types in config
35
+	 * @throws GridViewConfigException
36
+	 */
37
+	protected function testConfig()
38
+	{
39
+		foreach ($this->configTests() as $property => $tests) {
40
+
41
+			if (!property_exists($this, $property)) {
42
+				throw new GridViewConfigException(
43
+					'Unable to test ' . get_class($this) . ': property ' . $property . ' does not exist'
44
+				);
45
+			}
46
+
47
+			$testPassed = true;
48
+			$testMessage = 'Validation failed';
49
+
50
+			foreach (explode('|', $tests) as $test) {
51
+
52
+				switch ($test) {
53
+					case 'int':
54
+						$testPassed = is_numeric($this->$property);
55
+						$testMessage = 'Property should be numeric';
56
+						break;
57
+
58
+					case 'string':
59
+						$testPassed = is_string($this->$property);
60
+						$testMessage = 'Property should be a string';
61
+						break;
62
+
63
+					case 'array':
64
+						$testPassed = is_array($this->$property);
65
+						$testMessage = 'Property should be an array';
66
+						break;
67
+
68
+					case 'closure':
69
+						$testPassed = $this->$property instanceof Closure;
70
+						$testMessage = 'Property should be a valid callback (Closure instance)';
71
+						break;
72
+
73
+					case 'boolean':
74
+						$testPassed = is_bool($this->$property);
75
+						$testMessage = 'Property should be boolean';
76
+						break;
77
+
78
+					case 'any':
79
+						break;
80
+
81
+					default:
82
+						$testPassed = $testPassed || is_a($this->$property, $test) || is_subclass_of($this->$property, $test);
83
+						$testMessage = 'Property should be ' . $test . ' instance/class reference, check ' . $property;
84
+				}
85
+			}
86
+
87
+			if (!$testPassed) {
88
+				throw new GridViewConfigException(
89
+					'Tests ' . $tests . ' has failed on ' . get_class($this) . '::' . $property . ': ' . $testMessage
90
+				);
91
+			}
92
+		}
93
+	}
94 94
 }
95 95
\ No newline at end of file
Please login to merge, or discard this patch.
src/Formatters/BooleanFormatter.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 class BooleanFormatter implements IFormatter
6 6
 {
7
-    public function format($value): string
8
-    {
9
-        return $value ? 'Yes' : 'No';
10
-    }
7
+	public function format($value): string
8
+	{
9
+		return $value ? 'Yes' : 'No';
10
+	}
11 11
 }
12 12
\ No newline at end of file
Please login to merge, or discard this patch.
src/Formatters/RawFormatter.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 class RawFormatter implements IFormatter
6 6
 {
7
-    public function format($value): string
8
-    {
9
-        return $value;
10
-    }
7
+	public function format($value): string
8
+	{
9
+		return $value;
10
+	}
11 11
 }
12 12
\ No newline at end of file
Please login to merge, or discard this patch.
src/Columns/CallbackColumn.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -4,31 +4,31 @@
 block discarded – undo
4 4
 
5 5
 class CallbackColumn extends BaseColumn
6 6
 {
7
-    /**
8
-     * @var string
9
-     */
10
-    public $formatters = ['raw'];
7
+	/**
8
+	 * @var string
9
+	 */
10
+	public $formatters = ['raw'];
11 11
 
12
-    /**
13
-     * @var bool
14
-     */
15
-    public $sortable = false;
12
+	/**
13
+	 * @var bool
14
+	 */
15
+	public $sortable = false;
16 16
 
17
-    /**
18
-     * @return array
19
-     */
20
-    protected function configTests(): array
21
-    {
22
-        return array_merge(parent::configTests(), [
23
-            'value' => 'closure',
24
-        ]);
25
-    }
17
+	/**
18
+	 * @return array
19
+	 */
20
+	protected function configTests(): array
21
+	{
22
+		return array_merge(parent::configTests(), [
23
+			'value' => 'closure',
24
+		]);
25
+	}
26 26
 
27
-    /**
28
-     * @inheritdoc
29
-     */
30
-    public function _renderValue($row)
31
-    {
32
-        return call_user_func($this->value, $row);
33
-    }
27
+	/**
28
+	 * @inheritdoc
29
+	 */
30
+	public function _renderValue($row)
31
+	{
32
+		return call_user_func($this->value, $row);
33
+	}
34 34
 }
35 35
\ No newline at end of file
Please login to merge, or discard this patch.
src/GridView.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -15,226 +15,226 @@
 block discarded – undo
15 15
 
16 16
 class GridView
17 17
 {
18
-    use Configurable;
19
-
20
-    /**
21
-     * Counter for ids
22
-     * @var int
23
-     */
24
-    private static $counter = 0;
25
-
26
-    /**
27
-     * Grid id (used for request handling, for
28
-     * @var int
29
-     */
30
-    private $id;
31
-
32
-    /**
33
-     * DataProvider provides gridview with the data for representation
34
-     * @var BaseDataProvider
35
-     */
36
-    public $dataProvider;
37
-
38
-    /**
39
-     * Columns config. You may specify array or GridColumn instance
40
-     * @var BaseColumn[]
41
-     */
42
-    public $columns = [];
43
-
44
-    /**
45
-     * Common options for all columns, will be appended to all columns configs
46
-     * @var array
47
-     */
48
-    public $columnOptions = [
49
-        'class' => AttributeColumn::class,
50
-    ];
51
-
52
-    /**
53
-     * Renders the final UI
54
-     * @var string|BaseRenderer
55
-     */
56
-    public $renderer = DefaultRenderer::class;
57
-
58
-    /**
59
-     * Allows to pass some options into renderer/customize rendered behavior
60
-     * @var array
61
-     */
62
-    public $rendererOptions = [];
63
-
64
-    /**
65
-     * Controls amount of data per page
66
-     * @var int
67
-     */
68
-    public $rowsPerPage = 25;
69
-
70
-    /**
71
-     * Allows to tune the <table> tag with html options
72
-     * @var array
73
-     */
74
-    public $tableHtmlOptions = [
75
-        'class' => 'table table-bordered gridview-table',
76
-    ];
77
-
78
-    /**
79
-     * Indicate if filters will be shown or not
80
-     * @var bool
81
-     */
82
-    public $showFilters = true;
83
-
84
-    /**
85
-     * Flags allow to change standalone vue to. If false, GridView component should be included in your root Vue instance
86
-     * @var bool
87
-     */
88
-    public $standaloneVue = true;
89
-
90
-    /**
91
-     * @var Paginator
92
-     */
93
-    protected $pagination;
94
-
95
-    /**
96
-     * @var GridViewRequest
97
-     */
98
-    protected $request;
99
-
100
-    /**
101
-     * GridView constructor.
102
-     * @param array $config
103
-     * @throws Exceptions\GridViewConfigException
104
-     */
105
-    public function __construct(array $config)
106
-    {
107
-        $this->id = self::$counter++;
108
-
109
-        $this->loadConfig($config);
110
-
111
-        /**
112
-         * Making renderer
113
-         */
114
-        if (!is_object($this->renderer)) {
115
-            $className = GridViewHelper::resolveAlias('renderer', $this->renderer);
116
-            $this->renderer = new $className(array_merge(
117
-                $this->rendererOptions, [
118
-                    'gridView' => $this,
119
-                ]
120
-            ));
121
-        }
122
-
123
-        /**
124
-         * Build columns from config
125
-         */
126
-        $this->buildColumns();
127
-
128
-        $this->request = GridViewRequest::parse($this->id);
129
-        $this->request->perPage = $this->rowsPerPage;
130
-
131
-        $this->pagination = new LengthAwarePaginator(
132
-            $this->dataProvider->getData($this->request),
133
-            $this->dataProvider->getCount($this->request),
134
-            $this->rowsPerPage,
135
-            $this->request->page
136
-        );
137
-    }
138
-
139
-    /**
140
-     * @return array
141
-     */
142
-    protected function configTests(): array
143
-    {
144
-        return [
145
-            'dataProvider' => BaseDataProvider::class,
146
-            'columns' => 'array',
147
-            'renderer' => BaseRenderer::class,
148
-            'rowsPerPage' => 'int',
149
-            'tableHtmlOptions' => 'array',
150
-            'showFilters' => 'boolean',
151
-        ];
152
-    }
153
-
154
-    /**
155
-     * Build columns into objects
156
-     */
157
-    protected function buildColumns()
158
-    {
159
-        foreach ($this->columns as $key => &$columnOptions) {
160
-
161
-            /**
162
-             * In case of when column is already build
163
-             */
164
-            if (is_object($columnOptions)) {
165
-                continue;
166
-            }
167
-
168
-            /**
169
-             * When only attribute name/value passed
170
-             */
171
-            if (is_string($columnOptions)) {
172
-                $columnOptions = [
173
-                    'value' => $columnOptions,
174
-                ];
175
-            }
176
-
177
-            if ($columnOptions instanceof Closure) {
178
-                $columnOptions = [
179
-                    'class' => CallbackColumn::class,
180
-                    'value' => $columnOptions,
181
-                    'title' => GridViewHelper::columnTitle($key),
182
-                ];
183
-            }
184
-
185
-            /**
186
-             * Inline column declaration detector
187
-             */
188
-            if (is_string($columnOptions['value']) && strpos($columnOptions['value'], 'view:') === 0) {
189
-                $columnOptions['class'] = 'view';
190
-                $columnOptions['value'] = str_replace('view:', '', $columnOptions['value']);
191
-            }
192
-
193
-            $columnOptions = array_merge($this->columnOptions, $columnOptions);
194
-
195
-            $className = GridViewHelper::resolveAlias('column', $columnOptions['class']);
196
-            $columnOptions = new $className($columnOptions);
197
-        }
198
-    }
199
-
200
-    /**
201
-     * Draws widget and return html code
202
-     * @return string
203
-     */
204
-    public function render()
205
-    {
206
-        return $this->renderer->render($this);
207
-    }
208
-
209
-    /**
210
-     * @return LengthAwarePaginator|Paginator
211
-     */
212
-    public function getPagination()
213
-    {
214
-        return $this->pagination;
215
-    }
216
-
217
-    /**
218
-     * @return GridViewRequest
219
-     */
220
-    public function getRequest()
221
-    {
222
-        return $this->request;
223
-    }
224
-
225
-    /**
226
-     * @return int
227
-     */
228
-    public function getId() : int
229
-    {
230
-        return $this->id;
231
-    }
232
-
233
-    /**
234
-     * @return string
235
-     */
236
-    public function compileTableHtmlOptions() : string
237
-    {
238
-        return GridViewHelper::htmlOptionsToString($this->tableHtmlOptions);
239
-    }
18
+	use Configurable;
19
+
20
+	/**
21
+	 * Counter for ids
22
+	 * @var int
23
+	 */
24
+	private static $counter = 0;
25
+
26
+	/**
27
+	 * Grid id (used for request handling, for
28
+	 * @var int
29
+	 */
30
+	private $id;
31
+
32
+	/**
33
+	 * DataProvider provides gridview with the data for representation
34
+	 * @var BaseDataProvider
35
+	 */
36
+	public $dataProvider;
37
+
38
+	/**
39
+	 * Columns config. You may specify array or GridColumn instance
40
+	 * @var BaseColumn[]
41
+	 */
42
+	public $columns = [];
43
+
44
+	/**
45
+	 * Common options for all columns, will be appended to all columns configs
46
+	 * @var array
47
+	 */
48
+	public $columnOptions = [
49
+		'class' => AttributeColumn::class,
50
+	];
51
+
52
+	/**
53
+	 * Renders the final UI
54
+	 * @var string|BaseRenderer
55
+	 */
56
+	public $renderer = DefaultRenderer::class;
57
+
58
+	/**
59
+	 * Allows to pass some options into renderer/customize rendered behavior
60
+	 * @var array
61
+	 */
62
+	public $rendererOptions = [];
63
+
64
+	/**
65
+	 * Controls amount of data per page
66
+	 * @var int
67
+	 */
68
+	public $rowsPerPage = 25;
69
+
70
+	/**
71
+	 * Allows to tune the <table> tag with html options
72
+	 * @var array
73
+	 */
74
+	public $tableHtmlOptions = [
75
+		'class' => 'table table-bordered gridview-table',
76
+	];
77
+
78
+	/**
79
+	 * Indicate if filters will be shown or not
80
+	 * @var bool
81
+	 */
82
+	public $showFilters = true;
83
+
84
+	/**
85
+	 * Flags allow to change standalone vue to. If false, GridView component should be included in your root Vue instance
86
+	 * @var bool
87
+	 */
88
+	public $standaloneVue = true;
89
+
90
+	/**
91
+	 * @var Paginator
92
+	 */
93
+	protected $pagination;
94
+
95
+	/**
96
+	 * @var GridViewRequest
97
+	 */
98
+	protected $request;
99
+
100
+	/**
101
+	 * GridView constructor.
102
+	 * @param array $config
103
+	 * @throws Exceptions\GridViewConfigException
104
+	 */
105
+	public function __construct(array $config)
106
+	{
107
+		$this->id = self::$counter++;
108
+
109
+		$this->loadConfig($config);
110
+
111
+		/**
112
+		 * Making renderer
113
+		 */
114
+		if (!is_object($this->renderer)) {
115
+			$className = GridViewHelper::resolveAlias('renderer', $this->renderer);
116
+			$this->renderer = new $className(array_merge(
117
+				$this->rendererOptions, [
118
+					'gridView' => $this,
119
+				]
120
+			));
121
+		}
122
+
123
+		/**
124
+		 * Build columns from config
125
+		 */
126
+		$this->buildColumns();
127
+
128
+		$this->request = GridViewRequest::parse($this->id);
129
+		$this->request->perPage = $this->rowsPerPage;
130
+
131
+		$this->pagination = new LengthAwarePaginator(
132
+			$this->dataProvider->getData($this->request),
133
+			$this->dataProvider->getCount($this->request),
134
+			$this->rowsPerPage,
135
+			$this->request->page
136
+		);
137
+	}
138
+
139
+	/**
140
+	 * @return array
141
+	 */
142
+	protected function configTests(): array
143
+	{
144
+		return [
145
+			'dataProvider' => BaseDataProvider::class,
146
+			'columns' => 'array',
147
+			'renderer' => BaseRenderer::class,
148
+			'rowsPerPage' => 'int',
149
+			'tableHtmlOptions' => 'array',
150
+			'showFilters' => 'boolean',
151
+		];
152
+	}
153
+
154
+	/**
155
+	 * Build columns into objects
156
+	 */
157
+	protected function buildColumns()
158
+	{
159
+		foreach ($this->columns as $key => &$columnOptions) {
160
+
161
+			/**
162
+			 * In case of when column is already build
163
+			 */
164
+			if (is_object($columnOptions)) {
165
+				continue;
166
+			}
167
+
168
+			/**
169
+			 * When only attribute name/value passed
170
+			 */
171
+			if (is_string($columnOptions)) {
172
+				$columnOptions = [
173
+					'value' => $columnOptions,
174
+				];
175
+			}
176
+
177
+			if ($columnOptions instanceof Closure) {
178
+				$columnOptions = [
179
+					'class' => CallbackColumn::class,
180
+					'value' => $columnOptions,
181
+					'title' => GridViewHelper::columnTitle($key),
182
+				];
183
+			}
184
+
185
+			/**
186
+			 * Inline column declaration detector
187
+			 */
188
+			if (is_string($columnOptions['value']) && strpos($columnOptions['value'], 'view:') === 0) {
189
+				$columnOptions['class'] = 'view';
190
+				$columnOptions['value'] = str_replace('view:', '', $columnOptions['value']);
191
+			}
192
+
193
+			$columnOptions = array_merge($this->columnOptions, $columnOptions);
194
+
195
+			$className = GridViewHelper::resolveAlias('column', $columnOptions['class']);
196
+			$columnOptions = new $className($columnOptions);
197
+		}
198
+	}
199
+
200
+	/**
201
+	 * Draws widget and return html code
202
+	 * @return string
203
+	 */
204
+	public function render()
205
+	{
206
+		return $this->renderer->render($this);
207
+	}
208
+
209
+	/**
210
+	 * @return LengthAwarePaginator|Paginator
211
+	 */
212
+	public function getPagination()
213
+	{
214
+		return $this->pagination;
215
+	}
216
+
217
+	/**
218
+	 * @return GridViewRequest
219
+	 */
220
+	public function getRequest()
221
+	{
222
+		return $this->request;
223
+	}
224
+
225
+	/**
226
+	 * @return int
227
+	 */
228
+	public function getId() : int
229
+	{
230
+		return $this->id;
231
+	}
232
+
233
+	/**
234
+	 * @return string
235
+	 */
236
+	public function compileTableHtmlOptions() : string
237
+	{
238
+		return GridViewHelper::htmlOptionsToString($this->tableHtmlOptions);
239
+	}
240 240
 }
Please login to merge, or discard this patch.