Permalink
Browse files

[1.5] Added a way to prefix all the table names of a database schema …

…by setting the `tablePrefix` attribute of the `<database>` tag (refs #282)
  • Loading branch information...
1 parent a64cf56 commit a2b8212ad20d7eb36d317679fc5713ea4c57ebc2 @fzaninotto fzaninotto committed Feb 9, 2010
@@ -56,6 +56,7 @@ class Database extends XMLElement
private $tablesByName = array();
private $tablesByPhpName = array();
private $heavyIndexing;
+ protected $tablePrefix = '';
private $domainMap = array();
@@ -90,6 +91,7 @@ protected function setupObject()
$this->defaultPhpNamingMethod = $this->getAttribute("defaultPhpNamingMethod", NameGenerator::CONV_METHOD_UNDERSCORE);
$this->defaultTranslateMethod = $this->getAttribute("defaultTranslateMethod", Validator::TRANSLATE_NONE);
$this->heavyIndexing = $this->booleanValue($this->getAttribute("heavyIndexing"));
+ $this->tablePrefix = $this->getAttribute("tablePrefix");
}
/**
@@ -429,6 +431,16 @@ public function getBehavior($name)
return $this->behaviors[$name];
}
+ /**
+ * Get the table prefix for this database
+ *
+ * @return string the table prefix
+ */
+ public function getTablePrefix()
+ {
+ return $this->tablePrefix;
+ }
+
public function doFinalInitialization()
{
@@ -66,7 +66,7 @@ public function __construct($name=null)
*/
protected function setupObject()
{
- $this->foreignTableName = $this->getAttribute("foreignTable");
+ $this->foreignTableName = $this->getTable()->getDatabase()->getTablePrefix() . $this->getAttribute("foreignTable");
$this->name = $this->getAttribute("name");
$this->phpName = $this->getAttribute("phpName");
$this->refPhpName = $this->getAttribute("refPhpName");
@@ -315,13 +315,13 @@ public function __construct($name = null)
*/
public function setupObject()
{
- $this->name = $this->getAttribute("name");
- $this->phpName = $this->getAttribute("phpName");
+ $this->name = $this->getDatabase()->getTablePrefix() . $this->getAttribute("name");
+ // retrieves the method for converting from specified name to a PHP name.
+ $this->phpNamingMethod = $this->getAttribute("phpNamingMethod", $this->getDatabase()->getDefaultPhpNamingMethod());
+ $this->phpName = $this->getAttribute("phpName", $this->buildPhpName($this->getAttribute('name')));
$this->idMethod = $this->getAttribute("idMethod", $this->getDatabase()->getDefaultIdMethod());
$this->allowPkInsert = $this->booleanValue($this->getAttribute("allowPkInsert"));
- // retrieves the method for converting from specified name to a PHP name.
- $this->phpNamingMethod = $this->getAttribute("phpNamingMethod", $this->getDatabase()->getDefaultPhpNamingMethod());
$this->skipSql = $this->booleanValue($this->getAttribute("skipSql"));
$this->readOnly = $this->booleanValue($this->getAttribute("readOnly"));
@@ -622,6 +622,7 @@ public function addForeignKey($fkdata)
return $fk;
} else {
$fk = new ForeignKey();
+ $fk->setTable($this);
$fk->loadFromXML($fkdata);
return $this->addForeignKey($fk);
}
@@ -903,6 +904,11 @@ public function setPhpName($phpName)
{
$this->phpName = $phpName;
}
+
+ public function buildPhpName($name)
+ {
+ return NameFactory::generateName(NameFactory::PHP_GENERATOR, array($name, $this->phpNamingMethod));
+ }
/**
* Get studly version of PHP name.
@@ -31,6 +31,7 @@ PHP class or method name.
basePeer CDATA #IMPLIED
defaultPhpNamingMethod (nochange|underscore|phpname) "underscore"
heavyIndexing (true|false) "false"
+ tablePrefix CDATA #IMPLIED
>
<!ELEMENT external-schema EMPTY>
@@ -394,5 +394,6 @@
<xs:attribute name="basePeer" type="php_class" use="optional"/>
<xs:attribute name="defaultPhpNamingMethod" type="phpnamingmethod" default="underscore"/>
<xs:attribute name="heavyIndexing" type="xs:boolean" default="false"/>
+ <xs:attribute name="tablePrefix" type="xs:string" use="optional"/>
</xs:complexType>
</xs:schema>

0 comments on commit a2b8212

Please sign in to comment.