initial commit

This commit is contained in:
Chris Sewell
2012-11-28 03:55:08 -05:00
parent 7adb399b2e
commit cf140a2e97
3247 changed files with 492437 additions and 0 deletions

View File

@ -0,0 +1,61 @@
<?php
require_once 'propel/engine/builder/om/php5/PHP5ExtensionObjectBuilder.php';
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @package symfony
* @subpackage addon
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: SfExtensionObjectBuilder.php 2624 2006-11-07 09:34:59Z fabien $
*/
class SfExtensionObjectBuilder extends PHP5ExtensionObjectBuilder
{
protected function addIncludes(&$script)
{
if (!DataModelBuilder::getBuildProperty('builderAddIncludes'))
{
return;
}
parent::addIncludes($script);
}
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$baseClassname = $this->getObjectBuilder()->getClassname();
$script .= "
/**
* Subclass for representing a row from the '$tableName' table.
*
* $tableDesc
*
* @package ".$this->getPackage()."
*/
class ".$this->getClassname()." extends $baseClassname
{";
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
}
";
}
}

View File

@ -0,0 +1,65 @@
<?php
require_once 'propel/engine/builder/om/php5/PHP5ExtensionPeerBuilder.php';
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @package symfony
* @subpackage addon
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: SfExtensionPeerBuilder.php 2624 2006-11-07 09:34:59Z fabien $
*/
class SfExtensionPeerBuilder extends PHP5ExtensionPeerBuilder
{
protected function addIncludes(&$script)
{
if (!DataModelBuilder::getBuildProperty('builderAddIncludes'))
{
return;
}
parent::addIncludes($script);
}
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$baseClassname = $this->getPeerBuilder()->getClassname();
$script .= "
/**
* Subclass for performing query and update operations on the '$tableName' table.
*
* $tableDesc
*
* @package ".$this->getPackage()."
*/
class ".$this->getClassname()." extends $baseClassname
{";
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
}
";
}
}

View File

@ -0,0 +1,53 @@
<?php
require_once 'propel/engine/builder/om/php5/PHP5MapBuilderBuilder.php';
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @package symfony
* @subpackage addon
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: SfMapBuilderBuilder.php 3058 2006-12-16 17:17:26Z fabien $
*/
class SfMapBuilderBuilder extends PHP5MapBuilderBuilder
{
public function build()
{
if (!DataModelBuilder::getBuildProperty('builderAddComments'))
{
return sfToolkit::stripComments(parent::build());
}
return parent::build();
}
protected function addIncludes(&$script)
{
if (!DataModelBuilder::getBuildProperty('builderAddIncludes'))
{
return;
}
parent::addIncludes($script);
}
protected function addDoBuild(&$script)
{
parent::addDoBuild($script);
// fix http://propel.phpdb.org/trac/ticket/235: Column sizes not being inserted into [table]MapBuilder->DoBuild() by PHP5MapBuilderBuilder
$sizes = array();
foreach ($this->getTable()->getColumns() as $col)
{
$sizes[$col->getPhpName()] = !$col->getSize() ? 'null' : $col->getSize();
}
$script = preg_replace("/\\\$tMap\->addColumn\('([^']+)', '([^']+)', '([^']+)', CreoleTypes\:\:VARCHAR, (false|true)\)/e", '"\\\$tMap->addColumn(\'$1\', \'$2\', \'$3\', CreoleTypes::VARCHAR, $4, {$sizes[\'$2\']})"', $script);
}
}

View File

@ -0,0 +1,30 @@
<?php
require_once 'propel/engine/builder/om/php5/PHP5MultiExtendObjectBuilder.php';
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @package symfony
* @subpackage addon
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: SfMultiExtendObjectBuilder.php 1919 2006-09-01 14:41:22Z fabien $
*/
class SfMultiExtendObjectBuilder extends PHP5MultiExtendObjectBuilder
{
protected function addIncludes(&$script)
{
if (!DataModelBuilder::getBuildProperty('builderAddIncludes'))
{
return;
}
parent::addIncludes($script);
}
}

View File

