Completed
Push — master ( 04a99a...21cf60 )
by Denis
01:21
created
src/functions.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,5 +6,5 @@
 block discarded – undo
6 6
  * @return \Woo\GridView\GridView
7 7
  */
8 8
 function grid(array $config) {
9
-    return \Woo\GridView\GridView::make($config);
9
+	return \Woo\GridView\GridView::make($config);
10 10
 }
11 11
\ No newline at end of file
Please login to merge, or discard this patch.
src/DataProviders/DataProviderInterface.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -4,24 +4,24 @@
 block discarded – undo
4 4
 
5 5
 interface DataProviderInterface
6 6
 {
7
-    /**
8
-     * Should return total amount of rows
9
-     * @return int
10
-     */
11
-    public function getCount() : int;
7
+	/**
8
+	 * Should return total amount of rows
9
+	 * @return int
10
+	 */
11
+	public function getCount() : int;
12 12
 
13
-    /**
14
-     * Should return amount of pages
15
-     * @param int $perPage - amount of records per page
16
-     * @return int
17
-     */
18
-    public function getTotalPages(int $perPage) : int;
13
+	/**
14
+	 * Should return amount of pages
15
+	 * @param int $perPage - amount of records per page
16
+	 * @return int
17
+	 */
18
+	public function getTotalPages(int $perPage) : int;
19 19
 
20
-    /**
21
-     * Should return a list of data for current page
22
-     * @param int $page
23
-     * @param int $perPage - amount of records per page
24
-     * @return mixed
25
-     */
26
-    public function getData(int $page, int $perPage);
20
+	/**
21
+	 * Should return a list of data for current page
22
+	 * @param int $page
23
+	 * @param int $perPage - amount of records per page
24
+	 * @return mixed
25
+	 */
26
+	public function getData(int $page, int $perPage);
27 27
 }
28 28
\ No newline at end of file
Please login to merge, or discard this patch.
src/GridViewServiceProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
 	 */
14 14
 	public function boot()
15 15
 	{
16
-		$this->loadViewsFrom(__DIR__.'/../views', 'woo_gridview');
16
+		$this->loadViewsFrom(__DIR__ . '/../views', 'woo_gridview');
17 17
 
18 18
 		require_once __DIR__ . '/functions.php';
19 19
 	}
Please login to merge, or discard this patch.
src/traits/Configurable.php 2 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -8,7 +8,6 @@  discard block
 block discarded – undo
