Skip to content

Commit

Permalink
add macros to tables
Browse files Browse the repository at this point in the history
  • Loading branch information
cviebrock committed Apr 3, 2013
1 parent 5dd3ec6 commit 906d0d8
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion laravel/database/schema/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -422,4 +441,22 @@ protected function column($type, $parameters = array())
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.");
}

}

0 comments on commit 906d0d8

Please sign in to comment.