CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,222 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'exception/EngineException.php';
require_once 'model/Database.php';
/**
* A class for holding application data structures.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Leon Messerschmidt <leon@opticode.co.za> (Torque)
* @author John McNally <jmcnally@collab.net> (Torque)
* @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
* @version $Revision: 1640 $
* @package propel.generator.model
*/
class AppData
{
/**
* The list of databases for this application.
* @var array Database[]
*/
private $dbList = array();
/**
* The platform class for our database(s).
* @var string
*/
private $platform;
/**
* Name of the database. Only one database definition
* is allowed in one XML descriptor.
*/
private $name;
/**
* Flag to ensure that initialization is performed only once.
* @var boolean
*/
private $isInitialized = false;
/**
* Creates a new instance for the specified database type.
*
* @param Platform $platform The platform object to use for any databases added to this application model.
*/
public function __construct(Platform $platform)
{
$this->platform = $platform;
}
/**
* Gets the platform object to use for any databases added to this application model.
*
* @return Platform
*/
public function getPlatform()
{
return $this->platform;
}
/**
* Set the name of the database.
*
* @param name of the database.
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get the name of the database.
*
* @return String name
*/
public function getName()
{
return $this->name;
}
/**
* Get the short name of the database (without the '-schema' postfix).
*
* @return String name
*/
public function getShortName()
{
return str_replace("-schema", "", $this->name);
}
/**
* Return an array of all databases
*
* @return Array of Database objects
*/
public function getDatabases($doFinalInit = true)
{
// this is temporary until we'll have a clean solution
// for packaging datamodels/requiring schemas
if ($doFinalInit) {
$this->doFinalInitialization();
}
return $this->dbList;
}
/**
* Returns whether this application has multiple databases.
*
* @return boolean True if the application has multiple databases
*/
public function hasMultipleDatabases()
{
return (count($this->dbList) > 1);
}
/**
* Return the database with the specified name.
*
* @param name database name
* @return A Database object. If it does not exist it returns null
*/
public function getDatabase($name = null, $doFinalInit = true)
{
// this is temporary until we'll have a clean solution
// for packaging datamodels/requiring schemas
if ($doFinalInit) {
$this->doFinalInitialization();
}
if ($name === null) {
return $this->dbList[0];
}
for ($i=0,$size=count($this->dbList); $i < $size; $i++) {
$db = $this->dbList[$i];
if ($db->getName() === $name) {
return $db;
}
}
return null;
}
/**
* Checks whether a database with the specified nam exists in this AppData
*
* @param name database name
* @return boolean
*/
public function hasDatabase($name)
{
foreach ($this->dbList as $db) {
if ($db->getName() === $name) {
return true;
}
}
return false;
}
/**
* Add a database to the list and sets the AppData property to this
* AppData
*
* @param db the database to add
*/
public function addDatabase($db)
{
if ($db instanceof Database) {
$db->setAppData($this);
if ($db->getPlatform() === null) {
$db->setPlatform($this->platform);
}
$this->dbList[] = $db;
return $db;
} else {
// XML attributes array / hash
$d = new Database();
$d->setAppData($this);
if ($d->getPlatform() === null) {
$d->setPlatform($this->platform);
}
$d->loadFromXML($db);
return $this->addDatabase($d); // calls self w/ different param type
}
}
public function doFinalInitialization()
{
if (!$this->isInitialized) {
for ($i=0, $size=count($this->dbList); $i < $size; $i++) {
$this->dbList[$i]->doFinalInitialization();
}
$this->isInitialized = true;
}
}
/**
* Creats a string representation of this AppData.
* The representation is given in xml format.
*
* @return string Representation in xml format
*/
public function toString()
{
$result = "<app-data>\n";
for ($i=0,$size=count($this->dbList); $i < $size; $i++) {
$result .= $this->dbList[$i]->toString();
}
$result .= "</app-data>";
return $result;
}
}

View file

