Completed
Push — master ( 251636...00c698 )
by Denis
01:25
created
src/Columns/CallbackColumn.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -4,26 +4,26 @@
 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
-     * @return array
14
-     */
15
-    protected function configTests(): array
16
-    {
17
-        return array_merge(parent::configTests(), [
18
-            'value' => 'closure',
19
-        ]);
20
-    }
12
+	/**
13
+	 * @return array
14
+	 */
15
+	protected function configTests(): array
16
+	{
17
+		return array_merge(parent::configTests(), [
18
+			'value' => 'closure',
19
+		]);
20
+	}
21 21
 
22
-    /**
23
-     * @inheritdoc
24
-     */
25
-    public function _renderValue($row)
26
-    {
27
-        return call_user_func($this->value, $row);
28
-    }
22
+	/**
23
+	 * @inheritdoc
24
+	 */
25
+	public function _renderValue($row)
26
+	{
27
+		return call_user_func($this->value, $row);
28
+	}
29 29
 }
30 30
\ No newline at end of file
Please login to merge, or discard this patch.
src/Columns/ViewColumn.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@
 block discarded – undo
7 7
 
8 8
 class ViewColumn extends BaseColumn
9 9
 {
10
-    public $formatters = [];
10
+	public $formatters = [];
11 11
 
12
-    /**
13
-     * Render column value for row
14
-     * @param array|object $row
15
-     * @return string|mixed
16
-     * @throws Throwable
17
-     */
18
-    protected function _renderValue($row)
19
-    {
20
-        return view($this->value, $row)->render();
21
-    }
12
+	/**
13
+	 * Render column value for row
14
+	 * @param array|object $row
15
+	 * @return string|mixed
16
+	 * @throws Throwable
17
+	 */
18
+	protected function _renderValue($row)
19
+	{
20
+		return view($this->value, $row)->render();
21
+	}
22 22
 }
23 23
\ No newline at end of file
Please login to merge, or discard this patch.
src/Renderers/BaseRenderer.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -9,32 +9,32 @@
 block discarded – undo
9 9
 
10 10
 abstract class BaseRenderer
11 11
 {
12
-    use Configurable;
12
+	use Configurable;
13 13
 
14
-    /**
15
-     * @var GridView
16
-     */
17
-    public $gridView;
14
+	/**
15
+	 * @var GridView
16
+	 */
17
+	public $gridView;
18 18
 
19
-    /**
20
-     * BaseRenderer constructor.
21
-     * @param $config
22
-     * @throws GridViewConfigException
23
-     */
24
-    public function __construct($config)
25
-    {
26
-        $this->loadConfig($config);
27
-    }
19
+	/**
20
+	 * BaseRenderer constructor.
21
+	 * @param $config
22
+	 * @throws GridViewConfigException
23
+	 */
24
+	public function __construct($config)
25
+	{
26
+		$this->loadConfig($config);
27
+	}
28 28
 
29
-    /**
30
-     * @return array
31
-     */
32
-    protected function configTests(): array
33
-    {
34
-        return [
35
-            'gridView' => GridView::class,
36
-        ];
37
-    }
29
+	/**
30
+	 * @return array
31
+	 */
32
+	protected function configTests(): array
33
+	{
34
+		return [
35
+			'gridView' => GridView::class,
36
+		];
37
+	}
38 38
 
39
-    public abstract function render() : string;
39
+	public abstract function render() : string;
40 40
 }
41 41
\ No newline at end of file
Please login to merge, or discard this patch.
src/Renderers/DefaultRenderer.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
7 7
 
8 8
 class DefaultRenderer extends BaseRenderer
