Completed
Push — master ( 8e6ba3...69e16e )
by Denis
01:13
created
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.
src/GridViewHelper.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -23,144 +23,144 @@
 block discarded – undo
23 23
 
24 24
 class GridViewHelper
25 25
 {
26
-    /**
27
-     * A list of grid aliases
28
-     * @var array
29
-     */
30
-    private static $aliases = [
31
-        'column' => [
32
-            'attribute' => AttributeColumn::class,
33
-            'raw' => CallbackColumn::class,
34
-            'callback' => CallbackColumn::class,
35
-            'actions' => ActionsColumn::class,
36
-            'view' => ViewColumn::class,
37
-        ],
38
-        'formatter' => [
39
-            'email' => EmailFormatter::class,
40
-            'image' => ImageFormatter::class,
41
-            'text' => TextFormatter::class,
42
-            'url' => UrlFormatter::class,
43
-            'raw' => RawFormatter::class,
44
-        ],
45
-        'filter' => [
46
-            'text' => TextFilter::class,
47
-            'dropdown' => DropdownFilter::class,
48
-        ],
49
-        'renderer' => [
50
-            'default' => DefaultRenderer::class,
51
-        ],
52
-        'action' => [
53
-            'delete' => DeleteAction::class,
54
-            'update' => EditAction::class,
55
-            'edit' => EditAction::class,
56
-            'show' => ShowAction::class,
57
-            'view' => ShowAction::class,
58
-            'action' => Action::class,
59
-        ]
60
-    ];
61
-
62
-    private function __construct() {}
63
-
64
-    /**
65
-     * Useful in case you want to register a new alias for your project
66
-     * @param string $context
67
-     * @param string $alias
68
-     * @param string $aliasTo
69
-     */
70
-    public static function registerAlias(string $context, string $alias, string $aliasTo)
71
-    {
72
-        self::$aliases[$context][$alias] = $aliasTo;
73
-    }
74
-
75
-    /**
76
-     * Allows to resolve class name by its alias
77
-     * @param string $context
78
-     * @param string $alias
79
-     * @return mixed
80
-     */
81
-    public static function resolveAlias(string $context, string $alias)
82
-    {
83
-        return self::$aliases[$context][$alias] ?? $alias;
84
-    }
85
-
86
-    /**
87
-     * Allows to convert options array to html string
88
-     * @param array $htmlOptions
89
-     * @param array $context - context is variables, which are allowed to use when property value calculated dynamically
90
-     * @return string
91
-     */
92
-    public static function htmlOptionsToString(array $htmlOptions, array $context = []) : string
93
-    {
94
-        if (empty($htmlOptions)) {
95
-            return '';
96
-        }
97
-
98
-        $out = [];
99
-
100
-        foreach ($htmlOptions as $k => $v) {
101
-
102
-            if ($v instanceof \Closure) {
103
-                $v = call_user_func_array($v, $context);
104
-            }
105
-
106
-            $out[] = htmlentities($k) . '="' . htmlentities($v, ENT_COMPAT) . '"';
107
-        }
108
-
109
-        return implode(' ', $out);
110
-    }
111
-
112
-    /**
113
-     * Allows to make column title by it key or attribute name
114
-     * @param string|int $key
115
-     * @return string
116
-     */
117
-    public static function columnTitle($key) : string
118
-    {
119
-        if (is_numeric($key)) {
120
-            return 'Column';
121
-        }
122
-
123
-        return ucwords(
124
-            trim(
125
-                preg_replace_callback(
126
-                    '/([A-Z]|_|\.)/',
127
-                    function($word) {
128
-                        $word = $word[0];
129
-
130
-                        if ($word == '_' || $word == '.') {
131
-                            return ' ';
132
-                        }
133
-
134
-                        return ' ' . strtolower($word);
135
-                    },
136
-                    $key
137
-                )
138
-            )
139
-        );
140
-    }
141
-
142
-    /**
143
-     * Helper for internal purposes
144
-     * @param $id
145
-     * @param $component
146
-     * @return string
147
-     */
148
-    public static function gridIdFormatter($id, $component)
149
-    {
150
-        if ($id == 0) {
151
-            return $component;
152
-        }
153
-
154
-        return 'grid[' . $id . '][' . $component . ']';
155
-    }
156
-
157
-    /**
158
-     * Generates page url with all requested params from request
159
-     * @param $gridId
160
-     * @param $page
161
-     */
162
-    public static function pageUrl($gridId, $page)
163
-    {
164
-        return url()->current() . '?' . Arr::query([\Woo\GridView\GridViewHelper::gridIdFormatter($gridId, 'page') => $page] + request()->query());
165
-    }
26
+	/**
27
+	 * A list of grid aliases
28
+	 * @var array
29
+	 */
30
+	private static $aliases = [
31
+		'column' => [
32
+			'attribute' => AttributeColumn::class,
33
+			'raw' => CallbackColumn::class,
34
+			'callback' => CallbackColumn::class,
35
+			'actions' => ActionsColumn::class,
36
+			'view' => ViewColumn::class,
37
+		],
38
+		'formatter' => [
39
+			'email' => EmailFormatter::class,
40
+			'image' => ImageFormatter::class,
41
+			'text' => TextFormatter::class,
42
+			'url' => UrlFormatter::class,
43
+			'raw' => RawFormatter::class,
44
+		],
45
+		'filter' => [
46
+			'text' => TextFilter::class,
47
+			'dropdown' => DropdownFilter::class,
48
+		],
49
+		'renderer' => [
50
+			'default' => DefaultRenderer::class,
51
+		],
52
+		'action' => [
53
+			'delete' => DeleteAction::class,
54
+			'update' => EditAction::class,
55
+			'edit' => EditAction::class,
56
+			'show' => ShowAction::class,
57
+			'view' => ShowAction::class,
58
+			'action' => Action::class,
59
+		]
60
+	];
61
+
62
+	private function __construct() {}
63
+
64
+	/**
65
+	 * Useful in case you want to register a new alias for your project
66
+	 * @param string $context
67
+	 * @param string $alias
68
+	 * @param string $aliasTo
69
+	 */
70
+	public static function registerAlias(string $context, string $alias, string $aliasTo)
71
+	{
72
+		self::$aliases[$context][$alias] = $aliasTo;
73
+	}
74
+
75
+	/**
76
+	 * Allows to resolve class name by its alias
77
+	 * @param string $context
78
+	 * @param string $alias
79
+	 * @return mixed
80
+	 */
81
+	public static function resolveAlias(string $context, string $alias)
82
+	{
83
+		return self::$aliases[$context][$alias] ?? $alias;
84
+	}
85
+
86
+	/**
87
+	 * Allows to convert options array to html string
88
+	 * @param array $htmlOptions
89
+	 * @param array $context - context is variables, which are allowed to use when property value calculated dynamically
90
+	 * @return string
91
+	 */
92
+	public static function htmlOptionsToString(array $htmlOptions, array $context = []) : string
93
+	{
94
+		if (empty($htmlOptions)) {
95
+			return '';
96
+		}
97
+
98
+		$out = [];
99
+
100
+		foreach ($htmlOptions as $k => $v) {
101
+
102
+			if ($v instanceof \Closure) {
103
+				$v = call_user_func_array($v, $context);
104
+			}
105
+
106
+			$out[] = htmlentities($k) . '="' . htmlentities($v, ENT_COMPAT) . '"';
107
+		}
108
+
109
+		return implode(' ', $out);
110
+	}
111
+
112
+	/**
113
+	 * Allows to make column title by it key or attribute name
114
+	 * @param string|int $key
115
+	 * @return string
116
+	 */
117
+	public static function columnTitle($key) : string
118
+	{
119
+		if (is_numeric($key)) {
120
+			return 'Column';
121
+		}
122
+
123
+		return ucwords(
124
+			trim(
125
+				preg_replace_callback(
126
+					'/([A-Z]|_|\.)/',
127
+					function($word) {
128
+						$word = $word[0];
129
+
130
+						if ($word == '_' || $word == '.') {
131
+							return ' ';
132
+						}
133
+
134
+						return ' ' . strtolower($word);
135
+					},
136
+					$key
137
+				)
138
+			)
139
+		);
140
+	}
141
+
142
+	/**
143
+	 * Helper for internal purposes
144
+	 * @param $id
145
+	 * @param $component
146
+	 * @return string
147
+	 */
148
+	public static function gridIdFormatter($id, $component)
149
+	{
150
+		if ($id == 0) {
151
+			return $component;
152
+		}
153
+
154
+		return 'grid[' . $id . '][' . $component . ']';
155
+	}
156
+
157
+	/**
158
+	 * Generates page url with all requested params from request
159
+	 * @param $gridId
160
+	 * @param $page
161
+	 */
162
+	public static function pageUrl($gridId, $page)
163
+	{
164
+		return url()->current() . '?' . Arr::query([\Woo\GridView\GridViewHelper::gridIdFormatter($gridId, 'page') => $page] + request()->query());
165
+	}
166 166
 }