@ -0,0 +1,247 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/Index.php';
require_once 'builder/util/PropelTemplate.php';
/**
* Information about behaviors of a table.
*
* @author François Zaninotto
* @version $Revision: 1784 $
* @package propel.generator.model
*/
class Behavior extends XMLElement
{
protected $table;
protected $database;
protected $name;
protected $parameters = array();
protected $isTableModified = false;
protected $isEarly = false;
protected $dirname;
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function setTable(Table $table)
{
$this->table = $table;
}
public function getTable()
{
return $this->table;
}
public function setDatabase(Database $database)
{
$this->database = $database;
}
public function getDatabase()
{
return $this->database;
}
/**
* Add a parameter
* Expects an associative array looking like array('name' => 'foo', 'value' => bar)
*
* @param array associative array with name and value keys
*/
public function addParameter($attribute)
{
$attribute = array_change_key_case($attribute, CASE_LOWER);
$this->parameters[$attribute['name']] = $attribute['value'];
}
/**
* Overrides the behavior parameters
* Expects an associative array looking like array('foo' => 'bar')
*
* @param array associative array
*/
public function setParameters($parameters)
{
$this->parameters = $parameters;
}
/**
* Get the associative array of parameters
* @return array
*/
public function getParameters()
{
return $this->parameters;
}
public function getParameter($name)
{
return $this->parameters[$name];
}
/**
* This method is automatically called on database behaviors when the database model is finished
* Propagate the behavior to the tables of the database
* Override this method to have a database behavior do something special
*/
public function modifyDatabase()
{
foreach ($this->getDatabase()->getTables() as $table)
{
$b = clone $this;
$table->addBehavior($b);
}
}
/**
* This method is automatically called on table behaviors when the database model is finished
* Override it to add columns to the current table
*/
public function modifyTable()
{
}
public function setTableModified($bool)
{
$this->isTableModified = $bool;
}
public function isTableModified()
{
return $this->isTableModified;
}
public function setEarly($bool = true)
{
$this->isEarly = $bool;
}
public function isEarly()
{
return $this->isEarly;
}
/**
* Use Propel's simple templating system to render a PHP file
* using variables passed as arguments.
*
* @param string $filename The template file name, relative to the behavior's dirname
* @param array $vars An associative array of argumens to be rendered
* @param string $templateDir The name of the template subdirectory
*
* @return string The rendered template
*/
public function renderTemplate($filename, $vars = array(), $templateDir = '/templates/')
{
$filePath = $this->getDirname() . $templateDir . $filename;
if (!file_exists($filePath)) {
// try with '.php' at the end
$filePath = $filePath . '.php';
if (!file_exists($filePath)) {
throw new InvalidArgumentException(sprintf('Template "%s" not found in "%s" directory',
$filename,
$this->getDirname() . $templateDir
));
}
}
$template = new PropelTemplate();
$template->setTemplateFile($filePath);
$vars = array_merge($vars, array('behavior' => $this));
return $template->render($vars);
}
/**
* Returns the current dirname of this behavior (also works for descendants)
*
* @return string The absolute directory name
*/
protected function getDirname()
{
if (null === $this->dirname) {
$r = new ReflectionObject($this);
$this->dirname = dirname($r->getFileName());
}
return $this->dirname;
}
/**
* Retrieve a column object using a name stored in the behavior parameters
* Useful for table behaviors
*
* @param string $param Name of the parameter storing the column name
* @return ColumnMap The column of the table supporting the behavior
*/
public function getColumnForParameter($param)
{
return $this->getTable()->getColumn($this->getParameter($param));
}
/**
* Sets up the Behavior object based on the attributes that were passed to loadFromXML().
* @see parent::loadFromXML()
*/
protected function setupObject()
{
$this->name = $this->getAttribute("name");
}
/**
* @see parent::appendXml(DOMNode)
*/
public function appendXml(DOMNode $node)
{
$doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
$bNode = $node->appendChild($doc->createElement('behavior'));
$bNode->setAttribute('name', $this->getName());
foreach ($this->parameters as $name => $value) {
$parameterNode = $bNode->appendChild($doc->createElement('parameter'));
$parameterNode->setAttribute('name', $name);
$parameterNode->setAttribute('value', $value);
}
}
public function getTableModifier()
{
return $this;
}
public function getObjectBuilderModifier()
{
return $this;
}
public function getQueryBuilderModifier()
{
return $this;
}
public function getPeerBuilderModifier()
{
return $this;
}
public function getTableMapBuilderModifier()
{
return $this;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,91 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* A class for holding a column default value.
*
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class ColumnDefaultValue
{
const TYPE_VALUE = "value";
const TYPE_EXPR = "expr";
/**
* @var string The default value, as specified in the schema.
*/
private $value;
/**
* @var string The type of value represented by this object (DefaultValue::TYPE_VALUE or DefaultValue::TYPE_EXPR).
*/
private $type = ColumnDefaultValue::TYPE_VALUE;
/**
* Creates a new DefaultValue object.
*
* @param string $value The default value, as specified in the schema.
* @param string $type The type of default value (DefaultValue::TYPE_VALUE or DefaultValue::TYPE_EXPR)
*/
public function __construct($value, $type = null)
{
$this->setValue($value);
if ($type !== null) {
$this->setType($type);
}
}
/**
* @return string The type of default value (DefaultValue::TYPE_VALUE or DefaultValue::TYPE_EXPR)
*/
public function getType()
{
return $this->type;
}
/**
* @param string $type The type of default value (DefaultValue::TYPE_VALUE or DefaultValue::TYPE_EXPR)
*/
public function setType($type)
{
$this->type = $type;
}
/**
* Convenience method to indicate whether the value in this object is an expression (as opposed to simple value).
*
* @return boolean Whether value this object holds is an expression.
*/
public function isExpression()
{
return ($this->type == self::TYPE_EXPR);
}
/**
* @return string The value, as specified in the schema.
*/
public function getValue()
{
return $this->value;
}
/**
* @param string $value The value, as specified in the schema.
*/
public function setValue($value)
{
$this->value = $value;
}
}

View file

@ -0,0 +1,72 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* A <code>NameGenerator</code> implementation for table-specific
* constraints. Conforms to the maximum column name length for the
* type of database in use.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class ConstraintNameGenerator implements NameGenerator
{
/**
* Conditional compilation flag.
*/
const DEBUG = false;
/**
* First element of <code>inputs</code> should be of type {@link Database}, second
* should be a table name, third is the type identifier (spared if
* trimming is necessary due to database type length constraints),
* and the fourth is a <code>Integer</code> indicating the number
* of this contraint.
*
* @see NameGenerator
* @throws EngineException
*/
public function generateName($inputs)
{
$db = $inputs[0];
$name = $inputs[1];
$namePostfix = $inputs[2];
$constraintNbr = (string) $inputs[3];
// Calculate maximum RDBMS-specific column character limit.
$maxBodyLength = -1;
try {
$maxColumnNameLength = (int) $db->getPlatform()->getMaxColumnNameLength();
$maxBodyLength = ($maxColumnNameLength - strlen($namePostfix)
- strlen($constraintNbr) - 2);
if (self::DEBUG) {
print("maxColumnNameLength=" . $maxColumnNameLength
. " maxBodyLength=" . $maxBodyLength . "\n");
}
} catch (EngineException $e) {
echo $e;
throw $e;
}
// Do any necessary trimming.
if ($maxBodyLength !== -1 && strlen($name) > $maxBodyLength) {
$name = substr($name, 0, $maxBodyLength);
}
$name .= self::STD_SEPARATOR_CHAR . $namePostfix
. self::STD_SEPARATOR_CHAR . $constraintNbr;
return $name;
}
}

View file

@ -0,0 +1,676 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/XMLElement.php';
require_once 'model/IDMethod.php';
require_once 'model/NameGenerator.php';
require_once 'model/Table.php';
require_once 'model/Behavior.php';
/**
* A class for holding application data structures.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Leon Messerschmidt <leon@opticode.co.za> (Torque)
* @author John McNally<jmcnally@collab.net> (Torque)
* @author Martin Poeschl<mpoeschl@marmot.at> (Torque)
* @author Daniel Rall<dlr@collab.net> (Torque)
* @author Byron Foster <byron_foster@yahoo.com> (Torque)
* @version $Revision: 1802 $
* @package propel.generator.model
*/
class Database extends XMLElement
{
private $platform;
private $tableList = array();
private $curColumn;
private $name;
private $pkg;
/**
* Namespace for the generated OM.
*
* @var string
*/
protected $namespace;
private $baseClass;
private $basePeer;
private $defaultIdMethod;
private $defaultPhpNamingMethod;
private $defaultTranslateMethod;
private $dbParent;
private $tablesByName = array();
private $tablesByPhpName = array();
private $heavyIndexing;
protected $tablePrefix = '';
private $domainMap = array();
/**
* List of behaviors registered for this table
*
* @var array
*/
protected $behaviors = array();
/**
* Constructs a new Database object.
*
* @param string $name
*/
public function __construct($name = null)
{
$this->name = $name;
}
/**
* Sets up the Database object based on the attributes that were passed to loadFromXML().
* @see parent::loadFromXML()
*/
protected function setupObject()
{
$this->name = $this->getAttribute("name");
$namespace = $this->getAttribute("namespace", '');
$package = $this->getAttribute("package");
if ($namespace && !$package && $this->getBuildProperty('namespaceAutoPackage')) {
$package = str_replace('\\', '.', $namespace);
}
$this->namespace = $namespace;
$this->pkg = $package;
$this->baseClass = $this->getAttribute("baseClass");
$this->basePeer = $this->getAttribute("basePeer");
$this->defaultIdMethod = $this->getAttribute("defaultIdMethod", IDMethod::NATIVE);
$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', $this->getBuildProperty('tablePrefix'));
}
/**
* Returns the Platform implementation for this database.
*
* @return Platform a Platform implementation
*/
public function getPlatform()
{
return $this->platform;
}
/**
* Sets the Platform implementation for this database.
*
* @param Platform $platform A Platform implementation
*/
public function setPlatform($platform)
{
$this->platform = $platform;
}
/**
* Get the name of the Database
*/
public function getName()
{
return $this->name;
}
/**
* Set the name of the Database
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get the value of package.
* @return value of package.
*/
public function getPackage()
{
return $this->pkg;
}
/**
* Set the value of package.
* @param v Value to assign to package.
*/
public function setPackage($v)
{
$this->pkg = $v;
}
/**
* Get the value of the namespace.
* @return value of namespace.
*/
public function getNamespace()
{
return $this->namespace;
}
/**
* Set the value of the namespace.
* @param v Value to assign to namespace.
*/
public function setNamespace($v)
{
$this->namespace = $v;
}
/**
* Get the value of baseClass.
* @return value of baseClass.
*/
public function getBaseClass()
{
return $this->baseClass;
}
/**
* Set the value of baseClass.
* @param v Value to assign to baseClass.
*/
public function setBaseClass($v)
{
$this->baseClass = $v;
}
/**
* Get the value of basePeer.
* @return value of basePeer.
*/
public function getBasePeer()
{
return $this->basePeer;
}
/**
* Set the value of basePeer.
* @param v Value to assign to basePeer.
*/
public function setBasePeer($v)
{
$this->basePeer = $v;
}
/**
* Get the value of defaultIdMethod.
* @return value of defaultIdMethod.
*/
public function getDefaultIdMethod()
{
return $this->defaultIdMethod;
}
/**
* Set the value of defaultIdMethod.
* @param v Value to assign to defaultIdMethod.
*/
public function setDefaultIdMethod($v)
{
$this->defaultIdMethod = $v;
}
/**
* Get the value of defaultPHPNamingMethod which specifies the
* method for converting schema names for table and column to PHP names.
* @return string The default naming conversion used by this database.
*/
public function getDefaultPhpNamingMethod()
{
return $this->defaultPhpNamingMethod;
}
/**
* Set the value of defaultPHPNamingMethod.
* @param string $v The default naming conversion for this database to use.
*/
public function setDefaultPhpNamingMethod($v)
{
$this->defaultPhpNamingMethod = $v;
}
/**
* Get the value of defaultTranslateMethod which specifies the
* method for translate validator error messages.
* @return string The default translate method.
*/
public function getDefaultTranslateMethod()
{
return $this->defaultTranslateMethod;
}
/**
* Set the value of defaultTranslateMethod.
* @param string $v The default translate method to use.
*/
public function setDefaultTranslateMethod($v)
{
$this->defaultTranslateMethod = $v;
}
/**
* Get the value of heavyIndexing.
*
* This is a synonym for getHeavyIndexing().
*
* @return boolean Value of heavyIndexing.
* @see getHeavyIndexing()
*/
public function isHeavyIndexing()
{
return $this->getHeavyIndexing();
}
/**
* Get the value of heavyIndexing.
*
* @return boolean Value of heavyIndexing.
*/
public function getHeavyIndexing()
{
return $this->heavyIndexing;
}
/**
* Set the value of heavyIndexing.
* @param boolean $v Value to assign to heavyIndexing.
*/
public function setHeavyIndexing($v)
{
$this->heavyIndexing = (boolean) $v;
}
/**
* Return an array of all tables
*/
public function getTables()
{
return $this->tableList;
}
/**
* Check whether the database has a table.
* @return boolean
*/
public function hasTable($name)
{
return array_key_exists($name, $this->tablesByName);
}
/**
* Return the table with the specified name.
* @param string $name The name of the table (e.g. 'my_table')
* @return Table a Table object or null if it doesn't exist
*/
public function getTable($name)
{
if ($this->hasTable($name)) {
return $this->tablesByName[$name];
}
return null; // just to be explicit
}
/**
* Return the table with the specified phpName.
* @param string $phpName the PHP Name of the table (e.g. 'MyTable')
* @return Table a Table object or null if it doesn't exist
*/
public function getTableByPhpName($phpName)
{
if (isset($this->tablesByPhpName[$phpName])) {
return $this->tablesByPhpName[$phpName];
}
return null; // just to be explicit
}
/**
* An utility method to add a new table from an xml attribute.
*/
public function addTable($data)
{
if ($data instanceof Table) {
$tbl = $data; // alias
$tbl->setDatabase($this);
if (isset($this->tablesByName[$tbl->getName()])) {
throw new EngineException("Duplicate table declared: " . $tbl->getName());
}
$this->tableList[] = $tbl;
$this->tablesByName[ $tbl->getName() ] = $tbl;
$this->tablesByPhpName[ $tbl->getPhpName() ] = $tbl;
if ($tbl->getPackage() === null) {
$tbl->setPackage($this->getPackage());
}
return $tbl;
} else {
$tbl = new Table();
$tbl->setDatabase($this);
$tbl->loadFromXML($data);
return $this->addTable($tbl); // call self w/ different param
}
}
/**
* Set the parent of the database
*/
public function setAppData(AppData $parent)
{
$this->dbParent = $parent;
}
/**
* Get the parent of the table
*/
public function getAppData()
{
return $this->dbParent;
}
/**
* Adds Domain object from <domain> tag.
* @param mixed XML attributes (array) or Domain object.
*/
public function addDomain($data) {
if ($data instanceof Domain) {
$domain = $data; // alias
$domain->setDatabase($this);
$this->domainMap[ $domain->getName() ] = $domain;
return $domain;
} else {
$domain = new Domain();
$domain->setDatabase($this);
$domain->loadFromXML($data);
return $this->addDomain($domain); // call self w/ different param
}
}
/**
* Get already configured Domain object by name.
* @return Domain
*/
public function getDomain($domainName)
{
if (isset($this->domainMap[$domainName])) {
return $this->domainMap[$domainName];
}
return null; // just to be explicit
}
public function getGeneratorConfig()
{
if ($this->getAppData() && $this->getAppData()->getPlatform()) {
return $this->getAppData()->getPlatform()->getGeneratorConfig();
} else {
return null;
}
}
public function getBuildProperty($key)
{
if($config = $this->getGeneratorConfig()) {
return $config->getBuildProperty($key);
} else {
return '';
}
}
/**
* Adds a new Behavior to the database
* @return Behavior A behavior instance
*/
public function addBehavior($bdata)
{
if ($bdata instanceof Behavior) {
$behavior = $bdata;
$behavior->setDatabase($this);
$this->behaviors[$behavior->getName()] = $behavior;
return $behavior;
} else {
$class = $this->getConfiguredBehavior($bdata['name']);
$behavior = new $class();
$behavior->loadFromXML($bdata);
return $this->addBehavior($behavior);
}
}
/**
* Get the database behaviors
* @return Array of Behavior objects
*/
public function getBehaviors()
{
return $this->behaviors;
}
/**
* check if the database has a behavior by name
*
* @param string $name the behavior name
* @return boolean True if the behavior exists
*/
public function hasBehavior($name)
{
return array_key_exists($name, $this->behaviors);
}
/**
* Get one database behavior by name
* @param string $name the behavior name
* @return Behavior a behavior object
*/
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()
{
if($defaultBehaviors = $this->getBuildProperty('behaviorDefault')) {
// add generic behaviors from build.properties
$defaultBehaviors = explode(',', $defaultBehaviors);
foreach ($defaultBehaviors as $behavior) {
$this->addBehavior(array('name' => trim($behavior)));
}
}
// execute behavior database modifiers
foreach ($this->getBehaviors() as $behavior) {
$behavior->modifyDatabase();
}
$tables = $this->getTables();
// execute early table behaviors
foreach ($tables as $table) {
foreach ($table->getEarlyBehaviors() as $behavior) {
if (!$behavior->isTableModified()) {
$behavior->getTableModifier()->modifyTable();
$behavior->setTableModified(true);
}
}
}
for ($i=0,$size=count($tables); $i < $size; $i++) {
$currTable = $tables[$i];
// check schema integrity
// if idMethod="autoincrement", make sure a column is
// specified as autoIncrement="true"
// FIXME: Handle idMethod="native" via DB adapter.
/*
--- REMOVING THIS BECAUSE IT'S ANNOYING
if ($currTable->getIdMethod() == IDMethod::NATIVE ) {
$columns = $currTable->getColumns();
$foundOne = false;
for ($j=0, $cLen=count($columns); $j < $cLen && !$foundOne; $j++) {
$foundOne = $columns[$j]->isAutoIncrement();
}
if (!$foundOne) {
$errorMessage = "Table '" . $currTable->getName()
. "' is set to use native id generation, but it does not "
. "have a column which declared as the one to "
. "auto increment (i.e. autoIncrement=\"true\")";
throw new BuildException($errorMessage);
}
}
*/
$currTable->doFinalInitialization();
// setup reverse fk relations
$fks = $currTable->getForeignKeys();
for ($j=0, $fksLen=count($fks); $j < $fksLen; $j++) {
$currFK = $fks[$j];
$foreignTable = $this->getTable($currFK->getForeignTableName());
if ($foreignTable === null) {
throw new BuildException("ERROR!! Attempt to set foreign"
. " key to nonexistent table, "
. $currFK->getForeignTableName() . "!");
}
$referrers = $foreignTable->getReferrers();
if ($referrers === null || !in_array($currFK, $referrers, true) ) {
$foreignTable->addReferrer($currFK);
}
// local column references
$localColumnNames = $currFK->getLocalColumns();
for ($k=0,$lcnLen=count($localColumnNames); $k < $lcnLen; $k++) {
$local = $currTable->getColumn($localColumnNames[$k]);
// give notice of a schema inconsistency.
// note we do not prevent the npe as there is nothing
// that we can do, if it is to occur.
if ($local === null) {
throw new BuildException("ERROR!! Attempt to define foreign"
. " key with nonexistent column, "
. $localColumnNames[$k] . ", in table, "
. $currTable->getName() . "!");
}
//check for foreign pk's
if ($local->isPrimaryKey()) {
$currTable->setContainsForeignPK(true);
}
} // for each local col name
// foreign column references
$foreignColumnNames = $currFK->getForeignColumns();
for ($k=0,$fcnLen=count($localColumnNames); $k < $fcnLen; $k++) {
$foreign = $foreignTable->getColumn($foreignColumnNames[$k]);
// if the foreign column does not exist, we may have an
// external reference or a misspelling
if ($foreign === null) {
throw new BuildException("ERROR!! Attempt to set foreign"
. " key to nonexistent column, "
. $foreignColumnNames[$k] . ", in table, "
. $foreignTable->getName() . "!");
} else {
$foreign->addReferrer($currFK);
}
} // for each foreign col ref
}
}
// Behaviors may have added behaviors of their own
// These behaviors must launch their modifyTable() method,
// Until there is no behavior left
$behaviorsLeft = true;
while ($behaviorsLeft) {
$behaviorsLeft = false;
foreach ($tables as $table) {
foreach ($table->getBehaviors() as $behavior) {
if (!$behavior->isTableModified()) {
$behavior->getTableModifier()->modifyTable();
$behavior->setTableModified(true);
$behaviorsLeft = true;
}
}
}
}
}
/**
* @see XMLElement::appendXml(DOMNode)
*/
public function appendXml(DOMNode $node)
{
$doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
$dbNode = $node->appendChild($doc->createElement('database'));
$dbNode->setAttribute('name', $this->name);
if ($this->pkg) {
$dbNode->setAttribute('package', $this->pkg);
}
if ($this->defaultIdMethod) {
$dbNode->setAttribute('defaultIdMethod', $this->defaultIdMethod);
}
if ($this->baseClass) {
$dbNode->setAttribute('baseClass', $this->baseClass);
}
if ($this->basePeer) {
$dbNode->setAttribute('basePeer', $this->basePeer);
}
if ($this->defaultPhpNamingMethod) {
$dbNode->setAttribute('defaultPhpNamingMethod', $this->defaultPhpNamingMethod);
}
if ($this->defaultTranslateMethod) {
$dbNode->setAttribute('defaultTranslateMethod', $this->defaultTranslateMethod);
}
/*
FIXME - Before we can add support for domains in the schema, we need
to have a method of the Column that indicates whether the column was mapped
to a SPECIFIC domain (since Column->getDomain() will always return a Domain object)
foreach ($this->domainMap as $domain) {
$domain->appendXml($dbNode);
}
*/
foreach ($this->vendorInfos as $vi) {
$vi->appendXml($dbNode);
}
foreach ($this->tableList as $table) {
$table->appendXml($dbNode);
}
}
}

View file

@ -0,0 +1,386 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/XMLElement.php';
/**
* A class for holding data about a domain used in the schema.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Martin Poeschl <mpoeschl@marmot.at> (Torque)
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class Domain extends XMLElement
{
/**
* @var string The name of this domain
*/
private $name;
/**
* @var string Description for this domain.
*/
private $description;
/**
* @var int Size
*/
private $size;
/**
* @var int Scale
*/
private $scale;
/**
* @var int Propel type from schema
*/
private $propelType;
/**
* @var string The SQL type to use for this column
*/
private $sqlType;
/**
* @var ColumnDefaultValue A default value
*/
private $defaultValue;
/**
* @var Database
*/
private $database;
/**
* Creates a new Domain object.
* If this domain needs a name, it must be specified manually.
*
* @param string $type Propel type.
* @param string $sqlType SQL type.
* @param string $size
* @param string $scale
*/
public function __construct($type = null, $sqlType = null, $size = null, $scale = null)
{
$this->propelType = $type;
$this->sqlType = ($sqlType !== null) ? $sqlType : $type;
$this->size = $size;
$this->scale = $scale;
}
/**
* Copy the values from current object into passed-in Domain.
* @param Domain $domain Domain to copy values into.
*/
public function copy(Domain $domain)
{
$this->defaultValue = $domain->getDefaultValue();
$this->description = $domain->getDescription();
$this->name = $domain->getName();
$this->scale = $domain->getScale();
$this->size = $domain->getSize();
$this->sqlType = $domain->getSqlType();
$this->propelType = $domain->getType();
}
/**
* Sets up the Domain object based on the attributes that were passed to loadFromXML().
* @see parent::loadFromXML()
*/
protected function setupObject()
{
$schemaType = strtoupper($this->getAttribute("type"));
$this->copy($this->getDatabase()->getPlatform()->getDomainForType($schemaType));
//Name
$this->name = $this->getAttribute("name");
// Default value
$defval = $this->getAttribute("defaultValue", $this->getAttribute("default"));
if ($defval !== null) {
$this->setDefaultValue(new ColumnDefaultValue($defval, ColumnDefaultValue::TYPE_VALUE));
} elseif ($this->getAttribute("defaultExpr") !== null) {
$this->setDefaultValue(new ColumnDefaultValue($this->getAttribute("defaultExpr"), ColumnDefaultValue::TYPE_EXPR));
}
$this->size = $this->getAttribute("size");
$this->scale = $this->getAttribute("scale");
$this->description = $this->getAttribute("description");
}
/**
* Sets the owning database object (if this domain is being setup via XML).
* @param Database $database
*/
public function setDatabase(Database $database)
{
$this->database = $database;
}
/**
* Gets the owning database object (if this domain was setup via XML).
* @return Database
*/
public function getDatabase()
{
return $this->database;
}
/**
* @return string Returns the description.
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description The description to set.
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return string Returns the name.
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name The name to set.
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return string Returns the scale.
*/
public function getScale()
{
return $this->scale;
}
/**
* @param string $scale The scale to set.
*/
public function setScale($scale)
{
$this->scale = $scale;
}
/**
* Replaces the size if the new value is not null.
*
* @param string $value The size to set.
*/
public function replaceScale($value)
{
if ($value !== null) {
$this->scale = $value;
}
}
/**
* @return int Returns the size.
*/
public function getSize()
{
return $this->size;
}
/**
* @param int $size The size to set.
*/
public function setSize($size)
{
$this->size = $size;
}
/**
* Replaces the size if the new value is not null.
*
* @param int $value The size to set.
*/
public function replaceSize($value)
{
if ($value !== null) {
$this->size = $value;
}
}
/**
* @return string Returns the propelType.
*/
public function getType()
{
return $this->propelType;
}
/**
* @param string $propelType The PropelTypes type to set.
*/
public function setType($propelType)
{
$this->propelType = $propelType;
}
/**
* Replaces the type if the new value is not null.
*
* @param string $value The tyep to set.
*/
public function replaceType($value)
{
if ($value !== null) {
$this->propelType = $value;
}
}
/**
* Gets the default value object.
* @return ColumnDefaultValue The default value object for this domain.
*/
public function getDefaultValue()
{
return $this->defaultValue;
}
/**
* Gets the default value, type-casted for use in PHP OM.
* @return mixed
* @see getDefaultValue()
*/
public function getPhpDefaultValue()
{
if ($this->defaultValue === null) {
return null;
} else {
if ($this->defaultValue->isExpression()) {
throw new EngineException("Cannot get PHP version of default value for default value EXPRESSION.");
}
if ($this->propelType === PropelTypes::BOOLEAN || $this->propelType === PropelTypes::BOOLEAN_EMU) {
return $this->booleanValue($this->defaultValue->getValue());
} else {
return $this->defaultValue->getValue();
}
}
}
/**
* @param ColumnDefaultValue $value The column default value to set.
*/
public function setDefaultValue(ColumnDefaultValue $value)
{
$this->defaultValue = $value;
}
/**
* Replaces the default value if the new value is not null.
*
* @param ColumnDefaultValue $value The defualt value object
*/
public function replaceDefaultValue(ColumnDefaultValue $value = null)
{
if ($value !== null) {
$this->defaultValue = $value;
}
}
/**
* @return string Returns the sqlType.
*/
public function getSqlType()
{
return $this->sqlType;
}
/**
* @param string $sqlType The sqlType to set.
*/
public function setSqlType($sqlType)
{
$this->sqlType = $sqlType;
}
/**
* Replaces the SQL type if the new value is not null.
* @param string $sqlType The native SQL type to use for this domain.
*/
public function replaceSqlType($sqlType)
{
if ($sqlType !== null) {
$this->sqlType = $sqlType;
}
}
/**
* Return the size and scale in brackets for use in an sql schema.
*
* @return string Size and scale or an empty String if there are no values
* available.
*/
public function printSize()
{
if ($this->size !== null && $this->scale !== null) {
return '(' . $this->size . ',' . $this->scale . ')';
} elseif ($this->size !== null) {
return '(' . $this->size . ')';
} else {
return "";
}
}
/**
* @see XMLElement::appendXml(DOMNode)
*/
public function appendXml(DOMNode $node)
{
$doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
$domainNode = $node->appendChild($doc->createElement('domain'));
$domainNode->setAttribute('type', $this->getType());
$domainNode->setAttribute('name', $this->getName());
if ($this->sqlType !== $this->getType()) {
$domainNode->setAttribute('sqlType', $this->sqlType);
}
$def = $this->getDefaultValue();
if ($def) {
if ($def->isExpression()) {
$domainNode->setAttribute('defaultExpr', $def->getValue());
} else {
$domainNode->setAttribute('defaultValue', $def->getValue());
}
}
if ($this->size) {
$domainNode->setAttribute('size', $this->size);
}
if ($this->scale) {
$domainNode->setAttribute('scale', $this->scale);
}
if ($this->description) {
$domainNode->setAttribute('description', $this->description);
}
}
}

View file

@ -0,0 +1,509 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/XMLElement.php';
/**
* A Class for information about foreign keys of a table.
*
* @author Hans Lellelid <hans@xmpl.org>
* @author Fedor <fedor.karpelevitch@home.com>
* @author Daniel Rall <dlr@finemaltcoding.com>
* @version $Revision: 1778 $
* @package propel.generator.model
*/
class ForeignKey extends XMLElement
{
protected $foreignTableName;
protected $name;
protected $phpName;
protected $refPhpName;
protected $defaultJoin;
protected $onUpdate;
protected $onDelete;
protected $parentTable;
protected $localColumns = array();
protected $foreignColumns = array();
// the uppercase equivalent of the onDelete/onUpdate values in the dtd
const NONE = ""; // No "ON [ DELETE | UPDATE]" behaviour specified.
const NOACTION = "NO ACTION";
const CASCADE = "CASCADE";
const RESTRICT = "RESTRICT";
const SETDEFAULT = "SET DEFAULT";
const SETNULL = "SET NULL";
/**
* Constructs a new ForeignKey object.
*
* @param string $name
*/
public function __construct($name=null)
{
$this->name = $name;
}
/**
* Sets up the ForeignKey object based on the attributes that were passed to loadFromXML().
* @see parent::loadFromXML()
*/
protected function setupObject()
{
$this->foreignTableName = $this->getTable()->getDatabase()->getTablePrefix() . $this->getAttribute("foreignTable");
$this->name = $this->getAttribute("name");
$this->phpName = $this->getAttribute("phpName");
$this->refPhpName = $this->getAttribute("refPhpName");
$this->defaultJoin = $this->getAttribute('defaultJoin');
$this->onUpdate = $this->normalizeFKey($this->getAttribute("onUpdate"));
$this->onDelete = $this->normalizeFKey($this->getAttribute("onDelete"));
}
/**
* normalizes the input of onDelete, onUpdate attributes
*/
private function normalizeFKey($attrib)
{
if ($attrib === null || strtoupper($attrib) == "NONE") {
$attrib = self::NONE;
}
$attrib = strtoupper($attrib);
if ($attrib == "SETNULL") {
$attrib = self::SETNULL;
}
return $attrib;
}
/**
* returns whether or not the onUpdate attribute is set
*/
public function hasOnUpdate()
{
return ($this->onUpdate !== self::NONE);
}
/**
* returns whether or not the onDelete attribute is set
*/
public function hasOnDelete()
{
return ($this->onDelete !== self::NONE);
}
/**
* returns the onUpdate attribute
* @return string
*/
public function getOnUpdate()
{
return $this->onUpdate;
}
/**
* Returns the onDelete attribute
* @return string
*/
public function getOnDelete()
{
return $this->onDelete;
}
/**
* sets the onDelete attribute
*/
public function setOnDelete($value)
{
$this->onDelete = $this->normalizeFKey($value);
}
/**
* sets the onUpdate attribute
*/
public function setOnUpdate($value)
{
$this->onUpdate = $this->normalizeFKey($value);
}
/**
* Returns the name attribute.
*/
public function getName()
{
return $this->name;
}
/**
* Sets the name attribute.
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Gets the phpName for this foreign key (if any).
* @return string
*/
public function getPhpName()
{
return $this->phpName;
}
/**
* Sets a phpName to use for this foreign key.
* @param string $name
*/
public function setPhpName($name)
{
$this->phpName = $name;
}
/**
* Gets the refPhpName for this foreign key (if any).
* @return string
*/
public function getRefPhpName()
{
return $this->refPhpName;
}
/**
* Sets a refPhpName to use for this foreign key.
* @param string $name
*/
public function setRefPhpName($name)
{
$this->refPhpName = $name;
}
/**
* Gets the defaultJoin for this foreign key (if any).
* @return string
*/
public function getDefaultJoin()
{
return $this->defaultJoin;
}
/**
* Sets a defaultJoin to use for this foreign key.
* @param string $name
*/
public function setDefaultJoin($defaultJoin)
{
$this->defaultJoin = $defaultJoin;
}
/**
* Get the foreignTableName of the FK
*/
public function getForeignTableName()
{
return $this->foreignTableName;
}
/**
* Set the foreignTableName of the FK
*/
public function setForeignTableName($tableName)
{
$this->foreignTableName = $tableName;
}
/**
* Gets the resolved foreign Table model object.
* @return Table
*/
public function getForeignTable()
{
return $this->getTable()->getDatabase()->getTable($this->getForeignTableName());
}
/**
* Set the parent Table of the foreign key
*/
public function setTable(Table $parent)
{
$this->parentTable = $parent;
}
/**
* Get the parent Table of the foreign key
*/
public function getTable()
{
return $this->parentTable;
}
/**
* Returns the Name of the table the foreign key is in
*/
public function getTableName()
{
return $this->parentTable->getName();
}
/**
* Adds a new reference entry to the foreign key.
*/
public function addReference($p1, $p2 = null)
{
if (is_array($p1)) {
$this->addReference(@$p1["local"], @$p1["foreign"]);
} else {
if ($p1 instanceof Column) {
$p1 = $p1->getName();
}
if ($p2 instanceof Column) {
$p2 = $p2->getName();
}
$this->localColumns[] = $p1;
$this->foreignColumns[] = $p2;
}
}
/**
* Clear the references of this foreign key
*/
public function clearReferences()
{
$this->localColumns[] = array();
$this->foreignColumns[] = array();
}
/**
* Return a comma delimited string of local column names
* @deprecated because Column::makeList() is deprecated; use the array-returning getLocalColumns() and DDLBuilder->getColumnList() instead instead.
*/
public function getLocalColumnNames()
{
return Column::makeList($this->getLocalColumns(), $this->getTable()->getDatabase()->getPlatform());
}
/**
* Return a comma delimited string of foreign column names
* @deprecated because Column::makeList() is deprecated; use the array-returning getForeignColumns() and DDLBuilder->getColumnList() instead instead.
*/
public function getForeignColumnNames()
{
return Column::makeList($this->getForeignColumns(), $this->getTable()->getDatabase()->getPlatform());
}
/**
* Return an array of local column names.
* @return array string[]
*/
public function getLocalColumns()
{
return $this->localColumns;
}
/**
* Utility method to get local column to foreign column
* mapping for this foreign key.
*/
public function getLocalForeignMapping()
{
$h = array();
for ($i=0, $size=count($this->localColumns); $i < $size; $i++) {
$h[$this->localColumns[$i]] = $this->foreignColumns[$i];
}
return $h;
}
/**
* Utility method to get local column to foreign column
* mapping for this foreign key.
*/
public function getForeignLocalMapping()
{
$h = array();
for ($i=0, $size=count($this->localColumns); $i < $size; $i++) {
$h[$this->foreignColumns[$i]] = $this->localColumns[$i];
}
return $h;
}
/**
* Utility method to get local and foreign column objects
* mapping for this foreign key.
*/
public function getColumnObjectsMapping()
{
$mapping = array();
$localTable = $this->getTable();
$foreignTable = $this->getForeignTable();
for ($i=0, $size=count($this->localColumns); $i < $size; $i++) {
$mapping[]= array(
'local' => $localTable->getColumn($this->localColumns[$i]),
'foreign' => $foreignTable->getColumn($this->foreignColumns[$i]),
);
}
return $mapping;
}
/**
* Get the foreign column mapped to specified local column.
* @return string Column name.
*/
public function getMappedForeignColumn($local)
{
$m = $this->getLocalForeignMapping();
if (isset($m[$local])) {
return $m[$local];
}
return null;
}
/**
* Get the local column mapped to specified foreign column.
* @return string Column name.
*/
public function getMappedLocalColumn($foreign)
{
$m = $this->getForeignLocalMapping();
if (isset($m[$foreign])) {
return $m[$foreign];
}
return null;
}
/**
* Return an array of foreign column objects.
* @return array Column[]
*/
public function getForeignColumns()
{
return $this->foreignColumns;
}
/**
* Whether this foreign key uses a required column, or a list or required columns.
*
* @return boolean
*/
public function isLocalColumnsRequired()
{
foreach ($this->getLocalColumns() as $columnName) {
if (!$this->getTable()->getColumn($columnName)->isNotNull()) {
return false;
}
}
return true;
}
/**
* Whether this foreign key is also the primary key of the local table.
*
* @return boolean
*/
public function isLocalPrimaryKey()
{
$localCols = $this->getLocalColumns();
$localPKColumnObjs = $this->getTable()->getPrimaryKey();
$localPKCols = array();
foreach ($localPKColumnObjs as $lPKCol) {
$localPKCols[] = $lPKCol->getName();
}
return (!array_diff($localPKCols, $localCols));
}
/**
* Whether this foreign key is matched by an invertes foreign key (on foreign table).
*
* This is to prevent duplicate columns being generated for a 1:1 relationship that is represented
* by foreign keys on both tables. I don't know if that's good practice ... but hell, why not
* support it.
*
* @param ForeignKey $fk
* @return boolean
* @link http://propel.phpdb.org/trac/ticket/549
*/
public function isMatchedByInverseFK()
{
return (bool) $this->getInverseFK();
}
public function getInverseFK()
{
$foreignTable = $this->getForeignTable();
$map = $this->getForeignLocalMapping();
foreach ($foreignTable->getForeignKeys() as $refFK) {
$fkMap = $refFK->getLocalForeignMapping();
if ( ($refFK->getTableName() == $this->getTableName()) && ($map == $fkMap) ) { // compares keys and values, but doesn't care about order, included check to make sure it's the same table (fixes #679)
return $refFK;
}
}
}
/**
* Get the other foreign keys starting on the same table
* Used in many-to-many relationships
*
* @return ForeignKey
*/
public function getOtherFks()
{
$fks = array();
foreach ($this->getTable()->getForeignKeys() as $fk) {
if ($fk !== $this) {
$fks[]= $fk;
}
}
return $fks;
}
/**
* @see XMLElement::appendXml(DOMNode)
*/
public function appendXml(DOMNode $node)
{
$doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
$fkNode = $node->appendChild($doc->createElement('foreign-key'));
$fkNode->setAttribute('foreignTable', $this->getForeignTableName());
$fkNode->setAttribute('name', $this->getName());
if ($this->getPhpName()) {
$fkNode->setAttribute('phpName', $this->getPhpName());
}
if ($this->getRefPhpName()) {
$fkNode->setAttribute('refPhpName', $this->getRefPhpName());
}
if ($this->getDefaultJoin()) {
$fkNode->setAttribute('defaultJoin', $this->getDefaultJoin());
}
if ($this->getOnDelete()) {
$fkNode->setAttribute('onDelete', $this->getOnDelete());
}
if ($this->getOnUpdate()) {
$fkNode->setAttribute('onUpdate', $this->getOnUpdate());
}
for ($i=0, $size=count($this->localColumns); $i < $size; $i++) {
$refNode = $fkNode->appendChild($doc->createElement('reference'));
$refNode->setAttribute('local', $this->localColumns[$i]);
$refNode->setAttribute('foreign', $this->foreignColumns[$i]);
}
foreach ($this->vendorInfos as $vi) {
$vi->appendXml($fkNode);
}
}
}

View file

@ -0,0 +1,35 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Interface for various ID retrieval method types
* (i.e. auto-increment, sequence, ID broker, etc.).
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Daniel Rall <dlr@collab.net> (Torque)
* @version $Revision: 1612 $
* @package propel.generator.model
*/
interface IDMethod
{
/**
* Key generation via database-specific ID method
* (i.e. auto-increment for MySQL, sequence for Oracle, etc.).
*/
const NATIVE = "native";
/**
* No RDBMS key generation (keys may be generated by the
* application).
*/
const NO_ID_METHOD = "none";
}

View file

@ -0,0 +1,108 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/XMLElement.php';
/**
* Information related to an ID method.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author John McNally <jmcnally@collab.net> (Torque)
* @author Daniel Rall <dlr@collab.net> (Torque)
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class IdMethodParameter extends XMLElement
{
private $name;
private $value;
private $parentTable;
/**
* Sets up the IdMethodParameter object based on the attributes that were passed to loadFromXML().
* @see parent::loadFromXML()
*/
protected function setupObject()
{
$this->name = $this->getAttribute("name");
$this->value = $this->getAttribute("value");
}
/**
* Get the parameter name
*/
public function getName()
{
return $this->name;
}
/**
* Set the parameter name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get the parameter value
*/
public function getValue()
{
return $this->value;
}
/**
* Set the parameter value
*/
public function setValue($value)
{
$this->value = $value;
}
/**
* Set the parent Table of the id method
*/
public function setTable(Table $parent)
{
$this->parentTable = $parent;
}
/**
* Get the parent Table of the id method
*/
public function getTable()
{
return $this->parentTable;
}
/**
* Returns the Name of the table the id method is in
*/
public function getTableName()
{
return $this->parentTable->getName();
}
/**
* @see XMLElement::appendXml(DOMNode)
*/
public function appendXml(DOMNode $node)
{
$doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
$paramNode = $node->appendChild($doc->createElement('id-method-parameter'));
if ($this->getName()) {
$paramNode->setAttribute('name', $this->getName());
}
$paramNode->setAttribute('value', $this->getValue());
}
}

