From a478211a0713e4527876fbf86fdd535b2b1e0703 Mon Sep 17 00:00:00 2001 From: Hossein Zare <56504893+hossein-zare@users.noreply.github.com> Date: Fri, 18 Oct 2024 13:24:38 +0330 Subject: [PATCH] Add `$bind` parameter to allow binding custom Blade directive handlers to the BladeCompiler instance. --- src/Illuminate/View/Compilers/BladeCompiler.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index 7911462ebf32..6bd58d5c8d5b 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -939,17 +939,18 @@ public function aliasInclude($path, $alias = null) * * @param string $name * @param callable $handler + * @param bool $bind * @return void * * @throws \InvalidArgumentException */ - public function directive($name, callable $handler) + public function directive($name, callable $handler, bool $bind = false) { if (! preg_match('/^\w+(?:::\w+)?$/x', $name)) { throw new InvalidArgumentException("The directive name [{$name}] is not valid. Directive names must only contain alphanumeric characters and underscores."); } - $this->customDirectives[$name] = $handler; + $this->customDirectives[$name] = $bind ? $handler->bindTo($this, BladeCompiler::class) : $handler; } /**