9 9
 {
10
-    /**
11
-     * @return string
12
-     * @throws \Throwable
13
-     */
14
-    public function render(): string
15
-    {
16
-        $filters = [];
17
-        foreach ($this->gridView->columns as $column) {
18
-            if ($column->filter) {
19
-                $filters[$column->filter->name] = $this->gridView->getRequest()->getFilterValue($column->filter->name);
20
-            }
21
-        }
10
+	/**
11
+	 * @return string
12
+	 * @throws \Throwable
13
+	 */
14
+	public function render(): string
15
+	{
16
+		$filters = [];
17
+		foreach ($this->gridView->columns as $column) {
18
+			if ($column->filter) {
19
+				$filters[$column->filter->name] = $this->gridView->getRequest()->getFilterValue($column->filter->name);
20
+			}
21
+		}
22 22
 
23
-        return view('woo_gridview::renderers.default', [
24
-            'grid' => $this->gridView,
25
-            'filters' => $filters,
26
-        ])->render();
27
-    }
23
+		return view('woo_gridview::renderers.default', [
24
+			'grid' => $this->gridView,
25
+			'filters' => $filters,
26
+		])->render();
27
+	}
28 28
 }
29 29
\ 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, got ' . print_r($this->$property, 1);
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, got ' . print_r($this->$property, 1);
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/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);
10
+	return new \Woo\GridView\GridView($config);
11 11
 }
12 12
\ No newline at end of file
Please login to merge, or discard this patch.
src/Columns/Actions/Action.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
 
24 24
     /**
25 25
      * Action constructor.
26
-     * @param string|Closure $url
26
+     * @param string $url
27 27
      * @param string $content
28 28
      * @param string $method
29 29
      */
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -6,63 +6,63 @@
 block discarded – undo
6 6
 
7 7
 class Action