View file

@ -0,0 +1,285 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/XMLElement.php';
require_once 'exception/EngineException.php';
/**
* Information about indices of a table.
*
* @author Jason van Zyl <vanzyl@apache.org>
* @author Daniel Rall <dlr@finemaltcoding.com>
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class Index extends XMLElement
{
/** enables debug output */
const DEBUG = false;
private $indexName;
private $parentTable;
/** @var array string[] */
private $indexColumns;
/** @var array */
private $indexColumnSizes = array();
/**
* Creates a new Index instance.
*
* @param string $name
*/
public function __construct($name=null)
{
$this->indexName = $name;
}
private function createName()
{
$table = $this->getTable();
$inputs = array();
$inputs[] = $table->getDatabase();
$inputs[] = $table->getName();
if ($this->isUnique()) {
$inputs[] = "U";
} else {
$inputs[] = "I";
}
// ASSUMPTION: This Index not yet added to the list.
if ($this->isUnique()) {
$inputs[] = count($table->getUnices()) + 1;
} else {
$inputs[] = count($table->getIndices()) + 1;
}
$this->indexName = NameFactory::generateName(
NameFactory::CONSTRAINT_GENERATOR, $inputs);
}
/**
* Sets up the Index object based on the attributes that were passed to loadFromXML().
* @see parent::loadFromXML()
*/
protected function setupObject()
{
$this->indexName = $this->getAttribute("name");
}
/**
* @see #isUnique()
* @deprecated Use isUnique() instead.
*/
public function getIsUnique()
{
return $this->isUnique();
}
/**
* Returns the uniqueness of this index.
*/
public function isUnique()
{
return false;
}
/**
* @see #getName()
* @deprecated Use getName() instead.
*/
public function getIndexName()
{
return $this->getName();
}
/**
* Gets the name of this index.
*/
public function getName()
{
if ($this->indexName === null) {
try {
// generate an index name if we don't have a supplied one
$this->createName();
} catch (EngineException $e) {
// still no name
}
}
return substr($this->indexName, 0, $this->getTable()->getDatabase()->getPlatform()->getMaxColumnNameLength());
}
/**
* @see #setName(String name)
* @deprecated Use setName(String name) instead.
*/
public function setIndexName($name)
{
$this->setName($name);
}
/**
* Set the name of this index.
*/
public function setName($name)
{
$this->indexName = $name;
}
/**
* Set the parent Table of the index
*/
public function setTable(Table $parent)
{
$this->parentTable = $parent;
}
/**
* Get the parent Table of the index
*/
public function getTable()
{
return $this->parentTable;
}
/**
* Returns the Name of the table the index is in
*/
public function getTableName()
{
return $this->parentTable->getName();
}
/**
* Adds a new column to an index.
* @param mixed $data Column or attributes from XML.
*/
public function addColumn($data)
{
if ($data instanceof Column) {
$column = $data;
$this->indexColumns[] = $column->getName();
if ($column->getSize()) {
$this->indexColumnSizes[$column->getName()] = $column->getSize();
}
} else {
$attrib = $data;
$name = $attrib["name"];
$this->indexColumns[] = $name;
if (isset($attrib["size"])) {
$this->indexColumnSizes[$name] = $attrib["size"];
}
}
}
/**
* Sets array of columns to use for index.
*
* @param array $indexColumns Column[]
*/
public function setColumns(array $indexColumns)
{
$this->indexColumns = array();
$this->indexColumnSizes = array();
foreach ($indexColumns as $col) {
$this->addColumn($col);
}
}
/**
* Whether there is a size for the specified column.
* @param string $name
* @return boolean
*/
public function hasColumnSize($name)
{
return isset($this->indexColumnSizes[$name]);
}
/**
* Returns the size for the specified column, if given.
* @param string $name
* @return numeric The size or NULL
*/
public function getColumnSize($name)
{
if (isset($this->indexColumnSizes[$name])) {
return $this->indexColumnSizes[$name];
}
return null; // just to be explicit
}
/**
* @see #getColumnList()
* @deprecated Use getColumnList() instead (which is not deprecated too!)
*/
public function getIndexColumnList()
{
return $this->getColumnList();
}
/**
* Return a comma delimited string of the columns which compose this index.
* @deprecated because Column::makeList() is deprecated; use the array-returning getColumns() and DDLBuilder->getColumnList() instead instead.
*/
public function getColumnList()
{
return Column::makeList($this->getColumns(), $this->getTable()->getDatabase()->getPlatform());
}
/**
* @see #getColumns()
* @deprecated Use getColumns() instead.
*/
public function getIndexColumns()
{
return $this->getColumns();
}
/**
* Check whether the index has columns.
* @return boolean
*/
public function hasColumns()
{
return count($this->indexColumns) > 0;
}
/**
* Return the list of local columns. You should not edit this list.
* @return array string[]
*/
public function getColumns()
{
return $this->indexColumns;
}
/**
* @see XMLElement::appendXml(DOMNode)
*/
public function appendXml(DOMNode $node)
{
$doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
$idxNode = $node->appendChild($doc->createElement('index'));
$idxNode->setAttribute('name', $this->getName());
foreach ($this->indexColumns as $colname) {
$idxColNode = $idxNode->appendChild($doc->createElement('index-column'));
$idxColNode->setAttribute('name', $colname);
}
foreach ($this->vendorInfos as $vi) {
$vi->appendXml($idxNode);
}
}
}

