diff --git a/Doctrine.php b/Doctrine.php index 659cc045a..d9bda9dcf 100644 --- a/Doctrine.php +++ b/Doctrine.php @@ -1,5 +1,5 @@ diff --git a/Doctrine/DataDict.php b/Doctrine/DataDict.php index 19f3f3309..1cbe25b59 100644 --- a/Doctrine/DataDict.php +++ b/Doctrine/DataDict.php @@ -6,7 +6,7 @@ class Doctrine_DataDict { public function __construct(PDO $dbh) { $file = Doctrine::getPath().DIRECTORY_SEPARATOR."Doctrine".DIRECTORY_SEPARATOR."adodb-hack".DIRECTORY_SEPARATOR."adodb.inc.php"; - if( ! file_exists($file)) + if( ! file_exists($file)) throw new Doctrine_Exception("Couldn't include datadict. File $file does not exist"); require_once($file); @@ -89,7 +89,7 @@ class Doctrine_DataDict { case "boolean": return "L"; break; - case "enum": + case "enum": case "integer": if(empty($length)) return "I8"; @@ -109,5 +109,16 @@ class Doctrine_DataDict { throw new Doctrine_Exception("Unknown column type $type"); endswitch; } + /** + * checks for valid class name (uses camel case and underscores) + * + * @param string $classname + * @return boolean + */ + public static function isValidClassname($classname) { + if(preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname)) + throw new Doctrine_Exception("Class name is not valid. use camel case and underscores (i.e My_PerfectClass)."); + return true; + } } ?> diff --git a/Doctrine/Table.php b/Doctrine/Table.php index b6254bf56..bf4cdd6a4 100644 --- a/Doctrine/Table.php +++ b/Doctrine/Table.php @@ -154,7 +154,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $class = $method->getDeclaringClass(); if( ! isset($this->tableName)) - $this->tableName = strtolower($class->getName()); + $this->tableName = Doctrine::tableize($class->getName()); switch(count($this->primaryKeys)): case 0: @@ -205,7 +205,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { } endswitch; - if($this->getAttribute(Doctrine::ATTR_CREATE_TABLES)) { + if(Doctrine_DataDict::isValidClassname($class->getName()) && $this->getAttribute(Doctrine::ATTR_CREATE_TABLES)) { $dict = new Doctrine_DataDict($this->getSession()->getDBH()); $dict->createTable($this->tableName, $this->columns); } @@ -456,7 +456,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { * @param $name * @return boolean */ - final public function unbind() { + final public function unbind($name) { if( ! isset($this->bound[$name])) return false; @@ -807,7 +807,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { } /** * count - * + * * @return integer */ public function count() {