From 906d0d851e182ee832100af207a555e6919acf65 Mon Sep 17 00:00:00 2001 From: Colin Viebrock Date: Wed, 3 Apr 2013 18:26:15 -0500 Subject: [PATCH] add macros to tables --- laravel/database/schema/table.php | 39 ++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/laravel/database/schema/table.php b/laravel/database/schema/table.php index c728260c..84b64dcf 100644 --- a/laravel/database/schema/table.php +++ b/laravel/database/schema/table.php @@ -39,6 +39,25 @@ class Table { */ public $commands = array(); + /** + * The registered custom macros. + * + * @var array + */ + public static $macros = array(); + + /** + * Registers a custom macro. + * + * @param string $name + * @param Closure $macro + * @return void + */ + public static function macro($name, $macro) + { + static::$macros[$name] = $macro; + } + /** * Create a new schema table instance. * @@ -422,4 +441,22 @@ protected function column($type, $parameters = array()) return $this->columns[] = new Fluent($parameters); } -} \ No newline at end of file + /** + * Dynamically handle calls to custom macros. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + if (isset(static::$macros[$method])) + { + array_unshift($parameters, $this); + return call_user_func_array(static::$macros[$method], $parameters); + } + + throw new \Exception("Method [$method] does not exist."); + } + +}