From 95ba416f3c8292574ec504fb0364f4593a12a23a Mon Sep 17 00:00:00 2001 From: Kyle Decot Date: Fri, 16 Mar 2012 13:35:15 -0400 Subject: [PATCH] Adds Form::register which allows Bundles (or anything for that matter) to register custom form inputs which then can be called like `Form::xxx` --- laravel/form.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/laravel/form.php b/laravel/form.php index 1fd97ca6..32aff7e4 100644 --- a/laravel/form.php +++ b/laravel/form.php @@ -8,6 +8,28 @@ class Form { * @var array */ protected static $labels = array(); + + /** + * The registered custom inputs + * + * @var array + */ + + protected static $inputs = array(); + + /** + * Dynamically handle calls to custom registered inputs. + */ + + public static function __callStatic($method, $parameters) + { + if (isset(static::$inputs[$method])) + { + return call_user_func_array(static::$inputs[$method], $parameters); + } + + throw new \Exception("Method [$method] does not exist."); + } /** * Open a HTML form. @@ -61,6 +83,19 @@ public static function open($action = null, $method = 'POST', $attributes = arra return ''.$append.PHP_EOL; } + + /** + * Registers a custom input + * + * @param string $name + * @param Closure $input + * @return void + */ + + public static function register($name, $input) + { + static::$inputs[$name] = $input; + } /** * Determine the appropriate request method to use for a form.