diff --git a/FormBuilder.php b/FormBuilder.php index e1c00df..8d666e2 100644 --- a/FormBuilder.php +++ b/FormBuilder.php @@ -41,6 +41,13 @@ class FormBuilder { */ protected $labels = array(); + /** + * The registered form builder macros. + * + * @var array + */ + protected $macros = array(); + /** * The reserved form open attributes. * @@ -475,6 +482,18 @@ class FormBuilder { return ''.e($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. * @@ -591,4 +610,21 @@ class FormBuilder { $this->session = $session; } + /** + * Dynamically handle calls to the form builder. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + 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."); + } + } \ No newline at end of file