Skip to content

Commit

Permalink
ADD HelperMacro interface for better consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardodallavia committed Aug 29, 2022
1 parent 7287b59 commit 9dcaef2
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 10 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,16 @@ hlp()->sanitizeUrl('') // returns an empty string

If needed, you can easily add your own helper methods.

All you have to do is define your custom helper method using an invokable class:
All you have to do is define your custom helper class and implement the `HelperMacro` interface:

```php
<?php

namespace App\Helpers\Macros;

class Ping
use Maize\Helpers\HelperMacro;

class Ping implements HelperMacro
{
public function __invoke(): \Closure
{
Expand Down
8 changes: 8 additions & 0 deletions src/HelperMacro.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Maize\Helpers;

interface HelperMacro
{
public function __invoke(): \Closure;
}
3 changes: 2 additions & 1 deletion src/Macros/AnonymizeFilename.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Maize\Helpers\Macros;

use Illuminate\Support\Str;
use Maize\Helpers\HelperMacro;

class AnonymizeFilename
class AnonymizeFilename implements HelperMacro
{
public function __invoke(): \Closure
{
Expand Down
4 changes: 3 additions & 1 deletion src/Macros/ClassUsesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Maize\Helpers\Macros;

class ClassUsesTrait
use Maize\Helpers\HelperMacro;

class ClassUsesTrait implements HelperMacro
{
public function __invoke(): \Closure
{
Expand Down
3 changes: 2 additions & 1 deletion src/Macros/InstanceofTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Maize\Helpers\Macros;

use Illuminate\Support\Arr;
use Maize\Helpers\HelperMacro;

class InstanceofTypes
class InstanceofTypes implements HelperMacro
{
public function __invoke(): \Closure
{
Expand Down
4 changes: 3 additions & 1 deletion src/Macros/IsUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Maize\Helpers\Macros;

class IsUrl
use Maize\Helpers\HelperMacro;

class IsUrl implements HelperMacro
{
public function __invoke(): \Closure
{
Expand Down
3 changes: 2 additions & 1 deletion src/Macros/ModelKeyName.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Maize\Helpers\Macros;

use Illuminate\Database\Eloquent\Model;
use Maize\Helpers\HelperMacro;

class ModelKeyName
class ModelKeyName implements HelperMacro
{
public function __invoke(): \Closure
{
Expand Down
3 changes: 2 additions & 1 deletion src/Macros/MorphClassOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Maize\Helpers\Macros;

use Illuminate\Database\Eloquent\Model;
use Maize\Helpers\HelperMacro;

class MorphClassOf
class MorphClassOf implements HelperMacro
{
public function __invoke(): \Closure
{
Expand Down
4 changes: 3 additions & 1 deletion src/Macros/PaginationLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Maize\Helpers\Macros;

class PaginationLimit
use Maize\Helpers\HelperMacro;

class PaginationLimit implements HelperMacro
{
public function __invoke(): \Closure
{
Expand Down
3 changes: 2 additions & 1 deletion src/Macros/SanitizeUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Maize\Helpers\Macros;

use Illuminate\Support\Str;
use Maize\Helpers\HelperMacro;

class SanitizeUrl
class SanitizeUrl implements HelperMacro
{
public function __invoke(): \Closure
{
Expand Down

0 comments on commit 9dcaef2

Please sign in to comment.