1
1
# Laravel Helpers
2
2
3
3
[ ![ Latest Version on Packagist] ( https://img.shields.io/packagist/v/maize-tech/laravel-helpers.svg?style=flat-square )] ( https://packagist.org/packages/maize-tech/laravel-helpers )
4
- [ ![ GitHub Tests Action Status] ( https://img.shields.io/github/workflow/status/maize-tech/laravel-helpers/run-tests? label=tests )] ( https://github.com/maize-tech/laravel-helpers/actions?query=workflow%3Arun-tests+branch%3Amain )
5
- [ ![ GitHub Code Style Action Status] ( https://img.shields.io/github/workflow/status/maize-tech/laravel-helpers/Check%20&%20fix%20styling? label=code%20style )] ( https://github.com/maize-tech/laravel-helpers/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain )
4
+ [ ![ GitHub Tests Action Status] ( https://img.shields.io/github/actions/ workflow/status/maize-tech/laravel-helpers/run-tests.yml?branch=main& label=tests&style=flat-square )] ( https://github.com/maize-tech/laravel-helpers/actions?query=workflow%3Arun-tests+branch%3Amain )
5
+ [ ![ GitHub Code Style Action Status] ( https://img.shields.io/github/actions/ workflow/status/maize-tech/laravel-helpers/php-cs-fixer.yml?branch=main& label=code%20style&style=flat-square )] ( https://github.com/maize-tech/laravel-helpers/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain )
6
6
[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/maize-tech/laravel-helpers.svg?style=flat-square )] ( https://packagist.org/packages/maize-tech/laravel-helpers )
7
7
8
8
This repository contains some useful helpers for most applications using Laravel.
@@ -37,16 +37,9 @@ return [
37
37
|
38
38
*/
39
39
40
- 'macros' => [
41
- 'anonymizeFilename' => \Maize\Helpers\Macros\AnonymizeFilename::class,
42
- 'classUsesTrait' => \Maize\Helpers\Macros\ClassUsesTrait::class,
43
- 'instanceofTypes' => \Maize\Helpers\Macros\InstanceofTypes::class,
44
- 'isUrl' => \Maize\Helpers\Macros\IsUrl::class,
45
- 'modelKeyName' => \Maize\Helpers\Macros\ModelKeyName::class,
46
- 'morphClassOf' => \Maize\Helpers\Macros\MorphClassOf::class,
47
- 'paginationLimit' => \Maize\Helpers\Macros\PaginationLimit::class,
48
- 'sanitizeUrl' => \Maize\Helpers\Macros\SanitizeUrl::class,
49
- ],
40
+ 'macros' => Helper::defaultMacros()->merge([
41
+ // 'methodName' => App\Example\ExampleClass::class,
42
+ ])->toArray(),
50
43
51
44
];
52
45
```
@@ -72,6 +65,9 @@ hlp()->sanitizeUrl('mywebsite.com'); // using the helper function
72
65
- [ ` modelKeyName ` ] ( #modelkeyname )
73
66
- [ ` morphClassOf ` ] ( #morphclassof )
74
67
- [ ` paginationLimit ` ] ( #paginationlimit )
68
+ - [ ` pipe ` ] ( #pipe )
69
+ - [ ` sanitizeArrayOfStrings ` ] ( #sanitizearrayofstrings )
70
+ - [ ` sanitizeString ` ] ( #sanitizestring )
75
71
- [ ` sanitizeUrl ` ] ( #sanitizeurl )
76
72
77
73
### ` anonymizeFilename `
@@ -216,6 +212,49 @@ Article::paginate(
216
212
);
217
213
```
218
214
215
+ ### ` pipe `
216
+
217
+ The ` pipe ` function allows you to integrate Laravel pipelines with ease.
218
+ The first parameter is the object to be sent through the pipeline, while the second is the list of pipes.
219
+
220
+ ``` php
221
+ hlp()->pipe('test', [
222
+ \Maize\Helpers\Tests\Support\Actions\Uppercase::class,
223
+ ]); // returns 'TEST'
224
+
225
+ hlp()->pipe('test', [
226
+ \Maize\Helpers\Tests\Support\Actions\Uppercase::class,
227
+ \Maize\Helpers\Tests\Support\Actions\Reverse::class,
228
+ ]); // returns 'TSET'
229
+
230
+ hlp()->pipe('', []) // returns an empty string
231
+ ```
232
+
233
+ ### ` sanitizeArrayOfStrings `
234
+
235
+ The ` sanitizeArrayOfStrings ` function sanitizes an array of strings by removing all HTML tags and whitespace from both ends.
236
+ When passing an associative array, it also filters all keys with an empty value.
237
+
238
+ ``` php
239
+ hlp()->sanitizeArrayOfStrings([' test ', ' test ']); // returns '['test', 'test']'
240
+
241
+ hlp()->sanitizeArrayOfStrings(['a' => ' test </h1 > ', 'b' => ' test </h1 > ']) // returns ['a' => 'test', 'b' => 'test']
242
+
243
+ hlp()->sanitizeArrayOfStrings(['a' => '']); // returns an empty array
244
+ ```
245
+
246
+ ### ` sanitizeString `
247
+
248
+ The ` sanitizeString ` function sanitizes a string by removing all HTML tags and whitespace from both ends.
249
+
250
+ ``` php
251
+ hlp()->sanitizeString('<h1 > test </h1 >'); // returns 'test'
252
+
253
+ hlp()->sanitizeString(' <h1 > test '); // returns 'test'
254
+
255
+ hlp()->sanitizeString('<br />') // returns an empty string
256
+ ```
257
+
219
258
### ` sanitizeUrl `
220
259
221
260
The ` sanitizeUrl ` function prepends the specified url with the ` https ` protocol if none is set.
@@ -269,17 +308,9 @@ return [
269
308
|
270
309
*/
271
310
272
- 'macros' => [
273
- 'anonymizeFilename' => \Maize\Helpers\Macros\AnonymizeFilename::class,
274
- 'classUsesTrait' => \Maize\Helpers\Macros\ClassUsesTrait::class,
275
- 'instanceofTypes' => \Maize\Helpers\Macros\InstanceofTypes::class,
276
- 'isUrl' => \Maize\Helpers\Macros\IsUrl::class,
277
- 'modelKeyName' => \Maize\Helpers\Macros\ModelKeyName::class,
278
- 'morphClassOf' => \Maize\Helpers\Macros\MorphClassOf::class,
279
- 'paginationLimit' => \Maize\Helpers\Macros\PaginationLimit::class,
280
- 'sanitizeUrl' => \Maize\Helpers\Macros\SanitizeUrl::class,
311
+ 'macros' => Helper::defaultMacros()->merge([
281
312
'ping' => \App\Helpers\Macros\Ping::class,
282
- ],
313
+ ])->toArray() ,
283
314
284
315
];
285
316
```
0 commit comments