@ -0,0 +1,341 @@
<?php
require_once 'propel/engine/builder/om/php5/PHP5ComplexObjectBuilder.php';
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @package symfony
* @subpackage addon
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: SfObjectBuilder.php 3493 2007-02-18 09:23:10Z fabien $
*/
class SfObjectBuilder extends PHP5ComplexObjectBuilder
{
public function build()
{
if (!DataModelBuilder::getBuildProperty('builderAddComments'))
{
return sfToolkit::stripComments(parent::build());
}
return parent::build();
}
protected function addIncludes(&$script)
{
if (!DataModelBuilder::getBuildProperty('builderAddIncludes'))
{
return;
}
parent::addIncludes($script);
// include the i18n classes if needed
if ($this->getTable()->getAttribute('isI18N'))
{
$relatedTable = $this->getDatabase()->getTable($this->getTable()->getAttribute('i18nTable'));
$script .= '
require_once \''.$this->getFilePath($this->getStubObjectBuilder()->getPackage().'.'.$relatedTable->getPhpName().'Peer').'\';
require_once \''.$this->getFilePath($this->getStubObjectBuilder()->getPackage().'.'.$relatedTable->getPhpName()).'\';
';
}
}
protected function addClassBody(&$script)
{
parent::addClassBody($script);
if ($this->getTable()->getAttribute('isI18N'))
{
if (count($this->getTable()->getPrimaryKey()) > 1)
{
throw new Exception('i18n support only works with a single primary key');
}
$this->addCultureAccessorMethod($script);
$this->addCultureMutatorMethod($script);
$this->addI18nMethods($script);
}
if (DataModelBuilder::getBuildProperty('builderAddBehaviors'))
{
$this->addCall($script);
}
}
protected function addCall(&$script)
{
$script .= "
public function __call(\$method, \$arguments)
{
if (!\$callable = sfMixer::getCallable('{$this->getClassname()}:'.\$method))
{
throw new sfException(sprintf('Call to undefined method {$this->getClassname()}::%s', \$method));
}
array_unshift(\$arguments, \$this);
return call_user_func_array(\$callable, \$arguments);
}
";
}
protected function addAttributes(&$script)
{
parent::addAttributes($script);
if ($this->getTable()->getAttribute('isI18N'))
{
$script .= '
/**
* The value for the culture field.
* @var string
*/
protected $culture;
';
}
}
protected function addCultureAccessorMethod(&$script)
{
$script .= '
public function getCulture()
{
return $this->culture;
}
';
}
protected function addCultureMutatorMethod(&$script)
{
$script .= '
public function setCulture($culture)
{
$this->culture = $culture;
}
';
}
protected function addI18nMethods(&$script)
{
$table = $this->getTable();
$pks = $table->getPrimaryKey();
$pk = $pks[0]->getPhpName();
foreach ($table->getReferrers() as $fk)
{
$tblFK = $fk->getTable();
if ($tblFK->getName() == $table->getAttribute('i18nTable'))
{
$className = $tblFK->getPhpName();
$culture = '';
$culture_peername = '';
foreach ($tblFK->getColumns() as $col)
{
if (("true" === strtolower($col->getAttribute('isCulture'))))
{
$culture = $col->getPhpName();
$culture_peername = PeerBuilder::getColumnName($col, $className);
}
}
foreach ($tblFK->getColumns() as $col)
{
if ($col->isPrimaryKey()) continue;
$script .= '
public function get'.$col->getPhpName().'()
{
$obj = $this->getCurrent'.$className.'();
return ($obj ? $obj->get'.$col->getPhpName().'() : null);
}
public function set'.$col->getPhpName().'($value)
{
$this->getCurrent'.$className.'()->set'.$col->getPhpName().'($value);
}
';
}
$script .= '
protected $current_i18n = array();
public function getCurrent'.$className.'()
{
if (!isset($this->current_i18n[$this->culture]))
{
$obj = '.$className.'Peer::retrieveByPK($this->get'.$pk.'(), $this->culture);
if ($obj)
{
$this->set'.$className.'ForCulture($obj, $this->culture);
}
else
{
$this->set'.$className.'ForCulture(new '.$className.'(), $this->culture);
$this->current_i18n[$this->culture]->set'.$culture.'($this->culture);
}
}
return $this->current_i18n[$this->culture];
}
public function set'.$className.'ForCulture($object, $culture)
{
$this->current_i18n[$culture] = $object;
$this->add'.$className.'($object);
}
';
}
}
}
protected function addDoSave(&$script)
{
$tmp = '';
parent::addDoSave($tmp);
// add autosave to i18n object even if the base object is not changed
$tmp = preg_replace_callback('#(\$this\->(.+?)\->isModified\(\))#', array($this, 'i18nDoSaveCallback'), $tmp);
$script .= $tmp;
}
private function i18nDoSaveCallback($matches)
{
$value = $matches[1];
// get the related class to see if it is a i18n one
$table = $this->getTable();
$column = null;
foreach ($table->getForeignKeys() as $fk)
{
if ($matches[2] == $this->getFKVarName($fk))
{
$column = $fk;
break;
}
}
$foreign_table = $this->getDatabase()->getTable($fk->getForeignTableName());
if ($foreign_table->getAttribute('isI18N'))
{
$foreign_tables_i18n_table = $this->getDatabase()->getTable($foreign_table->getAttribute('i18nTable'));
$value .= ' || $this->'.$matches[2].'->getCurrent'.$foreign_tables_i18n_table->getPhpName().'()->isModified()';
}
return $value;
}
protected function addDelete(&$script)
{
$tmp = '';
parent::addDelete($tmp);
if (DataModelBuilder::getBuildProperty('builderAddBehaviors'))
{
// add sfMixer call
$pre_mixer_script = "
foreach (sfMixer::getCallables('{$this->getClassname()}:delete:pre') as \$callable)
{
\$ret = call_user_func(\$callable, \$this, \$con);
if (\$ret)
{
return;
}
}
";
$post_mixer_script = "
foreach (sfMixer::getCallables('{$this->getClassname()}:delete:post') as \$callable)
{
call_user_func(\$callable, \$this, \$con);
}
";
$tmp = preg_replace('/{/', '{'.$pre_mixer_script, $tmp, 1);
$tmp = preg_replace('/}\s*$/', $post_mixer_script.' }', $tmp);
}
// update current script
$script .= $tmp;
}
protected function addSave(&$script)
{
$tmp = '';
parent::addSave($tmp);
// add support for created_(at|on) and updated_(at|on) columns
$date_script = '';
$updated = false;
$created = false;
foreach ($this->getTable()->getColumns() as $col)
{
$clo = strtolower($col->getName());
if (!$updated && in_array($clo, array('updated_at', 'updated_on')))
{
$updated = true;
$date_script .= "
if (\$this->isModified() && !\$this->isColumnModified(".$this->getColumnConstant($col)."))
{
\$this->set".$col->getPhpName()."(time());
}
";
}
else if (!$created && in_array($clo, array('created_at', 'created_on')))
{
$created = true;
$date_script .= "
if (\$this->isNew() && !\$this->isColumnModified(".$this->getColumnConstant($col)."))
{
\$this->set".$col->getPhpName()."(time());
}
";
}
}
$tmp = preg_replace('/{/', '{'.$date_script, $tmp, 1);
if (DataModelBuilder::getBuildProperty('builderAddBehaviors'))
{
// add sfMixer call
$pre_mixer_script = "
foreach (sfMixer::getCallables('{$this->getClassname()}:save:pre') as \$callable)
{
\$affectedRows = call_user_func(\$callable, \$this, \$con);
if (is_int(\$affectedRows))
{
return \$affectedRows;
}
}
";
$post_mixer_script = <<<EOF
foreach (sfMixer::getCallables('{$this->getClassname()}:save:post') as \$callable)
{
call_user_func(\$callable, \$this, \$con, \$affectedRows);
}
EOF;
$tmp = preg_replace('/{/', '{'.$pre_mixer_script, $tmp, 1);
$tmp = preg_replace('/(\$con\->commit\(\);)/', '$1'.$post_mixer_script, $tmp);
}
// update current script
$script .= $tmp;
}
}

