-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathhelpers.php
219 lines (199 loc) · 4.32 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
if ( ! function_exists('dd'))
{
/**
* Dies and dumps.
*
* @return string
*/
function dd()
{
call_user_func_array('dump', func_get_args());
die;
}
}
if ( ! function_exists('content_directory'))
{
/**
* Gets the content directory.
*
* @return string
*/
function content_directory()
{
return WP_CONTENT_DIR;
}
}
if ( ! function_exists('plugin_directory'))
{
/**
* Gets the plugin directory.
*
* @return string
*/
function plugin_directory()
{
return WP_PLUGIN_DIR;
}
}
if ( ! function_exists('response'))
{
/**
* Generates a response.
*
* @param string $body
* @param integer $status
* @param array $headers
* @return \Herbert\Framework\Response
*/
function response($body, $status = 200, $headers = null)
{
return new Herbert\Framework\Response($body, $status, $headers);
}
}
if ( ! function_exists('json_response'))
{
/**
* Generates a json response.
*
* @param mixed $jsonable
* @param integer $status
* @param array $headers
* @return \Herbert\Framework\Response
*/
function json_response($jsonable, $status = 200, $headers = null)
{
return new Herbert\Framework\JsonResponse($jsonable, $status, $headers);
}
}
if ( ! function_exists('redirect_response'))
{
/**
* Generates a redirect response.
*
* @param string $url
* @param integer $status
* @param array $headers
* @return \Herbert\Framework\Response
*/
function redirect_response($url, $status = 302, $headers = null)
{
return new Herbert\Framework\RedirectResponse($url, $status, $headers);
}
}
if ( ! function_exists('herbert'))
{
/**
* Gets the herbert container.
*
* @param string $binding
* @return string
*/
function herbert($binding = null)
{
$instance = Herbert\Framework\Application::getInstance();
if ( ! $binding)
{
return $instance;
}
return $instance[$binding];
}
}
if ( ! function_exists('errors'))
{
/**
* Get the errors.
*
* @param string key
* @return array
*/
function errors($key = null)
{
$errors = herbert('errors');
$errors = isset($errors[0]) ? $errors[0] : $errors;
if (!$key)
{
return $errors;
}
return array_get($errors, $key);
}
}
if ( ! function_exists('session'))
{
/**
* Gets the session or a key from the session.
*
* @param string $key
* @param mixed $default
* @return \Illuminate\Session\Store|mixed
*/
function session($key = null, $default = null)
{
if ($key === null)
{
return herbert('session');
}
return herbert('session')->get($key, $default);
}
}
if ( ! function_exists('session_flashed'))
{
/**
* Gets the session flashbag or a key from the session flashbag.
*
* @param string $key
* @param mixed $default
* @return \Illuminate\Session\Store|mixed
*/
function session_flashed($key = null, $default = [])
{
if ($key === null)
{
return herbert('session')->getFlashBag();
}
return herbert('session')->getFlashBag()->get($key, $default);
}
}
if ( ! function_exists('view'))
{
/**
* Renders a twig view.
*
* @param string $name
* @param array $context
* @return string
*/
function view($name, $context = [])
{
return response(herbert('Twig_Environment')->render($name, $context));
}
}
if ( ! function_exists('panel_url'))
{
/**
* Gets the url to a panel.
*
* @param string $name
* @param array $query
* @return string
*/
function panel_url($name, $query = [])
{
return add_query_arg($query, herbert('panel')->url($name));
}
}
if ( ! function_exists('route_url'))
{
/**
* Gets the url to a route.
*
* @param string $name
* @param array $args
* @param array $query
* @return string
*/
function route_url($name, $args = [], $query = [])
{
return add_query_arg($query, herbert('router')->url($name, $args));
}
}