From c0f91169996e1fadbbb56e86a73f870f07180351 Mon Sep 17 00:00:00 2001 From: Nicholas Ruunu Date: Thu, 27 Feb 2014 11:45:39 +0100 Subject: [PATCH] Adds MacroableTrait to FormBuilder and HtmlBuilder --- FormBuilder.php | 41 +++-------------------------------------- HtmlBuilder.php | 41 +++-------------------------------------- 2 files changed, 6 insertions(+), 76 deletions(-) diff --git a/FormBuilder.php b/FormBuilder.php index d3bfb91..75e5926 100755 --- a/FormBuilder.php +++ b/FormBuilder.php @@ -2,9 +2,12 @@ use Illuminate\Routing\UrlGenerator; use Illuminate\Session\Store as Session; +use Illuminate\Support\Traits\MacroableTrait; class FormBuilder { + use MacroableTrait; + /** * The HTML builder instance. * @@ -47,13 +50,6 @@ class FormBuilder { */ protected $labels = array(); - /** - * The registered form builder macros. - * - * @var array - */ - protected $macros = array(); - /** * The reserved form open attributes. * @@ -730,18 +726,6 @@ class FormBuilder { return 'html->attributes($options).'>'.$value.''; } - /** - * Register a custom form macro. - * - * @param string $name - * @param callable $macro - * @return void - */ - public function macro($name, $macro) - { - $this->macros[$name] = $macro; - } - /** * Parse the form action method. * @@ -984,23 +968,4 @@ class FormBuilder { return $this; } - /** - * Dynamically handle calls to the form builder. - * - * @param string $method - * @param array $parameters - * @return mixed - * - * @throws \BadMethodCallException - */ - public function __call($method, $parameters) - { - if (isset($this->macros[$method])) - { - return call_user_func_array($this->macros[$method], $parameters); - } - - throw new \BadMethodCallException("Method {$method} does not exist."); - } - } diff --git a/HtmlBuilder.php b/HtmlBuilder.php index aad9e73..3639f9a 100755 --- a/HtmlBuilder.php +++ b/HtmlBuilder.php @@ -1,9 +1,12 @@ url = $url; } - /** - * Register a custom HTML macro. - * - * @param string $name - * @param callable $macro - * @return void - */ - public function macro($name, $macro) - { - $this->macros[$name] = $macro; - } - /** * Convert an HTML string to entities. * @@ -389,23 +373,4 @@ class HtmlBuilder { return $safe; } - /** - * Dynamically handle calls to the html class. - * - * @param string $method - * @param array $parameters - * @return mixed - * - * @throws \BadMethodCallException - */ - public function __call($method, $parameters) - { - if (isset($this->macros[$method])) - { - return call_user_func_array($this->macros[$method], $parameters); - } - - throw new \BadMethodCallException("Method {$method} does not exist."); - } - }