View file

@ -0,0 +1,147 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/XMLElement.php';
/**
* A Class for information regarding possible objects representing a table
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author John McNally <jmcnally@collab.net> (Torque)
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class Inheritance extends XMLElement
{
private $key;
private $className;
private $pkg;
private $ancestor;
private $parent;
/**
* Sets up the Inheritance object based on the attributes that were passed to loadFromXML().
* @see parent::loadFromXML()
*/
protected function setupObject()
{
$this->key = $this->getAttribute("key");
$this->className = $this->getAttribute("class");
$this->pkg = $this->getAttribute("package");
$this->ancestor = $this->getAttribute("extends");
}
/**
* Get the value of key.
* @return value of key.
*/
public function getKey()
{
return $this->key;
}
/**
* Set the value of key.
* @param v Value to assign to key.
*/
public function setKey($v)
{
$this->key = $v;
}
/**
* Get the value of parent.
* @return value of parent.
*/
public function getColumn()
{
return $this->parent;
}
/**
* Set the value of parent.
* @param v Value to assign to parent.
*/
public function setColumn(Column $v)
{
$this->parent = $v;
}
/**
* Get the value of className.
* @return value of className.
*/
public function getClassName()
{
return $this->className;
}
/**
* Set the value of className.
* @param v Value to assign to className.
*/
public function setClassName($v)
{
$this->className = $v;
}
/**
* Get the value of package.
* @return value of package.
*/
public function getPackage()
{
return $this->pkg;
}
/**
* Set the value of package.
* @param v Value to assign to package.
*/
public function setPackage($v)
{
$this->pkg = $v;
}
/**
* Get the value of ancestor.
* @return value of ancestor.
*/
public function getAncestor()
{
return $this->ancestor;
}
/**
* Set the value of ancestor.
* @param v Value to assign to ancestor.
*/
public function setAncestor($v)
{
$this->ancestor = $v;
}
/**
* @see XMLElement::appendXml(DOMNode)
*/
public function appendXml(DOMNode $node)
{
$doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
$inherNode = $node->appendChild($doc->createElement('inheritance'));
$inherNode->setAttribute('key', $this->key);
$inherNode->setAttribute('class', $this->className);
if ($this->ancestor !== null) {
$inherNode->setAttribute('extends', $this->ancestor);
}
}
}