View File

@ -0,0 +1,274 @@
<?php
require_once 'propel/engine/builder/om/php5/PHP5ComplexPeerBuilder.php';
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @package symfony
* @subpackage addon
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: SfPeerBuilder.php 2534 2006-10-26 17:13:50Z fabien $
*/
class SfPeerBuilder extends PHP5ComplexPeerBuilder
{
public function build()
{
if (!DataModelBuilder::getBuildProperty('builderAddComments'))
{
return sfToolkit::stripComments(parent::build());
}
return parent::build();
}
protected function addIncludes(&$script)
{
if (!DataModelBuilder::getBuildProperty('builderAddIncludes'))
{
return;
}
parent::addIncludes($script);
}
protected function addSelectMethods(&$script)
{
parent::addSelectMethods($script);
if ($this->getTable()->getAttribute('isI18N'))
{
$this->addDoSelectWithI18n($script);
}
}
protected function addDoSelectWithI18n(&$script)
{
$table = $this->getTable();
$thisTableObjectBuilder = OMBuilder::getNewObjectBuilder($table);
$className = $table->getPhpName();
$pks = $table->getPrimaryKey();
$pk = PeerBuilder::getColumnName($pks[0], $className);
// get i18n table name and culture column name
foreach ($table->getReferrers() as $fk)
{
$tblFK = $fk->getTable();
if ($tblFK->getName() == $table->getAttribute('i18nTable'))
{
$i18nClassName = $tblFK->getPhpName();
// FIXME
$i18nPeerClassName = $i18nClassName.'Peer';
$i18nTable = $table->getDatabase()->getTable($tblFK->getName());
$i18nTableObjectBuilder = OMBuilder::getNewObjectBuilder($i18nTable);
$i18nTablePeerBuilder = OMBuilder::getNewPeerBuilder($i18nTable);
$i18nPks = $i18nTable->getPrimaryKey();
$i18nPk = PeerBuilder::getColumnName($i18nPks[0], $i18nClassName);
$culturePhpName = '';
$cultureColumnName = '';
foreach ($tblFK->getColumns() as $col)
{
if (("true" === strtolower($col->getAttribute('isCulture'))))
{
$culturePhpName = $col->getPhpName();
$cultureColumnName = PeerBuilder::getColumnName($col, $i18nClassName);
}
}
}
}
$script .= "
/**
* Selects a collection of $className objects pre-filled with their i18n objects.
*
* @return array Array of $className objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectWithI18n(Criteria \$c, \$culture = null, \$con = null)
{
if (\$culture === null)
{
\$culture = sfContext::getInstance()->getUser()->getCulture();
}
// Set the correct dbName if it has not been overridden
if (\$c->getDbName() == Propel::getDefaultDB())
{
\$c->setDbName(self::DATABASE_NAME);
}
".$this->getPeerClassname()."::addSelectColumns(\$c);
\$startcol = (".$this->getPeerClassname()."::NUM_COLUMNS - ".$this->getPeerClassname()."::NUM_LAZY_LOAD_COLUMNS) + 1;
".$i18nPeerClassName."::addSelectColumns(\$c);
\$c->addJoin(".$pk.", ".$i18nPk.");
\$c->add(".$cultureColumnName.", \$culture);
\$rs = ".$this->basePeerClassname."::doSelect(\$c, \$con);
\$results = array();
while(\$rs->next()) {
";
if ($table->getChildrenColumn()) {
$script .= "
\$omClass = ".$this->getPeerClassname()."::getOMClass(\$rs, 1);
";
} else {
$script .= "
\$omClass = ".$this->getPeerClassname()."::getOMClass();
";
}
$script .= "
\$cls = Propel::import(\$omClass);
\$obj1 = new \$cls();
\$obj1->hydrate(\$rs);
\$obj1->setCulture(\$culture);
";
// if ($i18nTable->getChildrenColumn()) {
$script .= "
\$omClass = ".$i18nTablePeerBuilder->getPeerClassname()."::getOMClass(\$rs, \$startcol);
";
// } else {
// $script .= "
// \$omClass = ".$i18nTablePeerBuilder->getPeerClassname()."::getOMClass();
//";
// }
$script .= "
\$cls = Propel::import(\$omClass);
\$obj2 = new \$cls();
\$obj2->hydrate(\$rs, \$startcol);
\$obj1->set".$i18nClassName."ForCulture(\$obj2, \$culture);
\$obj2->set".$className."(\$obj1);
\$results[] = \$obj1;
}
return \$results;
}
";
}
protected function addDoValidate(&$script)
{
$tmp = '';
parent::addDoValidate($tmp);
$script .= str_replace("return {$this->basePeerClassname}::doValidate(".$this->getPeerClassname()."::DATABASE_NAME, ".$this->getPeerClassname()."::TABLE_NAME, \$columns);\n",
"\$res = {$this->basePeerClassname}::doValidate(".$this->getPeerClassname()."::DATABASE_NAME, ".$this->getPeerClassname()."::TABLE_NAME, \$columns);\n".
" if (\$res !== true) {\n".
" \$request = sfContext::getInstance()->getRequest();\n".
" foreach (\$res as \$failed) {\n".
" \$col = ".$this->getPeerClassname()."::translateFieldname(\$failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);\n".
" \$request->setError(\$col, \$failed->getMessage());\n".
" }\n".
" }\n\n".
" return \$res;\n", $tmp);
}
protected function addDoSelectRS(&$script)
{
$tmp = '';
parent::addDoSelectRS($tmp);
if (DataModelBuilder::getBuildProperty('builderAddBehaviors'))
{
$mixer_script = "
foreach (sfMixer::getCallables('{$this->getClassname()}:addDoSelectRS:addDoSelectRS') as \$callable)
{
call_user_func(\$callable, '{$this->getClassname()}', \$criteria, \$con);
}
";
$tmp = preg_replace('/{/', '{'.$mixer_script, $tmp, 1);
}
$script .= $tmp;
}
protected function addDoUpdate(&$script)
{
$tmp = '';
parent::addDoUpdate($tmp);
if (DataModelBuilder::getBuildProperty('builderAddBehaviors'))
{
// add sfMixer call
$pre_mixer_script = "
foreach (sfMixer::getCallables('{$this->getClassname()}:doUpdate:pre') as \$callable)
{
\$ret = call_user_func(\$callable, '{$this->getClassname()}', \$values, \$con);
if (false !== \$ret)
{
return \$ret;
}
}
";
$post_mixer_script = "
foreach (sfMixer::getCallables('{$this->getClassname()}:doUpdate:post') as \$callable)
{
call_user_func(\$callable, '{$this->getClassname()}', \$values, \$con, \$ret);
}
return \$ret;
";
$tmp = preg_replace('/{/', '{'.$pre_mixer_script, $tmp, 1);
$tmp = preg_replace("/\t\treturn ([^}]+)/", "\t\t\$ret = $1".$post_mixer_script.' ', $tmp, 1);
}
$script .= $tmp;
}
protected function addDoInsert(&$script)
{
$tmp = '';
parent::addDoInsert($tmp);
if (DataModelBuilder::getBuildProperty('builderAddBehaviors'))
{
// add sfMixer call
$pre_mixer_script = "
foreach (sfMixer::getCallables('{$this->getClassname()}:doInsert:pre') as \$callable)
{
\$ret = call_user_func(\$callable, '{$this->getClassname()}', \$values, \$con);
if (false !== \$ret)
{
return \$ret;
}
}
";
$post_mixer_script = "
foreach (sfMixer::getCallables('{$this->getClassname()}:doInsert:post') as \$callable)
{
call_user_func(\$callable, '{$this->getClassname()}', \$values, \$con, \$pk);
}
return";
$tmp = preg_replace('/{/', '{'.$pre_mixer_script, $tmp, 1);
$tmp = preg_replace("/\t\treturn/", "\t\t".$post_mixer_script, $tmp, 1);
}
$script .= $tmp;
}
}