Please login to merge, or discard this patch.
src/DataProviders/EloquentDataProvider.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -7,58 +7,58 @@
 block discarded – undo
7 7
 
8 8
 class EloquentDataProvider extends BaseDataProvider
9 9
 {
10
-    protected $query;
10
+	protected $query;
11 11
 
12
-    /**
13
-     * EloquentDataProvider constructor.
14
-     * @param Builder $query
15
-     */
16
-    public function __construct(Builder $query)
17
-    {
18
-        $this->query = clone $query;
19
-    }
12
+	/**
13
+	 * EloquentDataProvider constructor.
14
+	 * @param Builder $query
15
+	 */
16
+	public function __construct(Builder $query)
17
+	{
18
+		$this->query = clone $query;
19
+	}
20 20
 
21 21
 
22
-    /**
23
-     * @param GridViewRequest $request
24
-     * @return Builder
25
-     */
26
-    protected function baseQuery(GridViewRequest $request)
27
-    {
28
-        $query = clone $this->query;
22
+	/**
23
+	 * @param GridViewRequest $request
24
+	 * @return Builder
25
+	 */
26
+	protected function baseQuery(GridViewRequest $request)
27
+	{
28
+		$query = clone $this->query;
29 29
 
30
-        foreach ($request->filters as $field => $value) {
31
-            $query->where($field, 'LIKE', '%' . $value . '%');
32
-        }
30
+		foreach ($request->filters as $field => $value) {
31
+			$query->where($field, 'LIKE', '%' . $value . '%');
32
+		}
33 33
 
34
-        if ($request->sortColumn) {
35
-            $query->orderBy($request->sortColumn, $request->sortOrder);
36
-        }
34
+		if ($request->sortColumn) {
35
+			$query->orderBy($request->sortColumn, $request->sortOrder);
36
+		}
37 37
 
38
-        return $query;
39
-    }
38
+		return $query;
39
+	}
40 40
 
41
-    /**
42
-     * @inheritdoc
43
-     */
44
-    public function getCount(GridViewRequest $request) : int
45
-    {
46
-        return $this->baseQuery($request)->count();
47
-    }
41
+	/**
42
+	 * @inheritdoc
43
+	 */
44
+	public function getCount(GridViewRequest $request) : int
45
+	{
46
+		return $this->baseQuery($request)->count();
47
+	}
48 48
 
49
-    /**
50
-     * @inheritdoc
51
-     */
52
-    public function getData(GridViewRequest $request)
53
-    {
54
-        $query = $this->baseQuery($request);
49
+	/**
50
+	 * @inheritdoc
51
+	 */
52
+	public function getData(GridViewRequest $request)
53
+	{
54
+		$query = $this->baseQuery($request);
55 55
 
56
-        if ($request->perPage == 0) {
57
-            return $query->get();
58
-        }
56
+		if ($request->perPage == 0) {
57
+			return $query->get();
58
+		}
59 59
 
60
-        return $query->offset(($request->page - 1) * $request->perPage)
61
-            ->limit($request->perPage)
62
-            ->get();
63
-    }
60
+		return $query->offset(($request->page - 1) * $request->perPage)
61
+			->limit($request->perPage)
62
+			->get();
63
+	}
64 64
 }
Please login to merge, or discard this patch.