View file

@ -0,0 +1,77 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'exception/EngineException.php';
require_once 'model/NameGenerator.php';
require_once 'model/PhpNameGenerator.php';
require_once 'model/ConstraintNameGenerator.php';
/**
* A name generation factory.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class NameFactory
{
/**
* The class name of the PHP name generator.
*/
const PHP_GENERATOR = 'PhpNameGenerator';
/**
* The fully qualified class name of the constraint name generator.
*/
const CONSTRAINT_GENERATOR = 'ConstraintNameGenerator';
/**
* The single instance of this class.
*/
private static $instance;
/**
* The cache of <code>NameGenerator</code> algorithms in use for
* name generation, keyed by fully qualified class name.
*/
private static $algorithms = array();
/**
* Factory method which retrieves an instance of the named generator.
*
* @param name The fully qualified class name of the name
* generation algorithm to retrieve.
*/
protected static function getAlgorithm($name)
{
if (!isset(self::$algorithms[$name])) {
self::$algorithms[$name] = new $name();
}
return self::$algorithms[$name];
}
/**
* Given a list of <code>String</code> objects, implements an
* algorithm which produces a name.
*
* @param string $algorithmName The fully qualified class name of the {@link NameGenerator}
* implementation to use to generate names.
* @param array $inputs Inputs used to generate a name.
* @return The generated name.
* @throws EngineException
*/
public static function generateName($algorithmName, $inputs)
{
$algorithm = self::getAlgorithm($algorithmName);
return $algorithm->generateName($inputs);
}
}