8 8
 {
9
-    /**
10
-     * @var string
11
-     */
12
-    protected $url;
9
+	/**
10
+	 * @var string
11
+	 */
12
+	protected $url;
13 13
 
14
-    /**
15
-     * @var string
16
-     */
17
-    protected $content;
14
+	/**
15
+	 * @var string
16
+	 */
17
+	protected $content;
18 18
 
19
-    /**
20
-     * @var string
21
-     */
22
-    protected $method;
19
+	/**
20
+	 * @var string
21
+	 */
22
+	protected $method;
23 23
 
24
-    /**
25
-     * Action constructor.
26
-     * @param string|Closure $url
27
-     * @param string $content
28
-     * @param string $method
29
-     */
30
-    public function __construct($url, string $content, string $method = 'GET')
31
-    {
32
-        $this->url = $url;
24
+	/**
25
+	 * Action constructor.
26
+	 * @param string|Closure $url
27
+	 * @param string $content
28
+	 * @param string $method
29
+	 */
30
+	public function __construct($url, string $content, string $method = 'GET')
31
+	{
32
+		$this->url = $url;
33 33
 
34
-        $this->content = $content;
34
+		$this->content = $content;
35 35
 
36
-        $this->method = $method;
37
-    }
36
+		$this->method = $method;
37
+	}
38 38
 
39
-    protected function buildUrl($row)
40
-    {
41
-        if ($this->url instanceof Closure) {
42
-            return call_user_func($this->url, $row);
43
-        }
39
+	protected function buildUrl($row)
40
+	{
41
+		if ($this->url instanceof Closure) {
42
+			return call_user_func($this->url, $row);
43
+		}
44 44
 
45
-        return preg_replace_callback('/\{([\w\_]+)\}/', function($match) use ($row) {
45
+		return preg_replace_callback('/\{([\w\_]+)\}/', function($match) use ($row) {
46 46
 
47
-            $match = $match[1];
47
+			$match = $match[1];
48 48
 
49
-            if (isset($row->$match)) {
50
-                return $row->$match;
49
+			if (isset($row->$match)) {
50
+				return $row->$match;
51 51
 
52
-            } elseif (isset($row[$match])) {
53
-                return $row[$match];
54
-            }
52
+			} elseif (isset($row[$match])) {
53
+				return $row[$match];
54
+			}
55 55
 
56
-            return '';
57
-        }, $this->url);
58
-    }
56
+			return '';
57
+		}, $this->url);
58
+	}
59 59
 
60
-    public function render($row)
61
-    {
62
-        return view('woo_gridview::columns.action', [
63
-            'url' => $this->buildUrl($row),
64
-            'content' => $this->content,
65
-            'method' => $this->method,
66
-        ])->render();
67
-    }
60
+	public function render($row)
61
+	{
62
+		return view('woo_gridview::columns.action', [
63
+			'url' => $this->buildUrl($row),
64
+			'content' => $this->content,
65
+			'method' => $this->method,
66
+		])->render();
67
+	}
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
src/GridViewHelper.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -20,132 +20,132 @@
 block discarded – undo
20 20
 
21 21
 class GridViewHelper
22 22
 {
23
-    /**
24
-     * A list of grid aliases
25
-     * @var array
26
-     */
27
-    private static $aliases = [
28
-        'column' => [
29
-            'attribute' => AttributeColumn::class,
30
-            'raw' => CallbackColumn::class,
31
-            'callback' => CallbackColumn::class,
32
-            'actions' => ActionsColumn::class,
33
-            'view' => ViewColumn::class,
34
-        ],
35
-        'formatter' => [
36
-            'email' => EmailFormatter::class,
37
-            'image' => ImageFormatter::class,
38
-            'text' => TextFormatter::class,
39
-            'url' => UrlFormatter::class,
40
-        ],
41
-        'filter' => [
42
-            'text' => TextFilter::class,
43
-            'dropdown' => DropdownFilter::class,
44
-        ],
45
-        'renderer' => [
46
-            'default' => DefaultRenderer::class,
47
-        ],
48
-        'action' => [
49
-            'delete' => DeleteAction::class,
50
-            'update' => EditAction::class,
51
-            'edit' => EditAction::class,
52
-            'show' => ShowAction::class,
53
-            'view' => ShowAction::class,
54
-        ]
55
-    ];
56
-
57
-    private function __construct() {}
58
-
59
-    /**
60
-     * Useful in case you want to register a new alias for your project
61
-     * @param string $context
62
-     * @param string $alias
63
-     * @param string $aliasTo
64
-     */
65
-    public static function registerAlias(string $context, string $alias, string $aliasTo)
66
-    {
67
-        self::$aliases[$context][$alias] = $aliasTo;
68
-    }
69
-
70
-    /**
71
-     * Allows to resolve class name by its alias
72
-     * @param string $context
73
-     * @param string $alias
74
-     * @return mixed
75
-     */
76
-    public static function resolveAlias(string $context, string $alias)
77
-    {
78
-        return self::$aliases[$context][$alias] ?? $alias;
79
-    }
80
-
81
-    /**
82
-     * Allows to convert options array to html string
83
-     * @param array $htmlOptions
84
-     * @param array $context - context is variables, which are allowed to use when property value calculated dynamically
85
-     * @return string
86
-     */
87
-    public static function htmlOptionsToString(array $htmlOptions, array $context = []) : string
88
-    {
89
-        if (empty($htmlOptions)) {
90
-            return '';
91
-        }
92
-
93
-        $out = [];
94
-
95
-        foreach ($htmlOptions as $k => $v) {
96
-
97
-            if ($v instanceof \Closure) {
98
-                $v = call_user_func_array($v, $context);
99
-            }
100
-
101
-            $out[] = htmlentities($k) . '="' . htmlentities($v, ENT_COMPAT) . '"';
102
-        }
103
-
104
-        return implode(' ', $out);
105
-    }
106
-
107
-    /**
108
-     * Allows to make column title by it key or attribute name
109
-     * @param string|int $key
110
-     * @return string
111
-     */
112
-    public static function columnTitle($key) : string
113
-    {
114
-        if (is_numeric($key)) {
115
-            return 'Column';
116
-        }
117
-
118
-        return ucwords(
119
-            trim(
120
-                preg_replace_callback(
121
-                    '/([A-Z]|_|\.)/',
122
-                    function($word) {
123
-                        $word = $word[0];
124
-
125
-                        if ($word == '_' || $word == '.') {
126
-                            return ' ';
127
-                        }
128
-
129
-                        return ' ' . strtolower($word);
130
-                    },
131
-                    $key
132
-                )
133
-            )
134
-        );
135
-    }
136
-
137
-    /**
138
-     * Helper for internal purposes
139
-     * @param $id
140
-     * @param $component
141
-     * @return string
142
-     */
143
-    public static function gridIdFormatter($id, $component)
144
-    {
145
-        if ($id == 0) {
146
-            return $component;
147
-        }
148
-
149
-        return 'grid[' . $id . '][' . $component . ']';
150
-    }
23
+	/**
24
+	 * A list of grid aliases
25
+	 * @var array
26
+	 */
27
+	private static $aliases = [
28
+		'column' => [
29
+			'attribute' => AttributeColumn::class,
30
+			'raw' => CallbackColumn::class,
31
+			'callback' => CallbackColumn::class,
32
+			'actions' => ActionsColumn::class,
33
+			'view' => ViewColumn::class,
34
+		],
35
+		'formatter' => [
36
+			'email' => EmailFormatter::class,
37
+			'image' => ImageFormatter::class,
38
+			'text' => TextFormatter::class,
39
+			'url' => UrlFormatter::class,
40
+		],
41
+		'filter' => [
42
+			'text' => TextFilter::class,
43
+			'dropdown' => DropdownFilter::class,
44
+		],
45
+		'renderer' => [
46
+			'default' => DefaultRenderer::class,
47
+		],
48
+		'action' => [
49
+			'delete' => DeleteAction::class,
50
+			'update' => EditAction::class,
51
+			'edit' => EditAction::class,
52
+			'show' => ShowAction::class,
53
+			'view' => ShowAction::class,
54
+		]
55
+	];
56
+
57
+	private function __construct() {}
58
+
59
+	/**
60
+	 * Useful in case you want to register a new alias for your project
61
+	 * @param string $context
62
+	 * @param string $alias
63
+	 * @param string $aliasTo
64
+	 */
65
+	public static function registerAlias(string $context, string $alias, string $aliasTo)
66
+	{
67
+		self::$aliases[$context][$alias] = $aliasTo;
68
+	}
69
+
70
+	/**
71
+	 * Allows to resolve class name by its alias
72
+	 * @param string $context
73
+	 * @param string $alias
74
+	 * @return mixed
75
+	 */
76
+	public static function resolveAlias(string $context, string $alias)
77
+	{
78
+		return self::$aliases[$context][$alias] ?? $alias;
79
+	}
80
+
81
+	/**
82
+	 * Allows to convert options array to html string
83
+	 * @param array $htmlOptions
84
+	 * @param array $context - context is variables, which are allowed to use when property value calculated dynamically
85
+	 * @return string
86
+	 */
87
+	public static function htmlOptionsToString(array $htmlOptions, array $context = []) : string
88
+	{
89
+		if (empty($htmlOptions)) {
90
+			return '';
91
+		}
92
+
93
+		$out = [];
94
+
95
+		foreach ($htmlOptions as $k => $v) {
96
+
97
+			if ($v instanceof \Closure) {
98
+				$v = call_user_func_array($v, $context);
99
+			}
100
+
101
+			$out[] = htmlentities($k) . '="' . htmlentities($v, ENT_COMPAT) . '"';
102
+		}
103
+
104
+		return implode(' ', $out);
105
+	}
106
+
107
+	/**
108
+	 * Allows to make column title by it key or attribute name
109
+	 * @param string|int $key
110
+	 * @return string
111
+	 */
112
+	public static function columnTitle($key) : string
113
+	{
114
+		if (is_numeric($key)) {
115
+			return 'Column';
116
+		}
117
+
118
+		return ucwords(
119
+			trim(
120
+				preg_replace_callback(
121
+					'/([A-Z]|_|\.)/',
122
+					function($word) {
123
+						$word = $word[0];
124
+
125
+						if ($word == '_' || $word == '.') {
126
+							return ' ';
127
+						}
128
+
129
+						return ' ' . strtolower($word);
130
+					},
131
+					$key
132
+				)
133
+			)
134
+		);
135
+	}
136
+
137
+	/**
138
+	 * Helper for internal purposes
139
+	 * @param $id
140
+	 * @param $component
141
+	 * @return string
142
+	 */
143
+	public static function gridIdFormatter($id, $component)
144
+	{
145
+		if ($id == 0) {
146
+			return $component;
147
+		}
148
+
149
+		return 'grid[' . $id . '][' . $component . ']';
150
+	}
151 151
 }
152 152
\ No newline at end of file
Please login to merge, or discard this patch.
src/Columns/BaseColumn.php 1 patch
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -9,146 +9,146 @@
 block discarded – undo
9 9
 
10 10
 abstract class BaseColumn
11 11
 {
12
-    use Configurable;
13
-
14
-    /**
15
-     * Column title
16
-     * @var string
17
-     */
18
-    public $title = '';
19
-
20
-    /**
21
-     * Column value. Could be an attribute,
22
-     * @var string|mixed
23
-     */
24
-    public $value = '';
25
-
26
-    /**
27
-     * @var BaseFilter
28
-     */
29
-    public $filter;
30
-
31
-    /**
32
-     * @var boolean
33
-     */
34
-    public $sortable = true;
35
-
36
-    /**
37
-     * @var array
38
-     */
39
-    public $headerHtmlOptions = [];
40
-
41
-    /**
42
-     * @var array
43
-     */
44
-    public $contentHtmlOptions = [];
45
-
46
-    /**
47
-     * @var array - allowed: raw, url, email, text, image
48
-     */
49
-    public $formatters = ['text'];
50
-
51
-    /**
52
-     * Value when column is empty
53
-     * @var string
54
-     */
55
-    public $emptyValue = '-';
56
-
57
-    /**
58
-     * BaseColumn constructor.
59
-     * @param array $config
60
-     * @throws \Woo\GridView\Exceptions\GridViewConfigException
61
-     */
62
-    public function __construct(array $config)
63
-    {
64
-        $this->loadConfig($config);
65
-
66
-        $this->buildFilter();
67
-    }
68
-
69
-    protected function buildFilter()
70
-    {
71
-        if (is_null($this->filter) || is_object($this->filter)) {
72
-            return;
73
-        }
74
-
75
-        if (is_string($this->filter)) {
76
-            $this->filter = [
77
-                'class' => $this->filter,
78
-                'name' => $this->value,
79
-            ];
80
-        }
81
-
82
-        if (empty($this->filter['class'])) {
83
-            $this->filter['class'] = TextFilter::class;
84
-        }
85
-
86
-        if (empty($this->filter['name'])) {
87
-            $this->filter['name'] = $this->value;
88
-        }
89
-
90
-        $className = GridViewHelper::resolveAlias('filter', $this->filter['class']);
91
-        $this->filter = new $className($this->filter);
92
-    }
93
-
94
-    /**
95
-     * @return array
96
-     */
97
-    protected function configTests(): array
98
-    {
99
-        return [
100
-            'title' => 'string',
101
-            'value' => 'any',
102
-            'headerHtmlOptions' => 'array',
103
-            'contentHtmlOptions' => 'array',
104
-            'formatters' => 'array',
105
-            'emptyValue' => 'string',
106
-            'sortable' => 'bool',
107
-            'filter' => BaseFilter::class . '|null',
108
-        ];
109
-    }
110
-
111
-    /**
112
-     * Formatted header html options
113
-     * @return string
114
-     */
115
-    public function compileHeaderHtmlOptions() : string
116
-    {
117
-        return GridViewHelper::htmlOptionsToString($this->headerHtmlOptions);
118
-    }
119
-
120
-    /**
121
-     * Formatted content html options
122
-     * @param array $context
123
-     * @return string
124
-     */
125
-    public function compileContentHtmlOptions(array $context) : string
126
-    {
127
-        return GridViewHelper::htmlOptionsToString($this->contentHtmlOptions, $context);
128
-    }
129
-
130
-    /**
131
-     * Render column value for row
132
-     * @param array|object $row
133
-     * @return string|mixed
134
-     */
135
-    protected abstract function _renderValue($row);
136
-
137
-    /**
138
-     * Renders column content
139
-     * @param $row
140
-     * @return string
141
-     */
142
-    public function renderValue($row)
143
-    {
144
-        $value = $this->_renderValue($row);
145
-
146
-        foreach ($this->formatters as $formatter) {
147
-            $className = GridViewHelper::resolveAlias('formatter', $formatter);
148
-            $value = (new $className)->format($value);
149
-        }
150
-
151
-        return $value;
152
-    }
12
+	use Configurable;
13
+
14
+	/**
15
+	 * Column title
16
+	 * @var string
17
+	 */
18
+	public $title = '';
19
+
20
+	/**
21
+	 * Column value. Could be an attribute,
22
+	 * @var string|mixed
23
+	 */
24
+	public $value = '';
25
+
26
+	/**
27
+	 * @var BaseFilter
28
+	 */
29
+	public $filter;
30
+
31
+	/**
32
+	 * @var boolean
33
+	 */
34
+	public $sortable = true;
35
+
36
+	/**
37
+	 * @var array
38
+	 */
39
+	public $headerHtmlOptions = [];
40
+
41
+	/**
42
+	 * @var array
43
+	 */
44
+	public $contentHtmlOptions = [];
45
+
46
+	/**
47
+	 * @var array - allowed: raw, url, email, text, image
48
+	 */
49
+	public $formatters = ['text'];
50
+
51
+	/**
52
+	 * Value when column is empty
53
+	 * @var string
54
+	 */
55
+	public $emptyValue = '-';
56
+
57
+	/**
58
+	 * BaseColumn constructor.
59
+	 * @param array $config
60
+	 * @throws \Woo\GridView\Exceptions\GridViewConfigException
61
+	 */
62
+	public function __construct(array $config)
63
+	{
64
+		$this->loadConfig($config);
65
+
66
+		$this->buildFilter();
67
+	}
68
+
69
+	protected function buildFilter()
70
+	{
71
+		if (is_null($this->filter) || is_object($this->filter)) {
72
+			return;
73
+		}
74
+
75
+		if (is_string($this->filter)) {
76
+			$this->filter = [
77
+				'class' => $this->filter,
78
+				'name' => $this->value,
79
+			];
80
+		}
81
+
82
+		if (empty($this->filter['class'])) {
83
+			$this->filter['class'] = TextFilter::class;
84
+		}
85
+
86
+		if (empty($this->filter['name'])) {
87
+			$this->filter['name'] = $this->value;
88
+		}
89
+
90
+		$className = GridViewHelper::resolveAlias('filter', $this->filter['class']);
91
+		$this->filter = new $className($this->filter);
92
+	}
93
+
94
+	/**
95
+	 * @return array
96
+	 */
97
+	protected function configTests(): array
98
+	{
99
+		return [
100
+			'title' => 'string',
101
+			'value' => 'any',
102
+			'headerHtmlOptions' => 'array',
103
+			'contentHtmlOptions' => 'array',
104
+			'formatters' => 'array',
105
+			'emptyValue' => 'string',
106
+			'sortable' => 'bool',
107
+			'filter' => BaseFilter::class . '|null',
108
+		];
109
+	}
110
+
111
+	/**
112
+	 * Formatted header html options
113
+	 * @return string
114
+	 */
115
+	public function compileHeaderHtmlOptions() : string
116
+	{
117
+		return GridViewHelper::htmlOptionsToString($this->headerHtmlOptions);
118
+	}
119
+
120
+	/**
121
+	 * Formatted content html options
122
+	 * @param array $context
123
+	 * @return string
124
+	 */
125
+	public function compileContentHtmlOptions(array $context) : string
126
+	{
127
+		return GridViewHelper::htmlOptionsToString($this->contentHtmlOptions, $context);
128
+	}
129
+
130
+	/**
131
+	 * Render column value for row
132
+	 * @param array|object $row
133
+	 * @return string|mixed
134
+	 */
135
+	protected abstract function _renderValue($row);
136
+
137
+	/**
138
+	 * Renders column content
139
+	 * @param $row
140
+	 * @return string
141
+	 */
142
+	public function renderValue($row)
143
+	{
144
+		$value = $this->_renderValue($row);
145
+
146
+		foreach ($this->formatters as $formatter) {
147
+			$className = GridViewHelper::resolveAlias('formatter', $formatter);
148
+			$value = (new $className)->format($value);
149
+		}
150
+
151
+		return $value;
152
+	}
153 153
 
154 154
 }
155 155
\ No newline at end of file
Please login to merge, or discard this patch.