8 8
 {
9 9
     /**
10 10
      * Allows to load config into object properties
11
-     * @param object $object
12 11
      * @param array $config
13 12
      * @throws GridViewConfigException
14 13
      */
@@ -36,7 +35,6 @@  discard block
 block discarded – undo
36 35
     /**
37 36
      * Allows to test attributes and types in config
38 37
      * @param $object
39
-     * @param array $tests
40 38
      * @throws GridViewConfigException
41 39
      */
42 40
     protected function testConfig()
Please login to merge, or discard this patch.
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -6,83 +6,83 @@
 block discarded – undo
6 6
 
7 7
 trait Configurable
8 8
 {
9
-    /**
10
-     * Allows to load config into object properties
11
-     * @param object $object
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
-     * Override this method in classes
29
-     * @return array
30
-     */
31
-    protected function configTests() : array
32
-    {
33
-        return [];
34
-    }
35
-
36
-    /**
37
-     * Allows to test attributes and types in config
38
-     * @param $object
39
-     * @param array $tests
40
-     * @throws GridViewConfigException
41
-     */
42
-    protected function testConfig()
43
-    {
44
-        foreach ($this->configTests() as $property => $test) {
45
-
46
-            if (!property_exists($this, $property)) {
47
-                throw new GridViewConfigException(
48
-                    'Unable to test ' . get_class($this) . ': property ' . $property . ' does not exist'
49
-                );
50
-            }
51
-
52
-            if (is_scalar($test)) {
53
-
54
-                $testPassed = true;
55
-
56
-                switch ($test) {
57
-                    case 'int':
58
-                        $testPassed = is_numeric($this->$property);
59
-                        break;
60
-
61
-                    case 'string':
62
-                        $testPassed = is_string($this->$property);
63
-                        break;
64
-
65
-                    case 'array':
66
-                        $testPassed = is_array($this->$property);
67
-                        break;
68
-
69
-                    case 'closure':
70
-                        $testPassed = $this->$property instanceof \Closure;
71
-                        break;
72
-
73
-                    case 'any':
74
-                        break;
75
-
76
-                    default:
77
-                        $testPassed = is_subclass_of($this->$property, $test);
78
-                }
79
-
80
-                if (!$testPassed) {
81
-                    throw new GridViewConfigException('
9
+	/**
10
+	 * Allows to load config into object properties
11
+	 * @param object $object
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
+	 * Override this method in classes
29
+	 * @return array
30
+	 */
31
+	protected function configTests() : array
32
+	{
33
+		return [];
34
+	}
35
+
36
+	/**
37
+	 * Allows to test attributes and types in config
38
+	 * @param $object
39
+	 * @param array $tests
40
+	 * @throws GridViewConfigException
41
+	 */
42
+	protected function testConfig()
43
+	{
44
+		foreach ($this->configTests() as $property => $test) {
45
+
46
+			if (!property_exists($this, $property)) {
47
+				throw new GridViewConfigException(
48
+					'Unable to test ' . get_class($this) . ': property ' . $property . ' does not exist'
49
+				);
50
+			}
51
+
52
+			if (is_scalar($test)) {
53
+
54
+				$testPassed = true;
55
+
56
+				switch ($test) {
57
+					case 'int':
58
+						$testPassed = is_numeric($this->$property);
59
+						break;
60
+
61
+					case 'string':
62
+						$testPassed = is_string($this->$property);
63
+						break;
64
+
65
+					case 'array':
66
+						$testPassed = is_array($this->$property);
67
+						break;
68
+
69
+					case 'closure':
70
+						$testPassed = $this->$property instanceof \Closure;
71
+						break;
72
+
73
+					case 'any':
74
+						break;
75
+
76
+					default:
77
+						$testPassed = is_subclass_of($this->$property, $test);
78
+				}
79
+
80
+				if (!$testPassed) {
81
+					throw new GridViewConfigException('
82 82
                         Test ' . $test . ' has failed on ' . get_class($this) . '::' . $property
83
-                    );
84
-                }
85
-            }
86
-        }
87
-    }
83
+					);
84
+				}
85
+			}
86
+		}
87
+	}
88 88
 }
89 89
\ No newline at end of file
Please login to merge, or discard this patch.
src/Columns/AttributeColumn.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -7,47 +7,47 @@
 block discarded – undo
7 7
 
8 8
 class AttributeColumn extends BaseColumn
9 9
 {
10
-    /**
11
-     * AttributeColumn constructor.
12
-     * @param $config
13
-     * @throws GridViewConfigException
14
-     */
15
-    public function __construct($config)
16
-    {
17
-        parent::__construct($config);
18
-
19
-        if (empty($this->title)) {
20
-            $this->title = ucfirst(str_replace('_', ' ', $this->value));
21
-        }
22
-    }
23
-
24
-    /**
25
-     * @return array
26
-     */
27
-    protected function configTests(): array
28
-    {
29
-        return array_merge(parent::configTests(), [
30
-            'value' => 'string',
31
-        ]);
32
-    }
33
-
34
-    /**
35
-     * @inheritdoc
36
-     * @throws ColumnRenderException
37
-     * @throws GridViewConfigException
38
-     */
39
-    public function _renderValue($row)
40
-    {
41
-        if (is_array($row)) {
42
-
43
-            if (isset($row[$this->value]) && $row[$this->value] !== null) {
44
-                return $row[$this->value];
45
-            }
46
-
47
-        } elseif (isset($row->{$this->value}) && $row->{$this->value} !== null) {
48
-            return $row->{$this->value};
49
-        }
50
-
51
-        return $this->emptyValue;
52
-    }
10
+	/**
11
+	 * AttributeColumn constructor.
12
+	 * @param $config
13
+	 * @throws GridViewConfigException
14
+	 */
15
+	public function __construct($config)
16
+	{
17
+		parent::__construct($config);
18
+
19
+		if (empty($this->title)) {
20
+			$this->title = ucfirst(str_replace('_', ' ', $this->value));
21
+		}
22
+	}
23
+
24
+	/**
25
+	 * @return array
26
+	 */
27
+	protected function configTests(): array
28
+	{
29
+		return array_merge(parent::configTests(), [
30
+			'value' => 'string',
31
+		]);
32
+	}
33
+
34
+	/**
35
+	 * @inheritdoc
36
+	 * @throws ColumnRenderException
37
+	 * @throws GridViewConfigException
38
+	 */
39
+	public function _renderValue($row)
40
+	{
41
+		if (is_array($row)) {
42
+
43
+			if (isset($row[$this->value]) && $row[$this->value] !== null) {
44
+				return $row[$this->value];
45
+			}
46
+
47
+		} elseif (isset($row->{$this->value}) && $row->{$this->value} !== null) {
48
+			return $row->{$this->value};
49
+		}
50
+
51
+		return $this->emptyValue;
52
+	}
53 53
 }
54 54
\ No newline at end of file
Please login to merge, or discard this patch.
src/Columns/BaseColumn.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -8,119 +8,119 @@
 block discarded – undo
8 8
 
9 9
 abstract class BaseColumn
10 10
 {
11
-    use Configurable;
12
-
13
-    /**
14
-     * @var string
15
-     */
16
-    public $title = '';
17
-
18
-    /**
19
-     * @var string|mixed
20
-     */
21
-    public $value = '';
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    public $headerHtmlOptions = [];
27
-
28
-    /**
29
-     * @var array
30
-     */
31
-    public $contentHtmlOptions = [];
32
-
33
-    /**
34
-     * @var string - allowed: raw, url, email, text, image
35
-     */
36
-    public $contentFormat = 'text';
37
-
38
-    /**
39
-     * Value when
40
-     * @var string
41
-     */
42
-    public $emptyValue = '-';
43
-
44
-    /**
45
-     * BaseColumn constructor.
46
-     * @param array $config
47
-     * @throws \Woo\GridView\Exceptions\GridViewConfigException
48
-     */
49
-    public function __construct(array $config)
50
-    {
51
-        $this->loadConfig($config);
52
-    }
53
-
54
-    /**
55
-     * @return array
56
-     */
57
-    protected function configTests(): array
58
-    {
59
-        return [
60
-            'title' => 'string',
61
-            'value' => 'any',
62
-            'headerHtmlOptions' => 'array',
63
-            'contentHtmlOptions' => 'array',
64
-            'contentFormat' => 'string',
65
-            'emptyValue' => 'string',
66
-        ];
67
-    }
68
-
69
-    /**
70
-     * Formatted header html options
71
-     * @return string
72
-     */
73
-    public function headerHtmlOptions() : string
74
-    {
75
-        return GridViewHelper::htmlOptionsToString($this->headerHtmlOptions);
76
-    }
77
-
78
-    /**
79
-     * Formatted content html options
80
-     * @param array $context
81
-     * @return string
82
-     */
83
-    public function contentHtmlOptions(array $context) : string
84
-    {
85
-        return GridViewHelper::htmlOptionsToString($this->contentHtmlOptions, $context);
86
-    }
87
-
88
-    /**
89
-     * Render column value for row
90
-     * @param array|object $row
91
-     * @return string|mixed
92
-     */
93
-    protected abstract function _renderValue($row);
94
-
95
-    /**
96
-     * Renders column content
97
-     * @param $row
98
-     * @return string
99
-     * @throws GridViewConfigException
100
-     */
101
-    public function renderValue($row)
102
-    {
103
-        $value = $this->_renderValue($row);
104
-
105
-        switch ($this->contentFormat) {
106
-            case 'raw':
107
-                return $value;
108
-
109
-            case 'text':
110
-                return htmlentities($value);
111
-
112
-            case 'url':
113
-                return '<a href="' . htmlspecialchars($value, ENT_QUOTES) . '">' . htmlentities($value) . '</a>';
114
-
115
-            case 'email':
116
-                return '<a href="mailto:' . htmlspecialchars($value, ENT_QUOTES) . '">' . htmlentities($value) . '</a>';
117
-
118
-            case 'image':
119
-                return '<img src="' . htmlspecialchars($value, ENT_QUOTES) . '">';
120
-
121
-            default:
122
-                throw new GridViewConfigException('Invalid content format for attribute collumn: ' . $this->value);
123
-        }
124
-    }
11
+	use Configurable;
12
+
13
+	/**
14
+	 * @var string
15
+	 */
16
+	public $title = '';
17
+
18
+	/**
19
+	 * @var string|mixed
20
+	 */
21
+	public $value = '';
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	public $headerHtmlOptions = [];
27
+
28
+	/**
29
+	 * @var array
30
+	 */
31
+	public $contentHtmlOptions = [];
32
+
33
+	/**
34
+	 * @var string - allowed: raw, url, email, text, image
35
+	 */
36
+	public $contentFormat = 'text';
37
+
38
+	/**
39
+	 * Value when
40
+	 * @var string
41
+	 */
42
+	public $emptyValue = '-';
43
+
44
+	/**
45
+	 * BaseColumn constructor.
46
+	 * @param array $config
47
+	 * @throws \Woo\GridView\Exceptions\GridViewConfigException
48
+	 */
49
+	public function __construct(array $config)
50
+	{
51
+		$this->loadConfig($config);
52
+	}
53
+
54
+	/**
55
+	 * @return array
56
+	 */
57
+	protected function configTests(): array
58
+	{
59
+		return [
60
+			'title' => 'string',
61
+			'value' => 'any',
62
+			'headerHtmlOptions' => 'array',
63
+			'contentHtmlOptions' => 'array',
64
+			'contentFormat' => 'string',
65
+			'emptyValue' => 'string',
66
+		];
67
+	}
68
+
69
+	/**
70
+	 * Formatted header html options
71
+	 * @return string
72
+	 */
73
+	public function headerHtmlOptions() : string
74
+	{
75
+		return GridViewHelper::htmlOptionsToString($this->headerHtmlOptions);
76
+	}
77
+
78
+	/**
79
+	 * Formatted content html options
80
+	 * @param array $context
81
+	 * @return string
82
+	 */
83
+	public function contentHtmlOptions(array $context) : string
84
+	{
85
+		return GridViewHelper::htmlOptionsToString($this->contentHtmlOptions, $context);
86
+	}
87
+
88
+	/**
89
+	 * Render column value for row
90
+	 * @param array|object $row
91
+	 * @return string|mixed
92
+	 */
93
+	protected abstract function _renderValue($row);
94
+
95
+	/**
96
+	 * Renders column content
97
+	 * @param $row
98
+	 * @return string
99
+	 * @throws GridViewConfigException
100
+	 */
101
+	public function renderValue($row)
102
+	{
103
+		$value = $this->_renderValue($row);
104
+
105
+		switch ($this->contentFormat) {
106
+			case 'raw':
107
+				return $value;
108
+
109
+			case 'text':
110
+				return htmlentities($value);
111
+
112
+			case 'url':
113
+				return '<a href="' . htmlspecialchars($value, ENT_QUOTES) . '">' . htmlentities($value) . '</a>';
114
+
115
+			case 'email':
116
+				return '<a href="mailto:' . htmlspecialchars($value, ENT_QUOTES) . '">' . htmlentities($value) . '</a>';
117
+
118
+			case 'image':
119
+				return '<img src="' . htmlspecialchars($value, ENT_QUOTES) . '">';
120
+
121
+			default:
122
+				throw new GridViewConfigException('Invalid content format for attribute collumn: ' . $this->value);
123
+		}
124
+	}
125 125
 
126 126
 }
127 127
\ No newline at end of file
Please login to merge, or discard this patch.
src/Columns/RawColumn.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 RawColumn extends BaseColumn
6 6
 {
7
-    /**
8
-     * @var string
9
-     */
10
-    public $contentFormat = 'raw';
7
+	/**
8
+	 * @var string
9
+	 */
10
+	public $contentFormat = '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/GridView.php 1 patch
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -11,135 +11,135 @@
 block discarded – undo
11 11
 
12 12
 class GridView
13 13
 {
14
-    use Configurable;
15
-
16
-    /**
17
-     * @var DataProviderInterface
18
-     */
19
-    public $dataProvider;
20
-
21
-    /**
22
-     * @var array
23
-     */
24
-    public $columns = [];
25
-
26
-    /**
27
-     * @var array
28
-     */
29
-    public $columnOptions = [
30
-        'class' => AttributeColumn::class,
31
-    ];
32
-
33
-    /**
34
-     * @var string|BaseRenderer
35
-     */
36
-    public $renderer = DefaultRenderer::class;
37
-
38
-    /**
39
-     * @var array
40
-     */
41
-    public $rendererOptions = [];
42
-
43
-    /**
44
-     * @var int
45
-     */
46
-    public $rowsPerPage = 25;
47
-
48
-    /**
49
-     * @var array
50
-     */
51
-    public $tableHtmlOptions = [
52
-        'class' => 'table table-bordered gridview-table',
53
-    ];
54
-
55
-    /**
56
-     * GridView constructor.
57
-     * @param array $config
58
-     * @throws Exceptions\GridViewConfigException
59
-     */
60
-    public function __construct(array $config)
61
-    {
62
-        $this->loadConfig($config);
63
-        $this->buildColumns();
64
-    }
65
-
66
-    /**
67
-     * @return array
68
-     */
69
-    protected function configTests(): array
70
-    {
71
-        return [
72
-            'dataProvider' => DataProviderInterface::class,
73
-            'columns' => 'array',
74
-            'renderer' => BaseRenderer::class,
75
-            'rowsPerPage' => 'int',
76
-            'tableHtmlOptions' => 'array',
77
-        ];
78
-    }
79
-
80
-    /**
81
-     * Build columns into objects
82
-     */
83
-    protected function buildColumns()
84
-    {
85
-        foreach ($this->columns as &$columnOptions) {
86
-
87
-            /**
88
-             * In case of when column is already build
89
-             */
90
-            if (is_object($columnOptions)) {
91
-                continue;
92
-            }
93
-
94
-            /**
95
-             * When only attribute name/value passed
96
-             */
97
-            if (is_string($columnOptions)) {
98
-                $columnOptions = [
99
-                    'value' => $columnOptions,
100
-                ];
101
-            }
102
-
103
-            $columnOptions = array_merge($this->columnOptions, $columnOptions);
104
-
105
-            $className = GridViewHelper::resolveAlias('column', $columnOptions['class']);
106
-            $columnOptions = new $className($columnOptions);
107
-        }
108
-    }
109
-
110
-    /**
111
-     * Makes an instance
112
-     * @param $params
113
-     * @return GridView
114
-     * @throws Exceptions\GridViewConfigException
115
-     */
116
-    public static function make($params)
117
-    {
118
-        return new self($params);
119
-    }
120
-
121
-    /**
122
-     * Draws widget and return html code
123
-     * @return string
124
-     */
125
-    public function render()
126
-    {
127
-        if (!is_object($this->renderer)) {
128
-
129
-            $className = GridViewHelper::resolveAlias('renderer', $this->renderer);
130
-
131
-            $this->renderer = new $className($this->rendererOptions);
132
-        }
133
-
134
-        return $this->renderer->render($this);
135
-    }
136
-
137
-    /**
138
-     * Wrapper for draw method
139
-     * @see View::draw()
140
-     */
141
-    public function __toString()
142
-    {
143
-        return $this->render();
144
-    }
14
+	use Configurable;
15
+
16
+	/**
17
+	 * @var DataProviderInterface
18
+	 */
19
+	public $dataProvider;
20
+
21
+	/**
22
+	 * @var array
23
+	 */
24
+	public $columns = [];
25
+
26
+	/**
27
+	 * @var array
28
+	 */
29
+	public $columnOptions = [
30
+		'class' => AttributeColumn::class,
31
+	];
32
+
33
+	/**
34
+	 * @var string|BaseRenderer
35
+	 */
36
+	public $renderer = DefaultRenderer::class;
37
+
38
+	/**
39
+	 * @var array
40
+	 */
41
+	public $rendererOptions = [];
42
+
43
+	/**
44
+	 * @var int
45
+	 */
46
+	public $rowsPerPage = 25;
47
+
48
+	/**
49
+	 * @var array
50
+	 */
51
+	public $tableHtmlOptions = [
52
+		'class' => 'table table-bordered gridview-table',
53
+	];
54
+
55
+	/**
56
+	 * GridView constructor.
57
+	 * @param array $config
58
+	 * @throws Exceptions\GridViewConfigException
59
+	 */
60
+	public function __construct(array $config)
61
+	{
62
+		$this->loadConfig($config);
63
+		$this->buildColumns();
64
+	}
65
+
66
+	/**
67
+	 * @return array
68
+	 */
69
+	protected function configTests(): array
70
+	{
71
+		return [
72
+			'dataProvider' => DataProviderInterface::class,
73
+			'columns' => 'array',
74
+			'renderer' => BaseRenderer::class,
75
+			'rowsPerPage' => 'int',
76
+			'tableHtmlOptions' => 'array',
77
+		];
78
+	}
79
+
80
+	/**
81
+	 * Build columns into objects
82
+	 */
83
+	protected function buildColumns()
84
+	{
85
+		foreach ($this->columns as &$columnOptions) {
86
+
87
+			/**
88
+			 * In case of when column is already build
89
+			 */
90
+			if (is_object($columnOptions)) {
91
+				continue;
92
+			}
93
+
94
+			/**
95
+			 * When only attribute name/value passed
96
+			 */
97
+			if (is_string($columnOptions)) {
98
+				$columnOptions = [
99
+					'value' => $columnOptions,
100
+				];
101
+			}
102
+
103
+			$columnOptions = array_merge($this->columnOptions, $columnOptions);
104
+
105
+			$className = GridViewHelper::resolveAlias('column', $columnOptions['class']);
106
+			$columnOptions = new $className($columnOptions);
107
+		}
108
+	}
109
+
110
+	/**
111
+	 * Makes an instance
112
+	 * @param $params
113
+	 * @return GridView
114
+	 * @throws Exceptions\GridViewConfigException
115
+	 */
116
+	public static function make($params)
117
+	{
118
+		return new self($params);
119
+	}
120
+
121
+	/**
122
+	 * Draws widget and return html code
123
+	 * @return string
124
+	 */
125
+	public function render()
126
+	{
127
+		if (!is_object($this->renderer)) {
128
+
129
+			$className = GridViewHelper::resolveAlias('renderer', $this->renderer);
130
+
131
+			$this->renderer = new $className($this->rendererOptions);
132
+		}
133
+
134
+		return $this->renderer->render($this);
135
+	}
136
+
137
+	/**
138
+	 * Wrapper for draw method
139
+	 * @see View::draw()
140
+	 */
141
+	public function __toString()
142
+	{
143
+		return $this->render();
144
+	}
145 145
 }
146 146
\ No newline at end of file
Please login to merge, or discard this patch.
src/GridViewHelper.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -9,57 +9,57 @@
 block discarded – undo
9 9
 
10 10
 class GridViewHelper
11 11
 {
12
-    /**
13
-     * A list of grid aliases
14
-     * @var array
15
-     */
16
-    private static $aliases = [
17
-        'column' => [
18
-            'attribute' => AttributeColumn::class,
19
-            'raw' => RawColumn::class,
20
-            'actions' => ActionsColumn::class,
21
-        ],
22
-        'renderer' => [
23
-            'default' => DefaultRenderer::class,
24
-        ]
25
-    ];
12
+	/**
13
+	 * A list of grid aliases
14
+	 * @var array
15
+	 */
16
+	private static $aliases = [
17
+		'column' => [
18
+			'attribute' => AttributeColumn::class,
19
+			'raw' => RawColumn::class,
20
+			'actions' => ActionsColumn::class,
21
+		],
22
+		'renderer' => [
23
+			'default' => DefaultRenderer::class,
24
+		]
25
+	];
26 26
 
27
-    private function __construct() {}
27
+	private function __construct() {}
28 28
 
29
-    /**
30
-     * Allows to resolve class name by its alias
31
-     * @param string $context
32
-     * @param string $alias
33
-     * @return mixed
34
-     */
35
-    public static function resolveAlias(string $context, string $alias)
36
-    {
37
-        return self::$aliases[$context][$alias] ?? $alias;
38
-    }
29
+	/**
30
+	 * Allows to resolve class name by its alias
31
+	 * @param string $context
32
+	 * @param string $alias
33
+	 * @return mixed
34
+	 */
35
+	public static function resolveAlias(string $context, string $alias)
36
+	{
37
+		return self::$aliases[$context][$alias] ?? $alias;
38
+	}
39 39
 
40
-    /**
41
-     * Allows to convert options array to html string
42
-     * @param array $htmlOptions
43
-     * @param array $context - context is variables, which are allowed to use when property value calculated dynamically
44
-     * @return string
45
-     */
46
-    public static function htmlOptionsToString(array $htmlOptions, array $context = []) : string
47
-    {
48
-        if (empty($htmlOptions)) {
49
-            return '';
50
-        }
40
+	/**
41
+	 * Allows to convert options array to html string
42
+	 * @param array $htmlOptions
43
+	 * @param array $context - context is variables, which are allowed to use when property value calculated dynamically
44
+	 * @return string
45
+	 */
46
+	public static function htmlOptionsToString(array $htmlOptions, array $context = []) : string
47
+	{
48
+		if (empty($htmlOptions)) {
49
+			return '';
50
+		}
51 51
 
52
-        $out = [];
52
+		$out = [];
53 53
 
54
-        foreach ($htmlOptions as $k => $v) {
54
+		foreach ($htmlOptions as $k => $v) {
55 55
 
56
-            if ($v instanceof \Closure) {
57
-                $v = call_user_func_array($v, $context);
58
-            }
56
+			if ($v instanceof \Closure) {
57
+				$v = call_user_func_array($v, $context);
58
+			}
59 59
 
60
-            $out[] = htmlentities($k) . '="' . htmlentities($v, ENT_COMPAT) . '"';
61
-        }
60
+			$out[] = htmlentities($k) . '="' . htmlentities($v, ENT_COMPAT) . '"';
61
+		}
62 62
 
63
-        return implode(' ', $out);
64
-    }
63
+		return implode(' ', $out);
64
+	}
65 65
 }
66 66
\ No newline at end of file
Please login to merge, or discard this patch.