From: Chuck Hagenbuch Date: Mon, 31 May 2010 19:34:25 +0000 (-0400) Subject: Add shorthand column creation methods X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=65c1c62270f20ec5c3efe73e8c0cec85cce40cc4;p=horde.git Add shorthand column creation methods Credit to http://github.com/maintainable/framework/commit/7709643d3b88cff39cec717d4c6248ebd373a480 --- diff --git a/framework/Db/lib/Horde/Db/Adapter/Base/ColumnDefinition.php b/framework/Db/lib/Horde/Db/Adapter/Base/ColumnDefinition.php index 69c405e02..9d47ad6a4 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Base/ColumnDefinition.php +++ b/framework/Db/lib/Horde/Db/Adapter/Base/ColumnDefinition.php @@ -255,5 +255,4 @@ class Horde_Db_Adapter_Base_ColumnDefinition array_merge($options, array('column' => $this)) ); } - } diff --git a/framework/Db/lib/Horde/Db/Adapter/Base/TableDefinition.php b/framework/Db/lib/Horde/Db/Adapter/Base/TableDefinition.php index b3a8e6b6a..005422dc5 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Base/TableDefinition.php +++ b/framework/Db/lib/Horde/Db/Adapter/Base/TableDefinition.php @@ -29,6 +29,9 @@ class Horde_Db_Adapter_Base_TableDefinition implements ArrayAccess, IteratorAggr protected $_columns = null; protected $_primaryKey = null; + protected $_columntypes = array('string', 'text', 'integer', 'float', + 'datetime', 'timestamp', 'time', 'date', 'binary', 'boolean'); + /** * Class Constructor * @@ -137,6 +140,21 @@ class Horde_Db_Adapter_Base_TableDefinition implements ArrayAccess, IteratorAggr } /** + * Use __call to provide shorthand column creation ($this->integer(), etc.) + */ + public function __call($method, $arguments) + { + if (!in_array($method, $this->_columntypes)) { + throw new BadMethodCallException('Call to undeclared method "'.$method.'"'); + } elseif (count($arguments) > 0 && count($arguments) < 3) { + return $this->column($arguments[0], $method, + isset($arguments[1]) ? $arguments[1] : array()); + } else { + throw new BadMethodCallException('Method "'.$method.'" takes two arguments'); + } + } + + /** * Wrap up table creation block & create the table */ public function end()