View file

@ -0,0 +1,73 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* The generic interface to a name generation algorithm.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
* @author Byron Foster <byron_foster@yahoo.com> (Torque)
* @version $Revision: 1612 $
* @package propel.generator.model
*/
interface NameGenerator
{
/**
* The character used by most implementations as the separator
* between name elements.
*/
const STD_SEPARATOR_CHAR = '_';
/**
* Traditional method for converting schema table and column names
* to PHP names. The <code>CONV_METHOD_XXX</code> constants
* define how names for columns and tables in the database schema
* will be converted to PHP source names.
*
* @see PhpNameGenerator::underscoreMethod()
*/
const CONV_METHOD_UNDERSCORE = "underscore";
/**
* Heavier method for converting schema table and column names
* to PHP names. Similar to {@link #CONV_METHOD_UNDERSCORE} but
* this one will pass only letters and numbers through and will
* use as separator any character that is not a letter or a number
* inside the string to be converted. The <code>CONV_METHOD_XXX</code>
* constants define how names for columns and tales in the
* database schema will be converted to PHP source names.
*/
const CONV_METHOD_CLEAN = "clean";
/**
* Similar to {@link #CONV_METHOD_UNDERSCORE} except nothing is
* converted to lowercase.
*
* @see PhpNameGenerator::phpnameMethod()
*/
const CONV_METHOD_PHPNAME = "phpname";
/**
* Specifies no modification when converting from a schema column
* or table name to a PHP name.
*/
const CONV_METHOD_NOCHANGE = "nochange";
/**
* Given a list of <code>String</code> objects, implements an
* algorithm which produces a name.
*
* @param inputs Inputs used to generate a name.
* @return The generated name.
* @throws EngineException
*/
public function generateName($inputs);
}

View file

@ -0,0 +1,167 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/NameGenerator.php';
/**
* A <code>NameGenerator</code> implementation for PHP-esque names.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
* @author Byron Foster <byron_foster@yahoo.com> (Torque)
* @author Bernd Goldschmidt <bgoldschmidt@rapidsoft.de>
* @version $Revision: 1793 $
* @package propel.generator.model
*/
class PhpNameGenerator implements NameGenerator
{
/**
* <code>inputs</code> should consist of two (three) elements, the
* original name of the database element and the method for
* generating the name.
* The optional third element may contain a prefix that will be
* stript from name prior to generate the resulting name.
* There are currently three methods:
* <code>CONV_METHOD_NOCHANGE</code> - xml names are converted
* directly to php names without modification.
* <code>CONV_METHOD_UNDERSCORE</code> will capitalize the first
* letter, remove underscores, and capitalize each letter before
* an underscore. All other letters are lowercased. "phpname"
* works the same as the <code>CONV_METHOD_PHPNAME</code> method
* but will not lowercase any characters.
*
* @param inputs list expected to contain two (optional: three) parameters,
* element 0 contains name to convert, element 1 contains method for conversion,
* optional element 2 contains prefix to be striped from name
* @return The generated name.
* @see NameGenerator
*/
public function generateName($inputs)
{
$schemaName = $inputs[0];
$method = $inputs[1];
if (count($inputs)>2) {
$prefix = $inputs[2];
if ($prefix != '' && substr($schemaName, 0, strlen($prefix)) == $prefix) {
$schemaName = substr($schemaName, strlen($prefix));
}
}
$phpName = null;
switch ($method) {
case self::CONV_METHOD_CLEAN:
$phpName = $this->cleanMethod($schemaName);
break;
case self::CONV_METHOD_PHPNAME:
$phpName = $this->phpnameMethod($schemaName);
break;
case self::CONV_METHOD_NOCHANGE:
$phpName = $this->nochangeMethod($schemaName);
break;
case self::CONV_METHOD_UNDERSCORE:
default:
$phpName = $this->underscoreMethod($schemaName);
}
return $phpName;
}
/**
* Converts a database schema name to php object name by Camelization.
* Removes <code>STD_SEPARATOR_CHAR</code>, capitilizes first letter
* of name and each letter after the <code>STD_SEPERATOR</code>,
* converts the rest of the letters to lowercase.
*
* This method should be named camelizeMethod() for clarity
*
* my_CLASS_name -> MyClassName
*
* @param string $schemaName name to be converted.
* @return string Converted name.
* @see NameGenerator
* @see #underscoreMethod()
*/
protected function underscoreMethod($schemaName)
{
$name = "";
$tok = strtok($schemaName, self::STD_SEPARATOR_CHAR);
while ($tok) {
$name .= ucfirst(strtolower($tok));
$tok = strtok(self::STD_SEPARATOR_CHAR);
}
return $name;
}
/**
* Converts a database schema name to php object name. Removes
* any character that is not a letter or a number and capitilizes
* first letter of the name, the first letter of each alphanumeric
* block and converts the rest of the letters to lowercase.
*
* T$NAMA$RFO_max => TNamaRfoMax
*
* @param string $schemaName name to be converted.
* @return string Converted name.
* @see NameGenerator
* @see #underscoreMethod()
*/
protected function cleanMethod($schemaName)
{
$name = "";
$regexp = '/([a-z0-9]+)/i';
$matches = array();
if (preg_match_all($regexp, $schemaName, $matches)) {
foreach($matches[1] AS $tok) {
$name .= ucfirst(strtolower($tok));
}
} else {
return $schemaName;
}
return $name;
}
/**
* Converts a database schema name to php object name. Operates
* same as underscoreMethod but does not convert anything to
* lowercase.
*
* my_CLASS_name -> MyCLASSName
*
* @param string $schemaName name to be converted.
* @return string Converted name.
* @see NameGenerator
* @see #underscoreMethod(String)
*/
protected function phpnameMethod($schemaName)
{
$name = "";
$tok = strtok($schemaName, self::STD_SEPARATOR_CHAR);
while ($tok !== false) {
$name .= ucfirst($tok);
$tok = strtok(self::STD_SEPARATOR_CHAR);
}
return $name;
}
/**
* Converts a database schema name to PHP object name. In this
* case no conversion is made.
*
* @param string $name name to be converted.
* @return string The <code>name</code> parameter, unchanged.
*/
protected function nochangeMethod($name)
{
return $name;
}
}

View file

