-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.html
424 lines (250 loc) · 11.3 KB
/
helpers.html
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Helper Functions</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/ubuntu-font.css">
<script src="vendor/modernizr-2.6.2.min.js"></script>
<script type="text/javascript" src="vendor/google-code-prettify/prettify.js"></script>
</head><body><section class="docs-content"><div class="container">
<article class="docs-body"><h1>Helper Functions</h1>
<p><a name="arrays"></a></p>
<h2>Arrays</h2>
<h3>array_add</h3>
<p>The <code>array_add</code> function adds a given key / value pair to the array if the given key doesn't already exist in the array.</p>
<pre class="prettyprint"><code>$array = array('foo' => 'bar');
$array = array_add($array, 'key', 'value');
</code></pre>
<h3>array_divide</h3>
<p>The <code>array_divide</code> function returns two arrays, one containing the keys, and the other containing the values of the original array.</p>
<pre class="prettyprint"><code>$array = array('foo' => 'bar');
list($keys, $values) = array_divide($array);
</code></pre>
<h3>array_dot</h3>
<p>The <code>array_dot</code> function flattens a multi-dimensional array into a single level array that uses "dot" notation to indicate depth.</p>
<pre class="prettyprint"><code>$array = array('foo' => array('bar' => 'baz'));
$array = array_dot($array);
// array('foo.bar' => 'baz');
</code></pre>
<h3>array_except</h3>
<p>The <code>array_except</code> method removes the given key / value pairs from the array.</p>
<pre class="prettyprint"><code>$array = array_except($array, array('keys', 'to', 'remove'));
</code></pre>
<h3>array_fetch</h3>
<p>The <code>array_fetch</code> method returns a flattened array containing the selected nested element.</p>
<pre class="prettyprint"><code>$array = array(array('name' => 'Taylor'), array('name' => 'Dayle'));
var_dump(array_fetch($array, 'name'));
// array('Taylor', 'Dayle');
</code></pre>
<h3>array_first</h3>
<p>The <code>array_first</code> method returns the first element of an array passing a given truth test.</p>
<pre class="prettyprint"><code>$array = array(100, 200, 300);
$value = array_first($array, function($key, $value)
{
return $value >= 150;
});
</code></pre>
<p>A default value may also be passed as the third parameter:</p>
<pre class="prettyprint"><code>$value = array_first($array, $callback, $default);
</code></pre>
<h3>array_flatten</h3>
<p>The <code>array_flatten</code> method will flatten a multi-dimensional array into a single level.</p>
<pre class="prettyprint"><code>$array = array('name' => 'Joe', 'languages' => array('PHP', 'Ruby'));
$array = array_flatten($array);
// array('Joe', 'PHP', 'Ruby');
</code></pre>
<h3>array_forget</h3>
<p>The <code>array_forget</code> method will remove a given key / value pair from a deeply nested array using "dot" notation.</p>
<pre class="prettyprint"><code>$array = array('names' => array('joe' => array('programmer')));
$array = array_forget($array, 'names.joe');
</code></pre>
<h3>array_get</h3>
<p>The <code>array_get</code> method will retrieve a given value from a deeply nested array using "dot" notation.</p>
<pre class="prettyprint"><code>$array = array('names' => array('joe' => array('programmer')));
$value = array_get($array, 'names.joe');
</code></pre>
<h3>array_only</h3>
<p>The <code>array_only</code> method will return only the specified key / value pairs from the array.</p>
<pre class="prettyprint"><code>$array = array('name' => 'Joe', 'age' => 27, 'votes' => 1);
$array = array_only($array, array('name', 'votes'));
</code></pre>
<h3>array_pluck</h3>
<p>The <code>array_pluck</code> method will pluck a list of the given key / value pairs from the array.</p>
<pre class="prettyprint"><code>$array = array(array('name' => 'Taylor'), array('name' => 'Dayle'));
$array = array_pluck($array, 'name');
// array('Taylor', 'Dayle');
</code></pre>
<h3>array_pull</h3>
<p>The <code>array_pull</code> method will return a given key / value pair from the array, as well as remove it.</p>
<pre class="prettyprint"><code>$array = array('name' => 'Taylor', 'age' => 27);
$name = array_pull($array, 'name');
</code></pre>
<h3>array_set</h3>
<p>The <code>array_set</code> method will set a value within a deeply nested array using "dot" notation.</p>
<pre class="prettyprint"><code>$array = array('names' => array('programmer' => 'Joe'));
array_set($array, 'names.editor', 'Taylor');
</code></pre>
<h3>array_sort</h3>
<p>The <code>array_sort</code> method sorts the array by the results of the given Closure.</p>
<pre class="prettyprint"><code>$array = array(
array('name' => 'Jill'),
array('name' => 'Barry'),
);
$array = array_values(array_sort($array, function($value)
{
return $value['name'];
}));
</code></pre>
<h3>head</h3>
<p>Return the first element in the array. Useful for method chaining in PHP 5.3.x.</p>
<pre class="prettyprint"><code>$first = head($this->returnsArray('foo'));
</code></pre>
<h3>last</h3>
<p>Return the last element in the array. Useful for method chaining.</p>
<pre class="prettyprint"><code>$last = last($this->returnsArray('foo'));
</code></pre>
<p><a name="paths"></a></p>
<h2>Paths</h2>
<h3>app_path</h3>
<p>Get the fully qualified path to the <code>application</code> directory.</p>
<h3>base_path</h3>
<p>Get the fully qualified path to the root of the application install.</p>
<h3>public_path</h3>
<p>Get the fully qualified path to the <code>public</code> directory.</p>
<h3>storage_path</h3>
<p>Get the fully qualified path to the <code>application/storage</code> directory.</p>
<p><a name="strings"></a></p>
<h2>Strings</h2>
<h3>camel_case</h3>
<p>Convert the given string to <code>camelCase</code>.</p>
<pre class="prettyprint"><code>$camel = camel_case('foo_bar');
// fooBar
</code></pre>
<h3>class_basename</h3>
<p>Get the class name of the given class, without any namespace names.</p>
<pre class="prettyprint"><code>$class = class_basename('Foo\Bar\Baz');
// Baz
</code></pre>
<h3>e</h3>
<p>Run <code>htmlentites</code> over the given string, with UTF-8 support.</p>
<pre class="prettyprint"><code>$entities = e('<html>foo</html>');
</code></pre>
<h3>ends_with</h3>
<p>Determine if the given haystack ends with a given needle.</p>
<pre class="prettyprint"><code>$value = ends_with('This is my name', 'name');
</code></pre>
<h3>snake_case</h3>
<p>Convert the given string to <code>snake_case</code>.</p>
<pre class="prettyprint"><code>$snake = snake_case('fooBar');
// foo_bar
</code></pre>
<h3>starts_with</h3>
<p>Determine if the given haystack begins with the given needle.</p>
<pre class="prettyprint"><code>$value = starts_with('This is my name', 'This');
</code></pre>
<h3>str_contains</h3>
<p>Determine if the given haystack contains the given needle.</p>
<pre class="prettyprint"><code>$value = str_contains('This is my name', 'my');
</code></pre>
<h3>str_finish</h3>
<p>Add a single instance of the given needle to the haystack. Remove any extra instances.</p>
<pre class="prettyprint"><code>$string = str_finish('this/string', '/');
// this/string/
</code></pre>
<h3>str_is</h3>
<p>Determine if a given string matches a given pattern. Asterisks may be used to indicate wildcards.</p>
<pre class="prettyprint"><code>$value = str_is('foo*', 'foobar');
</code></pre>
<h3>str_plural</h3>
<p>Convert a string to its plural form (English only).</p>
<pre class="prettyprint"><code>$plural = str_plural('car');
</code></pre>
<h3>str_random</h3>
<p>Generate a random string of the given length.</p>
<pre class="prettyprint"><code>$string = str_random(40);
</code></pre>
<h3>str_singular</h3>
<p>Convert a string to its singular form (English only).</p>
<pre class="prettyprint"><code>$singular = str_singular('cars');
</code></pre>
<h3>studly_case</h3>
<p>Convert the given string to <code>StudlyCase</code>.</p>
<pre class="prettyprint"><code>$value = studly_case('foo_bar');
// FooBar
</code></pre>
<h3>trans</h3>
<p>Translate a given language line. Alias of <code>Lang::get</code>.</p>
<pre class="prettyprint"><code>$value = trans('validation.required'):
</code></pre>
<h3>trans_choice</h3>
<p>Tranlate a given language line with inflection. Alias of <code>Lang::choice</code>.</p>
<pre class="prettyprint"><code>$value = trans_choice('foo.bar', $count);
</code></pre>
<p><a name="urls"></a></p>
<h2>URLs</h2>
<h3>action</h3>
<p>Generate a URL for a given controller action.</p>
<pre class="prettyprint"><code>$url = action('HomeController@getIndex', $params);
</code></pre>
<h3>asset</h3>
<p>Generate a URL for an asset.</p>
<pre class="prettyprint"><code>$url = asset('img/photo.jpg');
</code></pre>
<h3>link_to</h3>
<p>Generate a HTML link to the given URL.</p>
<pre class="prettyprint"><code>echo link_to('foo/bar', $title, $attributes = array(), $secure = null);
</code></pre>
<h3>link_to_asset</h3>
<p>Generate a HTML link to the given asset.</p>
<pre class="prettyprint"><code>echo link_to_asset('foo/bar.zip', $title, $attributes = array(), $secure = null);
</code></pre>
<h3>link_to_route</h3>
<p>Generate a HTML link to the given route.</p>
<pre class="prettyprint"><code>echo link_to_route('route.name', $title, $parameters = array(), $attributes = array());
</code></pre>
<h3>link_to_action</h3>
<p>Generate a HTML link to the given controller action.</p>
<pre class="prettyprint"><code>echo link_to_action('HomeController@getIndex', $title, $parameters = array(), $attributes = array());
</code></pre>
<h3>secure_asset</h3>
<p>Generate a HTML link to the given asset using HTTPS.</p>
<pre class="prettyprint"><code>echo secure_asset('foo/bar.zip', $title, $attributes = array());
</code></pre>
<h3>secure_url</h3>
<p>Generate a fully qualified URL to a given path using HTTPS.</p>
<pre class="prettyprint"><code>echo secure_url('foo/bar', $parameters = array());
</code></pre>
<h3>url</h3>
<p>Generate a fully qualified URL to the given path.</p>
<pre class="prettyprint"><code>echo url('foo/bar', $parameters = array(), $secure = null);
</code></pre>
<p><a name="miscellaneous"></a></p>
<h2>Miscellaneous</h2>
<h3>csrf_token</h3>
<p>Get the value of the current CSRF token.</p>
<pre class="prettyprint"><code>$token = csrf_token();
</code></pre>
<h3>dd</h3>
<p>Dump the given variable and end execution of the script.</p>
<pre class="prettyprint"><code>dd($value);
</code></pre>
<h3>value</h3>
<p>If the given value is a <code>Closure</code>, return the value returned by the <code>Closure</code>. Otherwise, return the value.</p>
<pre class="prettyprint"><code>$value = value(function() { return 'bar'; });
</code></pre>
<h3>with</h3>
<p>Return the given object. Useful for method chaining constructors in PHP 5.3.x.</p>
<pre class="prettyprint"><code>$value = with(new Foo)->doWork();
</code></pre>
</article><div class="clearfix"></div>
</div>
</section>
<script src="js/jquery.min.js"></script>
<script src="js/plugins.js"></script>
<script type="text/javascript" src="vendor/google-code-prettify/run_prettify.js"></script>
</body></html>