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