@ -0,0 +1,343 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* A class that maps PropelTypes to PHP native types, PDO types (and Creole types).
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class PropelTypes
{
const CHAR = "CHAR";
const VARCHAR = "VARCHAR";
const LONGVARCHAR = "LONGVARCHAR";
const CLOB = "CLOB";
const CLOB_EMU = "CLOB_EMU";
const NUMERIC = "NUMERIC";
const DECIMAL = "DECIMAL";
const TINYINT = "TINYINT";
const SMALLINT = "SMALLINT";
const INTEGER = "INTEGER";
const BIGINT = "BIGINT";
const REAL = "REAL";
const FLOAT = "FLOAT";
const DOUBLE = "DOUBLE";
const BINARY = "BINARY";
const VARBINARY = "VARBINARY";
const LONGVARBINARY = "LONGVARBINARY";
const BLOB = "BLOB";
const DATE = "DATE";
const TIME = "TIME";
const TIMESTAMP = "TIMESTAMP";
const BU_DATE = "BU_DATE";
const BU_TIMESTAMP = "BU_TIMESTAMP";
const BOOLEAN = "BOOLEAN";
const BOOLEAN_EMU = "BOOLEAN_EMU";
private static $TEXT_TYPES = array(
self::CHAR, self::VARCHAR, self::LONGVARCHAR, self::CLOB, self::DATE, self::TIME, self::TIMESTAMP, self::BU_DATE, self::BU_TIMESTAMP
);
private static $LOB_TYPES = array(
self::VARBINARY, self::LONGVARBINARY, self::BLOB
);
private static $TEMPORAL_TYPES = array(
self::DATE, self::TIME, self::TIMESTAMP, self::BU_DATE, self::BU_TIMESTAMP
);
private static $NUMERIC_TYPES = array(
self::SMALLINT, self::TINYINT, self::INTEGER, self::BIGINT, self::FLOAT, self::DOUBLE, self::NUMERIC, self::DECIMAL, self::REAL
);
private static $BOOLEAN_TYPES = array(
self::BOOLEAN, self::BOOLEAN_EMU
);
const CHAR_NATIVE_TYPE = "string";
const VARCHAR_NATIVE_TYPE = "string";
const LONGVARCHAR_NATIVE_TYPE = "string";
const CLOB_NATIVE_TYPE = "string";
const CLOB_EMU_NATIVE_TYPE = "resource";
const NUMERIC_NATIVE_TYPE = "string";
const DECIMAL_NATIVE_TYPE = "string";
const TINYINT_NATIVE_TYPE = "int";
const SMALLINT_NATIVE_TYPE = "int";
const INTEGER_NATIVE_TYPE = "int";
const BIGINT_NATIVE_TYPE = "string";
const REAL_NATIVE_TYPE = "double";
const FLOAT_NATIVE_TYPE = "double";
const DOUBLE_NATIVE_TYPE = "double";
const BINARY_NATIVE_TYPE = "string";
const VARBINARY_NATIVE_TYPE = "string";
const LONGVARBINARY_NATIVE_TYPE = "string";
const BLOB_NATIVE_TYPE = "resource";
const BU_DATE_NATIVE_TYPE = "string";
const DATE_NATIVE_TYPE = "string";
const TIME_NATIVE_TYPE = "string";
const TIMESTAMP_NATIVE_TYPE = "string";
const BU_TIMESTAMP_NATIVE_TYPE = "string";
const BOOLEAN_NATIVE_TYPE = "boolean";
const BOOLEAN_EMU_NATIVE_TYPE = "boolean";
/**
* Mapping between Propel types and PHP native types.
*
* @var array
*/
private static $propelToPHPNativeMap = array(
self::CHAR => self::CHAR_NATIVE_TYPE,
self::VARCHAR => self::VARCHAR_NATIVE_TYPE,
self::LONGVARCHAR => self::LONGVARCHAR_NATIVE_TYPE,
self::CLOB => self::CLOB_NATIVE_TYPE,
self::CLOB_EMU => self::CLOB_EMU_NATIVE_TYPE,
self::NUMERIC => self::NUMERIC_NATIVE_TYPE,
self::DECIMAL => self::DECIMAL_NATIVE_TYPE,
self::TINYINT => self::TINYINT_NATIVE_TYPE,
self::SMALLINT => self::SMALLINT_NATIVE_TYPE,
self::INTEGER => self::INTEGER_NATIVE_TYPE,
self::BIGINT => self::BIGINT_NATIVE_TYPE,
self::REAL => self::REAL_NATIVE_TYPE,
self::FLOAT => self::FLOAT_NATIVE_TYPE,
self::DOUBLE => self::DOUBLE_NATIVE_TYPE,
self::BINARY => self::BINARY_NATIVE_TYPE,
self::VARBINARY => self::VARBINARY_NATIVE_TYPE,
self::LONGVARBINARY => self::LONGVARBINARY_NATIVE_TYPE,
self::BLOB => self::BLOB_NATIVE_TYPE,
self::DATE => self::DATE_NATIVE_TYPE,
self::BU_DATE => self::BU_DATE_NATIVE_TYPE,
self::TIME => self::TIME_NATIVE_TYPE,
self::TIMESTAMP => self::TIMESTAMP_NATIVE_TYPE,
self::BU_TIMESTAMP => self::BU_TIMESTAMP_NATIVE_TYPE,
self::BOOLEAN => self::BOOLEAN_NATIVE_TYPE,
self::BOOLEAN_EMU => self::BOOLEAN_EMU_NATIVE_TYPE,
);
/**
* Mapping between Propel types and Creole types (for rev-eng task)
*
* @var array
*/
private static $propelTypeToCreoleTypeMap = array(
self::CHAR => self::CHAR,
self::VARCHAR => self::VARCHAR,
self::LONGVARCHAR => self::LONGVARCHAR,
self::CLOB => self::CLOB,
self::NUMERIC => self::NUMERIC,
self::DECIMAL => self::DECIMAL,
self::TINYINT => self::TINYINT,
self::SMALLINT => self::SMALLINT,
self::INTEGER => self::INTEGER,
self::BIGINT => self::BIGINT,
self::REAL => self::REAL,
self::FLOAT => self::FLOAT,
self::DOUBLE => self::DOUBLE,
self::BINARY => self::BINARY,
self::VARBINARY => self::VARBINARY,
self::LONGVARBINARY => self::LONGVARBINARY,
self::BLOB => self::BLOB,
self::DATE => self::DATE,
self::TIME => self::TIME,
self::TIMESTAMP => self::TIMESTAMP,
self::BOOLEAN => self::BOOLEAN,
self::BOOLEAN_EMU => self::BOOLEAN_EMU,
// These are pre-epoch dates, which we need to map to String type
// since they cannot be properly handled using strtotime() -- or even numeric
// timestamps on Windows.
self::BU_DATE => self::VARCHAR,
self::BU_TIMESTAMP => self::VARCHAR,
);
/**
* Mapping between Propel types and PDO type contants (for prepared statement setting).
*
* @var array
*/
private static $propelTypeToPDOTypeMap = array(
self::CHAR => PDO::PARAM_STR,
self::VARCHAR => PDO::PARAM_STR,
self::LONGVARCHAR => PDO::PARAM_STR,
self::CLOB => PDO::PARAM_STR,
self::CLOB_EMU => PDO::PARAM_STR,
self::NUMERIC => PDO::PARAM_INT,
self::DECIMAL => PDO::PARAM_STR,
self::TINYINT => PDO::PARAM_INT,
self::SMALLINT => PDO::PARAM_INT,
self::INTEGER => PDO::PARAM_INT,
self::BIGINT => PDO::PARAM_INT,
self::REAL => PDO::PARAM_STR,
self::FLOAT => PDO::PARAM_STR,
self::DOUBLE => PDO::PARAM_STR,
self::BINARY => PDO::PARAM_STR,
self::VARBINARY => PDO::PARAM_LOB,
self::LONGVARBINARY => PDO::PARAM_LOB,
self::BLOB => PDO::PARAM_LOB,
self::DATE => PDO::PARAM_STR,
self::TIME => PDO::PARAM_STR,
self::TIMESTAMP => PDO::PARAM_STR,
self::BOOLEAN => PDO::PARAM_BOOL,
self::BOOLEAN_EMU => PDO::PARAM_INT,
// These are pre-epoch dates, which we need to map to String type
// since they cannot be properly handled using strtotime() -- or even numeric
// timestamps on Windows.
self::BU_DATE => PDO::PARAM_STR,
self::BU_TIMESTAMP => PDO::PARAM_STR,
);
/**
* Return native PHP type which corresponds to the
* Creole type provided. Use in the base object class generation.
*
* @param $propelType The Propel type name.
* @return string Name of the native PHP type
*/
public static function getPhpNative($propelType)
{
return self::$propelToPHPNativeMap[$propelType];
}
/**
* Returns the correct Creole type _name_ for propel added types
*
* @param $type the propel added type.
* @return string Name of the the correct Creole type (e.g. "VARCHAR").
*/
public static function getCreoleType($type)
{
return self::$propelTypeToCreoleTypeMap[$type];
}
/**
* Resturns the PDO type (PDO::PARAM_* constant) value.
* @return int
*/
public static function getPDOType($type)
{
return self::$propelTypeToPDOTypeMap[$type];
}
/**
* Returns Propel type constant corresponding to Creole type code.
* Used but Propel Creole task.
*
* @param int $sqlType The Creole SQL type constant.
* @return string The Propel type to use or NULL if none found.
*/
public static function getPropelType($sqlType)
{
if (isset(self::$creoleToPropelTypeMap[$sqlType])) {
return self::$creoleToPropelTypeMap[$sqlType];
}
}
/**
* Get array of Propel types.
*
* @return array string[]
*/
public static function getPropelTypes()
{
return array_keys(self::$propelTypeToCreoleTypeMap);
}
/**
* Whether passed type is a temporal (date/time/timestamp) type.
*
* @param string $type Propel type
* @return boolean
*/
public static function isTemporalType($type)
{
return in_array($type, self::$TEMPORAL_TYPES);
}
/**
* Returns true if values for the type need to be quoted.
*
* @param string $type The Propel type to check.
* @return boolean True if values for the type need to be quoted.
*/
public static function isTextType($type)
{
return in_array($type, self::$TEXT_TYPES);
}
/**
* Returns true if values for the type are numeric.
*
* @param string $type The Propel type to check.
* @return boolean True if values for the type need to be quoted.
*/
public static function isNumericType($type)
{
return in_array($type, self::$NUMERIC_TYPES);
}
/**
* Returns true if values for the type are boolean.
*
* @param string $type The Propel type to check.
* @return boolean True if values for the type need to be quoted.
*/
public static function isBooleanType($type)
{
return in_array($type, self::$BOOLEAN_TYPES);
}
/**
* Returns true if type is a LOB type (i.e. would be handled by Blob/Clob class).
* @param string $type Propel type to check.
* @return boolean
*/
public static function isLobType($type)
{
return in_array($type, self::$LOB_TYPES);
}
/**
* Convenience method to indicate whether a passed-in PHP type is a primitive.
*
* @param string $phpType The PHP type to check
* @return boolean Whether the PHP type is a primitive (string, int, boolean, float)
*/
public static function isPhpPrimitiveType($phpType)
{
return in_array($phpType, array("boolean", "int", "double", "float", "string"));
}
/**
* Convenience method to indicate whether a passed-in PHP type is a numeric primitive.
*
* @param string $phpType The PHP type to check
* @return boolean Whether the PHP type is a primitive (string, int, boolean, float)
*/
public static function isPhpPrimitiveNumericType($phpType)
{
return in_array($phpType, array("boolean", "int", "double", "float"));
}
/**
* Convenience method to indicate whether a passed-in PHP type is an object.
*
* @param string $phpType The PHP type to check
* @return boolean Whether the PHP type is a primitive (string, int, boolean, float)
*/
public static function isPhpObjectType($phpType)
{
return (!self::isPhpPrimitiveType($phpType) && !in_array($phpType, array("resource", "array")));
}
}

View file

@ -0,0 +1,194 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/XMLElement.php';
/**
* Data about a validation rule used in an application.
*
* @author Michael Aichler <aichler@mediacluster.de> (Propel)
* @author John McNally <jmcnally@collab.net> (Intake)
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class Rule extends XMLElement
{
private $name;
private $value;
private $message;
private $validator;
private $classname;
/**
* Sets up the Rule object based on the attributes that were passed to loadFromXML().
* @see parent::loadFromXML()
*/
protected function setupObject()
{
$this->name = $this->getAttribute("name");
$this->value = $this->getAttribute("value");
$this->classname = $this->getAttribute("class");
/*
* Set some default values if they are not specified.
* This is escpecially useful for maxLength; the size
* is already known by the column and this way it is
* not necessary to manage the same size two times.
*
* Currently there is only one such supported default:
* - maxLength value = column max length
* (this default cannot be easily set at runtime w/o changing
* design of class system in undesired ways)
*/
if ($this->value === null) {
switch($this->name) {
case 'maxLength':
$this->value = $this->validator->getColumn()->getSize();
break;
}
}
$this->message = $this->getAttribute("message");
}
/**
* Sets the owning validator for this rule.
* @param Validator $validator
* @see Validator::addRule()
*/
public function setValidator(Validator $validator)
{
$this->validator = $validator;
}
/**
* Gets the owning validator for this rule.
* @return Validator
*/
public function getValidator()
{
return $this->validator;
}
/**
* Sets the dot-path name of class to use for rule.
* If no class is specified in XML, then a classname will
* be built based on the 'name' attrib.
* @param string $classname dot-path classname (e.g. myapp.propel.MyValidator)
*/
public function setClass($classname)
{
$this->classname = $classname;
}
/**
* Gets the dot-path name of class to use for rule.
* If no class was specified, this method will build a default classname
* based on the 'name' attribute. E.g. 'maxLength' -> 'propel.validator.MaxLengthValidator'
* @return string dot-path classname (e.g. myapp.propel.MyValidator)
*/
public function getClass()
{
if ($this->classname === null && $this->name !== null) {
return "propel.validator." . ucfirst($this->name) . "Validator";
}
return $this->classname;
}
/**
* Sets the name of the validator for this rule.
* This name is used to build the classname if none was specified.
* @param string $name Validator name for this rule (e.g. "maxLength", "required").
* @see getClass()
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Gets the name of the validator for this rule.
* @return string Validator name for this rule (e.g. "maxLength", "required").
*/
public function getName()
{
return $this->name;
}
/**
* Sets the value parameter for this validator rule.
* Note: not all validators need a value parameter (e.g. 'required' validator
* does not).
* @param string $value
*/
public function setValue($value)
{
$this->value = $value;
}
/**
* Gets the value parameter for this validator rule.
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* Sets the message that will be displayed to the user if validation fails.
* This message may be a Gettext msgid (if translation="gettext") or some other
* id for an alternative not-yet-supported translation system. It may also
* be a simple, single-language string.
* @param string $message
* @see setTranslation()
*/
public function setMessage($message)
{
$this->message = $message;
}
/**
* Gets the message that will be displayed to the user if validation fails.
* This message may be a Gettext msgid (if translation="gettext") or some other
* id for an alternative not-yet-supported translation system. It may also
* be a simple, single-language string.
* @return string
* @see setTranslation()
*/
public function getMessage()
{
$message = str_replace('${value}', $this->getValue(), $this->message);
return $message;
}
/**
* @see XMLElement::appendXml(DOMNode)
*/
public function appendXml(DOMNode $node)
{
$doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
$ruleNode = $node->appendChild($doc->createElement('rule'));
$ruleNode->setAttribute('name', $this->getName());
if ($this->getValue() !== null) {
$ruleNode->setAttribute('value', $this->getValue());
}
if ($this->classname !== null) {
$ruleNode->setAttribute('class', $this->getClass());
}
$ruleNode->setAttribute('message', $this->getMessage());
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,58 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/Index.php';
/**
* Information about unique columns of a table. This class assumes
* that in the underlying RDBMS, unique constraints and unique indices
* are roughly equivalent. For example, adding a unique constraint to
* a column also creates an index on that column (this is known to be
* true for MySQL and Oracle).
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Jason van Zyl <jvanzyl@apache.org> (Torque)
* @author Daniel Rall <dlr@collab.net> (Torque)
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class Unique extends Index
{
/**
* Returns <code>true</code>.
*/
public function isUnique()
{
return true;
}
/**
* @see XMLElement::appendXml(DOMNode)
*/
public function appendXml(DOMNode $node)
{
$doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
$uniqueNode = $node->appendChild($doc->createElement('unique'));
$uniqueNode->setAttribute('name', $this->getName());
$columns = $this->getColumns();
foreach ($this->getColumns() as $colname) {
$uniqueColNode = $uniqueNode->appendChild($doc->createElement('unique-column'));
$uniqueColNode->setAttribute('name', $colname);
}
foreach ($this->vendorInfos as $vi) {
$vi->appendXml($uniqueNode);
}
}
}

