11# Laravel Helpers
22
33[ ![ 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 )
66[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/maize-tech/laravel-helpers.svg?style=flat-square )] ( https://packagist.org/packages/maize-tech/laravel-helpers )
77
88This repository contains some useful helpers for most applications using Laravel.
@@ -37,16 +37,9 @@ return [
3737 |
3838 */
3939
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(),
5043
5144];
5245```
@@ -72,6 +65,9 @@ hlp()->sanitizeUrl('mywebsite.com'); // using the helper function
7265- [ ` modelKeyName ` ] ( #modelkeyname )
7366- [ ` morphClassOf ` ] ( #morphclassof )
7467- [ ` paginationLimit ` ] ( #paginationlimit )
68+ - [ ` pipe ` ] ( #pipe )
69+ - [ ` sanitizeArrayOfStrings ` ] ( #sanitizearrayofstrings )
70+ - [ ` sanitizeString ` ] ( #sanitizestring )
7571- [ ` sanitizeUrl ` ] ( #sanitizeurl )
7672
7773### ` anonymizeFilename `
@@ -216,6 +212,49 @@ Article::paginate(
216212);
217213```
218214
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+
219258### ` sanitizeUrl `
220259
221260The ` sanitizeUrl ` function prepends the specified url with the ` https ` protocol if none is set.
@@ -269,17 +308,9 @@ return [
269308 |
270309 */
271310
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([
281312 'ping' => \App\Helpers\Macros\Ping::class,
282- ],
313+ ])->toArray() ,
283314
284315];
285316```
0 commit comments