From b05f91e16e6148149145c20768f96eb8b03b7c93 Mon Sep 17 00:00:00 2001 From: Sebastiaan Luca Date: Mon, 26 Jun 2017 19:51:26 +0200 Subject: [PATCH 1/2] Implement macro class Signed-off-by: Sebastiaan Luca --- src/Illuminate/Contracts/Support/Macro.php | 13 +++++++++++++ src/Illuminate/Support/Traits/Macroable.php | 20 ++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100755 src/Illuminate/Contracts/Support/Macro.php diff --git a/src/Illuminate/Contracts/Support/Macro.php b/src/Illuminate/Contracts/Support/Macro.php new file mode 100755 index 000000000000..16e6919809d0 --- /dev/null +++ b/src/Illuminate/Contracts/Support/Macro.php @@ -0,0 +1,13 @@ +bindTo($this, static::class), $parameters); + $macro = static::$macros[$method]; + + if (is_string($macro) && is_a($macro, Macro::class, true)) { + $macro = (new $macro)->handle(); } - return call_user_func_array(static::$macros[$method], $parameters); + if ($macro instanceof Closure) { + return call_user_func_array($macro->bindTo($this, static::class), $parameters); + } + + return call_user_func_array($macro, $parameters); } } From 7908979591d5dceb81ba68dbdf7d4bc58e069cb4 Mon Sep 17 00:00:00 2001 From: Sebastiaan Luca Date: Mon, 26 Jun 2017 20:12:50 +0200 Subject: [PATCH 2/2] Adhere to PHPDoc style guidelines Signed-off-by: Sebastiaan Luca --- src/Illuminate/Contracts/Support/Macro.php | 2 +- src/Illuminate/Support/Traits/Macroable.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Contracts/Support/Macro.php b/src/Illuminate/Contracts/Support/Macro.php index 16e6919809d0..e8930b4375ad 100755 --- a/src/Illuminate/Contracts/Support/Macro.php +++ b/src/Illuminate/Contracts/Support/Macro.php @@ -7,7 +7,7 @@ interface Macro /** * Return the callable macro. * - * @return callable + * @return callable */ public function handle(); } diff --git a/src/Illuminate/Support/Traits/Macroable.php b/src/Illuminate/Support/Traits/Macroable.php index a627a9704e33..f50a4522b755 100644 --- a/src/Illuminate/Support/Traits/Macroable.php +++ b/src/Illuminate/Support/Traits/Macroable.php @@ -19,7 +19,7 @@ trait Macroable * Register a custom macro. * * @param string $name - * @param \Illuminate\Contracts\Support\Macro|callable $macro + * @param \Illuminate\Contracts\Support\Macro|callable $macro * * @return void */