View file

@ -0,0 +1,184 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/XMLElement.php';
require_once 'exception/EngineException.php';
require_once 'model/PropelTypes.php';
require_once 'model/Rule.php';
/**
* Validator.
*
* @author Michael Aichler <aichler@mediacluster.de> (Propel)
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class Validator extends XMLElement
{
const TRANSLATE_NONE = "none";
const TRANSLATE_GETTEXT = "gettext";
/**
* The column this validator applies to.
*
* @var Column
*/
private $column;
/**
* The rules for the validation.
*
* @var array Rule[]
*/
private $ruleList = array();
/**
* The translation mode.
*
* @var string
*/
private $translate;
/**
* Parent table.
*
* @var Table
*/
private $table;
/**
* Sets up the Validator object based on the attributes that were passed to loadFromXML().
* @see parent::loadFromXML()
*/
protected function setupObject()
{
$this->column = $this->getTable()->getColumn($this->getAttribute("column"));
$this->translate = $this->getAttribute("translate", $this->getTable()->getDatabase()->getDefaultTranslateMethod());;
}
/**
* Add a Rule to this validator.
* Supports two signatures:
* - addRule(Rule $rule)
* - addRule(array $attribs)
* @param mixed $data Rule object or XML attribs (array) from <rule/> element.
* @return Rule The added Rule.
*/
public function addRule($data)
{
if ($data instanceof Rule) {
$rule = $data; // alias
$rule->setValidator($this);
$this->ruleList[] = $rule;
return $rule;
}
else {
$rule = new Rule();
$rule->setValidator($this);
$rule->loadFromXML($data);
return $this->addRule($rule); // call self w/ different param
}
}
/**
* Gets an array of all added rules for this validator.
* @return array Rule[]
*/
public function getRules()
{
return $this->ruleList;
}
/**
* Gets the name of the column that this Validator applies to.
* @return string
*/
public function getColumnName()
{
return $this->column->getName();
}
/**
* Sets the Column object that this validator applies to.
* @param Column $column
* @see Table::addValidator()
*/
public function setColumn(Column $column)
{
$this->column = $column;
}
/**
* Gets the Column object that this validator applies to.
* @return Column
*/
public function getColumn()
{
return $this->column;
}
/**
* Set the owning Table.
* @param Table $table
*/
public function setTable(Table $table)
{
$this->table = $table;
}
/**
* Get the owning Table.
* @return Table
*/
public function getTable()
{
return $this->table;
}
/**
* Set the translation mode to use for the message.
* Currently only "gettext" and "none" are supported. The default is "none".
* @param string $method Translation method ("gettext", "none").
*/
public function setTranslate($method)
{
$this->translate = $method;
}
/**
* Get the translation mode to use for the message.
* Currently only "gettext" and "none" are supported. The default is "none".
* @return string Translation method ("gettext", "none").
*/
public function getTranslate()
{
return $this->translate;
}
/**
* @see XMLElement::appendXml(DOMNode)
*/
public function appendXml(DOMNode $node)
{
$doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
$valNode = $node->appendChild($doc->createElement('validator'));
$valNode->setAttribute('column', $this->getColumnName());
if ($this->translate !== null) {
$valNode->setAttribute('translate', $this->translate);
}
foreach ($this->ruleList as $rule) {
$rule->appendXml($valNode);
}
}
}

View file

@ -0,0 +1,172 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/XMLElement.php';
require_once 'exception/EngineException.php';
/**
* Object to hold vendor-specific info.
*
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 1612 $
* @package propel.generator.model
*/
class VendorInfo extends XMLElement
{
/**
* The vendor RDBMS type.
*
* @var string
*/
private $type;
/**
* Vendor parameters.
*
* @var array
*/
private $parameters = array();
/**
* Creates a new VendorInfo instance.
*
* @param string $type RDBMS type (optional)
*/
public function __construct($type = null)
{
$this->type = $type;
}
/**
* Sets up this object based on the attributes that were passed to loadFromXML().
* @see parent::loadFromXML()
*/
protected function setupObject()
{
$this->type = $this->getAttribute("type");
}
/**
* Set RDBMS type for this vendor-specific info.
*
* @param string $v
*/
public function setType($v)
{
$this->type = $v;
}
/**
* Get RDBMS type for this vendor-specific info.
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Adds a new vendor parameter to this object.
* @param array $attrib Attributes from XML.
*/
public function addParameter($attrib)
{
$name = $attrib["name"];
$this->parameters[$name] = $attrib["value"];
}
/**
* Sets parameter value.
*
* @param string $name
* @param mixed $value The value for the parameter.
*/
public function setParameter($name, $value)
{
$this->parameters[$name] = $value;
}
/**
* Gets parameter value.
*
* @param string $name
* @return mixed Paramter value.
*/
public function getParameter($name)
{
if (isset($this->parameters[$name])) {
return $this->parameters[$name];
}
return null; // just to be explicit
}
/**
* Whether parameter exists.
*
* @param string $name
*/
public function hasParameter($name)
{
return isset($this->parameters[$name]);
}
/**
* Sets assoc array of parameters for venfor specific info.
*
* @param array $params Paramter data.
*/
public function setParameters(array $params = array())
{
$this->parameters = $params;
}
/**
* Gets assoc array of parameters for venfor specific info.
*
* @return array
*/
public function getParameters()
{
return $this->parameters;
}
/**
* Gets a new merged VendorInfo object.
* @param VendorInfo $info
* @return VendorInfo new object with merged parameters
*/
public function getMergedVendorInfo(VendorInfo $merge)
{
$newParams = array_merge($this->getParameters(), $merge->getParameters());
$newInfo = new VendorInfo($this->getType());
$newInfo->setParameters($newParams);
return $newInfo;
}
/**
* @see XMLElement::appendXml(DOMNode)
*/
public function appendXml(DOMNode $node)
{
$doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
$vendorNode = $node->appendChild($doc->createElement("vendor"));
$vendorNode->setAttribute("type", $this->getType());
foreach ($this->parameters as $key => $value) {
$parameterNode = $doc->createElement("parameter");
$parameterNode->setAttribute("name", $key);
$parameterNode->setAttribute("value", $value);
$vendorNode->appendChild($parameterNode);
}
}
}

View file

@ -0,0 +1,182 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'model/VendorInfo.php';
/**
* An abstract class for elements represented by XML tags (e.g. Column, Table).
*
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 1612 $
* @package propel.generator.model
*/
abstract class XMLElement
{
/**
* The name => value attributes from XML.
*
* @var array
*/
protected $attributes = array();
/**
* Any associated vendor-specific information objects.
*
* @var array VendorInfo[]
*/
protected $vendorInfos = array();
/**
* Replaces the old loadFromXML() so that we can use loadFromXML() to load the attribs into the class.
*/
abstract protected function setupObject();
/**
* This is the entry point method for loading data from XML.
* It calls a setupObject() method that must be implemented by the child class.
* @param array $attributes The attributes for the XML tag.
*/
public function loadFromXML($attributes)
{
$this->attributes = array_change_key_case($attributes, CASE_LOWER);
$this->setupObject();
}
/**
* Returns the assoc array of attributes.
* All attribute names (keys) are lowercase.
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* Gets a particular attribute by [case-insensitive] name.
* If attribute is not set then the $defaultValue is returned.
* @param string $name The [case-insensitive] name of the attribute to lookup.
* @param mixed $defaultValue The default value to use in case the attribute is not set.
* @return mixed The value of the attribute or $defaultValue if not set.
*/
public function getAttribute($name, $defaultValue = null)
{
$name = strtolower($name);
if (isset($this->attributes[$name])) {
return $this->attributes[$name];
} else {
return $defaultValue;
}
}
/**
* Converts value specified in XML to a boolean value.
* This is to support the default value when used w/ a boolean column.
* @return value
*/
protected function booleanValue($val)
{
if (is_numeric($val)) {
return (bool) $val;
} else {
return (in_array(strtolower($val), array('true', 't', 'y', 'yes'), true) ? true : false);
}
}
/**
* Appends DOM elements to represent this object in XML.
* @param DOMNode $node
*/
abstract public function appendXml(DOMNode $node);
/**
* Sets an associated VendorInfo object.
*
* @param mixed $data VendorInfo object or XML attrib data (array)
* @return VendorInfo
*/
public function addVendorInfo($data)
{
if ($data instanceof VendorInfo) {
$vi = $data;
$this->vendorInfos[$vi->getType()] = $vi;
return $vi;
} else {
$vi = new VendorInfo();
$vi->loadFromXML($data);
return $this->addVendorInfo($vi); // call self w/ different param
}
}
/**
* Gets the any associated VendorInfo object.
* @return VendorInfo
*/
public function getVendorInfoForType($type)
{
if (isset($this->vendorInfos[$type])) {
return $this->vendorInfos[$type];
} else {
// return an empty object
return new VendorInfo();
}
}
/**
* Find the best class name for a given behavior
* Looks in build.properties for path like propel.behavior.[bname].class
* If not found, tries to autoload [Bname]Behavior
* If no success, returns 'Behavior'
*
* @param string $bname behavior name, e.g. 'timestampable'
* @return string behavior class name, e.g. 'TimestampableBehavior'
*/
public function getConfiguredBehavior($bname)
{
if ($config = $this->getGeneratorConfig()) {
if ($class = $config->getConfiguredBehavior($bname)) {
return $class;
}
}
// first fallback: maybe the behavior is loaded or autoloaded
$gen = new PhpNameGenerator();
if(class_exists($class = $gen->generateName($bname, PhpNameGenerator::CONV_METHOD_PHPNAME) . 'Behavior')) {
return $class;
}
// second fallback: use parent behavior class (mostly for unit tests)
return 'Behavior';
}
/**
* String representation of the current object.
*
* This is an xml representation with the XML declaration removed.
*
* @see appendXml()
*/
public function toString()
{
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$this->appendXml($doc);
$xmlstr = $doc->saveXML();
return trim(preg_replace('/<\?xml.*?\?>/', '', $xmlstr));
}
/**
* Magic string method
* @see toString()
*/
public function __toString()
{
return $this->toString();
}
}