Browse Source

add macros to tables

Colin Viebrock 11 years ago
parent
commit
906d0d851e
1 changed files with 38 additions and 1 deletions
  1. 38 1
      laravel/database/schema/table.php

+ 38 - 1
laravel/database/schema/table.php

@@ -39,6 +39,25 @@ class Table {
 	 */
 	 */
 	public $commands = array();
 	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.
 	 * Create a new schema table instance.
 	 *
 	 *
@@ -422,4 +441,22 @@ class Table {
 		return $this->columns[] = new Fluent($parameters);
 		return $this->columns[] = new Fluent($parameters);
 	}
 	}
 
 
-}
+	/**
+	 * 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.");
+	}
+
+}