added macro method.

This commit is contained in:
Taylor Otwell committed 2013-02-26 23:31:46 -06:00
1 parent 28832d5d71
commit a5751249be
1 file changed
+36
+36
View File
@@ -41,6 +41,13 @@ class FormBuilder {
*/ */
protected $labels = array(); protected $labels = array();
/**
* The registered form builder macros.
*
* @var array
*/
protected $macros = array();
/** /**
* The reserved form open attributes. * The reserved form open attributes.
* *
@@ -475,6 +482,18 @@ class FormBuilder {
return '<button'.Html::attributes($attributes).'>'.e($value).'</button>'; return '<button'.Html::attributes($attributes).'>'.e($value).'</button>';
} }
/**
* 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. * Parse the form action method.
* *
@@ -591,4 +610,21 @@ class FormBuilder {
$this->session = $session; $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.");
}
} }