Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

optimized generated classes #541

Merged
merged 1 commit into from

3 participants

@gharlan

Made some optimizations in generated classes:

  • fixed code style
  • avoid IDE warnings
  • added type hints
  • some other fixes
src/Propel/Generator/Builder/Om/ObjectBuilder.php
@@ -3314,7 +3318,7 @@ protected function addRefFKGetJoinMethods(&$script, ForeignKey $refFK)
* @param string \$joinBehavior optional join type to use (defaults to $joinBehavior)
* @return Collection|{$className}[] List of $className objects
*/
- public function get".$relCol."Join".$relCol2."(\$criteria = null, \$con = null, \$joinBehavior = $joinBehavior)
+ public function get".$relCol."Join".$relCol2."(Criteria \$criteria = null, \$con = null, \$joinBehavior = $joinBehavior)
@staabm Collaborator
staabm added a note

ConnectionInterface $con

@gharlan
gharlan added a note

fixed in #537

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@staabm staabm commented on the diff
src/Propel/Generator/Builder/Om/ObjectBuilder.php
((16 lines not shown))
$relatedObjectClassName = $this->getRefFKPhpNameAffix($refFK, false);
$lowerRelatedObjectClassName = lcfirst($relatedObjectClassName);
$collName = $this->getRefFKCollVarName($refFK);
$script .= "
/**
- * @param {$relatedObjectClassName} \${$lowerRelatedObjectClassName} The $lowerRelatedObjectClassName object to add.
+ * @param {$className} \${$lowerRelatedObjectClassName} The $className object to add.
@staabm Collaborator
staabm added a note

Why className instead of relatedObjectClassName?

@gharlan
gharlan added a note

Sometimes $relatedObjectClassName is something like "EssayRelatedByFirstAuthor" while $className is the real class name ("Essay").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@staabm
Collaborator

Travis requires some more love :-)

@gharlan

Fixed it.. ;)

@willdurand
Owner

:+1:

@staabm
Collaborator

:+1:

@gharlan

ping @willdurand: can it be merged?

@willdurand willdurand merged commit a4c9864 into propelorm:master

1 check passed

Details default The Travis CI build passed
@willdurand
Owner

thx

@gharlan gharlan deleted the gharlan:optimized-generated-classes branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 22, 2014
  1. @gharlan

    optimized generated classes

    gharlan authored
This page is out of date. Refresh to see the latest.
View
4 src/Propel/Generator/Behavior/Versionable/VersionableBehaviorObjectBuilderModifier.php
@@ -299,7 +299,7 @@ public function addVersion(\$con = null)
$fkVersionColumnName = $fk->getLocalColumnName() . '_version';
$fkVersionColumnPhpName = $versionTable->getColumn($fkVersionColumnName)->getPhpName();
$script .= "
- if ((\$related = \$this->get{$fkGetter}(\$con)) && \$related->getVersion()) {
+ if ((\$related = \$this->get{$fkGetter}(null, \$con)) && \$related->getVersion()) {
\$version->set{$fkVersionColumnPhpName}(\$related->getVersion());
}";
}
@@ -309,7 +309,7 @@ public function addVersion(\$con = null)
$idsColumn = $this->behavior->getReferrerIdsColumn($fk);
$versionsColumn = $this->behavior->getReferrerVersionsColumn($fk);
$script .= "
- if (\$relateds = \$this->get{$fkGetter}(\$con)->toKeyValue('{$fk->getForeignColumn()->getPhpName()}', 'Version')) {
+ if (\$relateds = \$this->get{$fkGetter}(null, \$con)->toKeyValue('{$fk->getForeignColumn()->getPhpName()}', 'Version')) {
\$version->set{$idsColumn->getPhpName()}(array_keys(\$relateds));
\$version->set{$versionsColumn->getPhpName()}(array_values(\$relateds));
}";
View
137 src/Propel/Generator/Builder/Om/ObjectBuilder.php
@@ -289,19 +289,16 @@ protected function addClassBody(&$script)
/* @var $refFK ForeignKey */
foreach ($table->getCrossFks() as $fkList) {
list($refFK, $crossFK) = $fkList;
- $fkName = $this->getFKPhpNameAffix($crossFK, true);
if (!$refFK->isLocalPrimaryKey()) {
- $this->addScheduledForDeletionAttribute($script, $fkName);
+ $this->addCrossFkScheduledForDeletionAttribute($script, $crossFK);
}
}
}
foreach ($table->getReferrers() as $refFK) {
- $fkName = $this->getRefFKPhpNameAffix($refFK, true);
-
if (!$refFK->isLocalPrimaryKey()) {
- $this->addScheduledForDeletionAttribute($script, $fkName);
+ $this->addRefFkScheduledForDeletionAttribute($script, $refFK);
}
}
@@ -460,7 +457,14 @@ protected function addColumnAttributes(&$script)
*/
protected function addColumnAttributeComment(&$script, Column $column)
{
- $cptype = $column->getPhpType();
+ if ($column->isTemporalType()) {
+ $cptype = $this->getBuildProperty('dateTimeClass');
+ if (!$cptype) {
+ $cptype = '\DateTime';
+ }
+ } else {
+ $cptype = $column->getPhpType();
+ }
$clo = $column->getLowercasedName();
$script .= "
@@ -790,7 +794,7 @@ public function addTemporalAccessorComment(&$script, Column $column)
* @param string \$format The date/time format string (either date()-style or strftime()-style).
* If format is NULL, then the raw \DateTime object will be returned.
*
- * @return mixed Formatted date/time value as string or $dateTimeClass object (if format is NULL), NULL if column is NULL" .($handleMysqlDate ? ', and 0 if column value is ' . $mysqlInvalidDateString : '')."
+ * @return string|$dateTimeClass Formatted date/time value as string or $dateTimeClass object (if format is NULL), NULL if column is NULL" .($handleMysqlDate ? ', and 0 if column value is ' . $mysqlInvalidDateString : '')."
*
* @throws PropelException - if unable to parse/validate the date/time value.
*/";
@@ -1139,7 +1143,6 @@ protected function addDefaultAccessorBody(&$script, Column $column)
}
$script .= "
-
return \$this->$clo;";
}
@@ -1443,7 +1446,6 @@ protected function addMutatorCloseClose(&$script, Column $col)
{
$cfc = $col->getPhpName();
$script .= "
-
return \$this;
} // set$cfc()
";
@@ -1931,8 +1933,7 @@ protected function addHydrateBody(&$script)
$tableMap = $this->getTableMapClassName();
$script .= "
- try {
-";
+ try {";
$n = 0;
foreach ($table->getColumns() as $col) {
if (!$col->isLazyLoad()) {
@@ -2017,7 +2018,7 @@ protected function addHydrateBody(&$script)
return \$startcol + $n; // $n = ".$this->getTableMapClass()."::NUM_HYDRATE_COLUMNS.
} catch (Exception \$e) {
- throw new PropelException(\"Error populating ".$this->getStubObjectBuilder()->getClassName()." object\", 0, \$e);
+ throw new PropelException(sprintf('Error populating %s object', ".var_export($this->getStubObjectBuilder()->getClassName(), true)."), 0, \$e);
}";
}
@@ -2039,6 +2040,8 @@ protected function addHydrateClose(&$script)
**/
protected function addBuildPkeyCriteria(&$script)
{
+ $this->declareClass('Propel\\Runtime\\Exception\\LogicException');
+
$this->addBuildPkeyCriteriaComment($script);
$this->addBuildPkeyCriteriaOpen($script);
$this->addBuildPkeyCriteriaBody($script);
@@ -2085,7 +2088,6 @@ public function buildPkeyCriteria()
protected function addBuildPkeyCriteriaBody(&$script)
{
if (!$this->getTable()->getPrimaryKey()) {
- $this->declareClass('Propel\\Runtime\\Exception\\LogicException');
$script .= "
throw new LogicException('The {$this->getObjectName()} object has no primary key');";
return;
@@ -2166,7 +2168,9 @@ protected function addBuildCriteriaBody(&$script)
foreach ($this->getTable()->getColumns() as $col) {
$clo = $col->getLowercasedName();
$script .= "
- if (\$this->isColumnModified(".$this->getColumnConstant($col).")) \$criteria->add(".$this->getColumnConstant($col).", \$this->$clo);";
+ if (\$this->isColumnModified(".$this->getColumnConstant($col).")) {
+ \$criteria->add(".$this->getColumnConstant($col).", \$this->$clo);
+ }";
}
}
@@ -2524,7 +2528,9 @@ public function fromArray(\$arr, \$keyType = TableMap::$defaultKeyType)
foreach ($table->getColumns() as $num => $col) {
$cfc = $col->getPhpName();
$script .= "
- if (array_key_exists(\$keys[$num], \$arr)) \$this->set$cfc(\$arr[\$keys[$num]]);";
+ if (array_key_exists(\$keys[$num], \$arr)) {
+ \$this->set$cfc(\$arr[\$keys[$num]]);
+ }";
} /* foreach */
$script .= "
}
@@ -2953,7 +2959,6 @@ public function isPrimaryKeyNull()
{";
if (count($pkeys) == 1) {
$script .= "
-
return null === \$this->get" . $pkeys[0]->getPhpName() . "();";
} else {
$tests = array();
@@ -2961,7 +2966,6 @@ public function isPrimaryKeyNull()
$tests[]= "(null === \$this->get" . $pkey->getPhpName() . "())";
}
$script .= "
-
return " . join(' && ', $tests) . ";";
}
$script .= "
@@ -3021,7 +3025,7 @@ protected function addFKMethods(&$script)
*/
protected function addFKAttributes(&$script, ForeignKey $fk)
{
- $className = $fk->getForeignTable()->getPhpName();
+ $className = $this->getNewObjectBuilder($fk->getForeignTable())->getObjectClassName();
$varName = $this->getFKVarName($fk);
$script .= "
@@ -3312,9 +3316,9 @@ protected function addRefFKGetJoinMethods(&$script, ForeignKey $refFK)
* @param Criteria \$criteria optional Criteria object to narrow the query
* @param ConnectionInterface \$con optional connection object
* @param string \$joinBehavior optional join type to use (defaults to $joinBehavior)
- * @return Collection|{$className}[] List of $className objects
+ * @return ObjectCollection|{$className}[] List of $className objects
*/
- public function get".$relCol."Join".$relCol2."(\$criteria = null, \$con = null, \$joinBehavior = $joinBehavior)
+ public function get".$relCol."Join".$relCol2."(Criteria \$criteria = null, \$con = null, \$joinBehavior = $joinBehavior)
{";
$script .= "
\$query = $fkQueryClassName::create(null, \$criteria);
@@ -3599,10 +3603,10 @@ protected function addRefFKGet(&$script, ForeignKey $refFK)
*
* @param Criteria \$criteria optional Criteria object to narrow the query
* @param ConnectionInterface \$con optional connection object
- * @return Collection|{$className}[] List of $className objects
+ * @return ObjectCollection|{$className}[] List of $className objects
* @throws PropelException
*/
- public function get$relCol(\$criteria = null, ConnectionInterface \$con = null)
+ public function get$relCol(Criteria \$criteria = null, ConnectionInterface \$con = null)
{
\$partial = \$this->{$collName}Partial && !\$this->isNew();
if (null === \$this->$collName || null !== \$criteria || \$partial) {
@@ -3655,6 +3659,9 @@ protected function addRefFKSet(&$script, ForeignKey $refFK)
$relatedName = $this->getRefFKPhpNameAffix($refFK, true);
$relatedObjectClassName = $this->getRefFKPhpNameAffix($refFK, false);
+ $builder = $this->getNewObjectBuilder($refFK->getTable());
+ $className = $builder->getObjectClassName();
+
$inputCollection = lcfirst($relatedName);
$inputCollectionEntry = lcfirst($this->getRefFKPhpNameAffix($refFK, false));
@@ -3663,7 +3670,7 @@ protected function addRefFKSet(&$script, ForeignKey $refFK)
$script .= "
/**
- * Sets a collection of $relatedObjectClassName objects related by a one-to-many relationship
+ * Sets a collection of $className objects related by a one-to-many relationship
* to the current object.
* It will also schedule objects for deletion based on a diff between old objects (aka persisted)
* and new objects from the given Propel collection.
@@ -3674,6 +3681,7 @@ protected function addRefFKSet(&$script, ForeignKey $refFK)
*/
public function set{$relatedName}(Collection \${$inputCollection}, ConnectionInterface \$con = null)
{
+ /** @var {$className}[] \${$inputCollection}ToDelete */
\${$inputCollection}ToDelete = \$this->get{$relatedName}(new Criteria(), \$con)->diff(\${$inputCollection});
";
@@ -3713,17 +3721,26 @@ public function set{$relatedName}(Collection \${$inputCollection}, ConnectionInt
* @param string &$script The script will be modified in this method.
* @param ForeignKey $refFK
*/
- protected function addRefFKDoAdd(&$script, $refFK)
+ protected function addRefFKDoAdd(&$script, ForeignKey $refFK)
{
+ $tblFK = $refFK->getTable();
+
+ $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
+ $className = $joinedTableObjectBuilder->getObjectClassName();
+
+ if ($tblFK->getChildrenColumn()) {
+ $className = $joinedTableObjectBuilder->getFullyQualifiedClassName();
+ }
+
$relatedObjectClassName = $this->getRefFKPhpNameAffix($refFK, false);
$lowerRelatedObjectClassName = lcfirst($relatedObjectClassName);
$collName = $this->getRefFKCollVarName($refFK);
$script .= "
/**
- * @param {$relatedObjectClassName} \${$lowerRelatedObjectClassName} The $lowerRelatedObjectClassName object to add.
+ * @param {$className} \${$lowerRelatedObjectClassName} The $className object to add.
@staabm Collaborator
staabm added a note

Why className instead of relatedObjectClassName?

@gharlan
gharlan added a note

Sometimes $relatedObjectClassName is something like "EssayRelatedByFirstAuthor" while $className is the real class name ("Essay").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
*/
- protected function doAdd{$relatedObjectClassName}(\${$lowerRelatedObjectClassName})
+ protected function doAdd{$relatedObjectClassName}($className \${$lowerRelatedObjectClassName})
{
\$this->{$collName}[]= \${$lowerRelatedObjectClassName};
\${$lowerRelatedObjectClassName}->set" . $this->getFKPhpNameAffix($refFK, $plural = false) . "(\$this);
@@ -3735,8 +3752,17 @@ protected function doAdd{$relatedObjectClassName}(\${$lowerRelatedObjectClassNam
* @param string &$script The script will be modified in this method.
* @param ForeignKey $refFK
*/
- protected function addRefFKRemove(&$script, $refFK)
+ protected function addRefFKRemove(&$script, ForeignKey $refFK)
{
+ $tblFK = $refFK->getTable();
+
+ $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
+ $className = $joinedTableObjectBuilder->getObjectClassName();
+
+ if ($tblFK->getChildrenColumn()) {
+ $className = $joinedTableObjectBuilder->getFullyQualifiedClassName();
+ }
+
$relatedName = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$relatedObjectClassName = $this->getRefFKPhpNameAffix($refFK, $plural = false);
$inputCollection = lcfirst($relatedName . 'ScheduledForDeletion');
@@ -3748,10 +3774,10 @@ protected function addRefFKRemove(&$script, $refFK)
$script .= "
/**
- * @param {$relatedObjectClassName} \${$lowerRelatedObjectClassName} The $lowerRelatedObjectClassName object to remove.
+ * @param {$className} \${$lowerRelatedObjectClassName} The $className object to remove.
* @return ". $this->getObjectClassname() ." The current object (for fluent API support)
*/
- public function remove{$relatedObjectClassName}(\${$lowerRelatedObjectClassName})
+ public function remove{$relatedObjectClassName}($className \${$lowerRelatedObjectClassName})
{
if (\$this->get{$relatedName}()->contains(\${$lowerRelatedObjectClassName})) {
\$this->{$collName}->remove(\$this->{$collName}->search(\${$lowerRelatedObjectClassName}));
@@ -3854,20 +3880,37 @@ protected function addCrossFKAttributes(&$script, ForeignKey $crossFK)
$className = $joinedTableObjectBuilder->getObjectClassName();
$script .= "
/**
- * @var {$className}[] Collection to store aggregation of $className objects.
+ * @var ObjectCollection|{$className}[] Collection to store aggregation of $className objects.
*/
protected $" . $this->getCrossFKVarName($crossFK) . ";
";
}
- protected function addScheduledForDeletionAttribute(&$script, $fkName)
+ protected function addCrossFkScheduledForDeletionAttribute(&$script, ForeignKey $crossFK)
{
- $fkName = lcfirst($fkName);
+ $joinedTableObjectBuilder = $this->getNewObjectBuilder($crossFK->getForeignTable());
+ $className = $joinedTableObjectBuilder->getObjectClassName();
+ $fkName = lcfirst($this->getFKPhpNameAffix($crossFK, true));
$script .= "
/**
* An array of objects scheduled for deletion.
- * @var ObjectCollection
+ * @var ObjectCollection|{$className}[]
+ */
+ protected \${$fkName}ScheduledForDeletion = null;
+";
+ }
+
+ protected function addRefFkScheduledForDeletionAttribute(&$script, ForeignKey $refFK)
+ {
+ $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
+ $className = $joinedTableObjectBuilder->getObjectClassName();
+ $fkName = lcfirst($this->getRefFKPhpNameAffix($refFK, true));
+
+ $script .= "
+ /**
+ * An array of objects scheduled for deletion.
+ * @var ObjectCollection|{$className}[]
*/
protected \${$fkName}ScheduledForDeletion = null;
";
@@ -3999,7 +4042,6 @@ protected function addCrossFKClear(&$script, ForeignKey $crossFK)
public function clear{$relCol}()
{
\$this->$collName = null; // important to set this to NULL since that means it is uninitialized
- \$this->{$collName}Partial = null;
}
";
} // addRefererClear()
@@ -4080,7 +4122,7 @@ protected function addCrossFKGet(&$script, $refFK, $crossFK)
*
* @return ObjectCollection|{$relatedObjectClassName}[] List of {$relatedObjectClassName} objects
*/
- public function get{$relatedName}(\$criteria = null, ConnectionInterface \$con = null)
+ public function get{$relatedName}(Criteria \$criteria = null, ConnectionInterface \$con = null)
{
if (null === \$this->$collName || null !== \$criteria) {
if (\$this->isNew() && null === \$this->$collName) {
@@ -4163,7 +4205,7 @@ protected function addCrossFKCount(&$script, $refFK, $crossFK)
*
* @return int the number of related $relatedObjectClassName objects
*/
- public function count{$relatedName}(\$criteria = null, \$distinct = false, ConnectionInterface \$con = null)
+ public function count{$relatedName}(Criteria \$criteria = null, \$distinct = false, ConnectionInterface \$con = null)
{
if (null === \$this->$collName || null !== \$criteria) {
if (\$this->isNew() && null === \$this->$collName) {
@@ -4237,24 +4279,25 @@ public function add{$relatedObjectClassName}($crossObjectClassName $crossObjectN
*/
protected function addCrossFKDoAdd(&$script, ForeignKey $refFK, ForeignKey $crossFK)
{
- $relatedObjectClassName = $this->getFKPhpNameAffix($crossFK, $plural = false);
- $selfRelationNamePlural = $this->getFKPhpNameAffix($refFK, $plural = true);
- $lowerRelatedObjectClassName = lcfirst($relatedObjectClassName);
- $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
- $className = $joinedTableObjectBuilder->getObjectClassname();
- $refKObjectClassName = $this->getRefFKPhpNameAffix($refFK, $plural = false);
- $tblFK = $refFK->getTable();
- $foreignObjectName = '$' . $tblFK->getStudlyPhpName();
+ $relatedObjectClassName = $this->getFKPhpNameAffix($crossFK, $plural = false);
+ $selfRelationNamePlural = $this->getFKPhpNameAffix($refFK, $plural = true);
+ $lowerRelatedObjectClassName = lcfirst($relatedObjectClassName);
+ $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
+ $className = $joinedTableObjectBuilder->getObjectClassname();
+ $refFKObjectClassName = $this->getRefFKPhpNameAffix($refFK, $plural = false);
+ $tblFK = $refFK->getTable();
+ $foreignObjectName = '$' . $tblFK->getStudlyPhpName();
+ $crossObjectClassName = $this->getNewObjectBuilder($crossFK->getForeignTable())->getObjectClassName();
$script .= "
/**
- * @param {$relatedObjectClassName} \${$lowerRelatedObjectClassName} The $lowerRelatedObjectClassName object to add.
+ * @param {$crossObjectClassName} \${$lowerRelatedObjectClassName} The $lowerRelatedObjectClassName object to add.
*/
- protected function doAdd{$relatedObjectClassName}(\${$lowerRelatedObjectClassName})
+ protected function doAdd{$relatedObjectClassName}($crossObjectClassName \${$lowerRelatedObjectClassName})
{
{$foreignObjectName} = new {$className}();
{$foreignObjectName}->set{$relatedObjectClassName}(\${$lowerRelatedObjectClassName});
- \$this->add{$refKObjectClassName}({$foreignObjectName});
+ \$this->add{$refFKObjectClassName}({$foreignObjectName});
// set the back reference to this object directly as using provided method either results
// in endless loop or in multiple relations
if (!\${$lowerRelatedObjectClassName}->get{$selfRelationNamePlural}()->contains(\$this)) {
View
24 src/Propel/Generator/Builder/Om/QueryBuilder.php
@@ -396,7 +396,7 @@ protected function addFactoryComment(&$script)
protected function addFactoryOpen(&$script)
{
$script .= "
- public static function create(\$modelAlias = null, \$criteria = null)
+ public static function create(\$modelAlias = null, Criteria \$criteria = null)
{";
}
@@ -406,7 +406,7 @@ public static function create(\$modelAlias = null, \$criteria = null)
*/
protected function addFactoryBody(&$script)
{
- $classname = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($this->getTable()), true);
+ $classname = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($this->getTable()));
$script .= "
if (\$criteria instanceof " . $classname . ") {
return \$criteria;
@@ -590,9 +590,11 @@ protected function findPkSimple(\$key, \$con)
if ($table->getChildrenColumn()) {
$script .="
\$cls = {$tableMapClassName}::getOMClass(\$row, 0, false);
+ /** @var $ARClassName \$obj */
\$obj = new \$cls();";
} else {
$script .="
+ /** @var $ARClassName \$obj */
\$obj = new $ARClassName();";
}
$script .= "
@@ -650,6 +652,7 @@ protected function findPkComplex(\$key, \$con)
protected function addFindPks(&$script)
{
$this->declareClasses(
+ '\Propel\Runtime\Collection\ObjectCollection',
'\Propel\Runtime\Connection\ConnectionInterface',
'\Propel\Runtime\Propel'
);
@@ -733,7 +736,6 @@ public function filterByPrimaryKey(\$key)
$col = $pks[0];
$const = $this->getColumnConstant($col);
$script .= "
-
return \$this->addUsingAlias($const, \$key, Criteria::EQUAL);";
} else {
// composite primary key
@@ -787,7 +789,6 @@ public function filterByPrimaryKeys(\$keys)
$col = $pks[0];
$const = $this->getColumnConstant($col);
$script .= "
-
return \$this->addUsingAlias($const, \$keys, Criteria::IN);";
} else {
// composite primary key
@@ -1002,7 +1003,7 @@ public function filterBy$colPhpName(\$$variableName = null, \$comparison = null)
} elseif ($col->isBooleanType()) {
$script .= "
if (is_string(\$$variableName)) {
- \$$colName = in_array(strtolower(\$$variableName), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
+ \$$variableName = in_array(strtolower(\$$variableName), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
}";
}
$script .= "
@@ -1065,7 +1066,6 @@ public function filterBy$singularPhpName(\$$variableName = null, \$comparison =
protected function addFilterByFk(&$script, $fk)
{
$this->declareClasses(
- '\Propel\Runtime\Collection\Collection',
'\Propel\Runtime\Collection\ObjectCollection',
'\Propel\Runtime\Exception\PropelException'
);
@@ -1139,7 +1139,6 @@ public function filterBy$relationName($objectName, \$comparison = null)
protected function addFilterByRefFk(&$script, $fk)
{
$this->declareClasses(
- '\Propel\Runtime\Collection\Collection',
'\Propel\Runtime\Collection\ObjectCollection',
'\Propel\Runtime\Exception\PropelException'
);
@@ -1571,18 +1570,16 @@ protected function addDelete(&$script)
{
$script .= "
/**
- * Performs a DELETE on the database, given a ".$this->getObjectClassName()." or Criteria object OR a primary key value.
+ * Performs a DELETE on the database based on the current ModelCriteria
*
- * @param mixed \$values Criteria or ".$this->getObjectClassName()." object or primary key or array of primary keys
- * which is used to create the DELETE statement
* @param ConnectionInterface \$con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
- public function delete(ConnectionInterface \$con = null)
- {
+ public function delete(ConnectionInterface \$con = null)
+ {
if (null === \$con) {
\$con = Propel::getServiceContainer()->getWriteConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
@@ -1617,8 +1614,7 @@ public function delete(ConnectionInterface \$con = null)
}
$script .= "
-
- {$this->getTableMapClassName()}::removeInstanceFromPool(\$criteria);
+ {$this->getTableMapClassName()}::removeInstanceFromPool(\$criteria);
";
$script .= "
View
2  src/Propel/Generator/Builder/Om/QueryInheritanceBuilder.php
@@ -192,7 +192,7 @@ protected function addFactory(&$script)
*
* @return " . $classname . "
*/
- public static function create(\$modelAlias = null, \$criteria = null)
+ public static function create(\$modelAlias = null, Criteria \$criteria = null)
{
if (\$criteria instanceof " . $classname . ") {
return \$criteria;
View
49 src/Propel/Generator/Builder/Om/TableMapBuilder.php
@@ -92,6 +92,7 @@ class ".$this->getUnqualifiedClassName()." extends TableMap
{
use InstancePoolTrait;
use TableMapTrait;
+
";
}
@@ -429,10 +430,10 @@ protected function addBuildTableMap(&$script)
*/
public static function buildTableMap()
{
- \$dbMap = Propel::getServiceContainer()->getDatabaseMap(" . $this->getTableMapClass() . "::DATABASE_NAME);
- if (!\$dbMap->hasTable(" . $this->getTableMapClass() . "::TABLE_NAME)) {
- \$dbMap->addTableObject(new ".$this->getTableMapClass()."());
- }
+ \$dbMap = Propel::getServiceContainer()->getDatabaseMap(" . $this->getTableMapClass() . "::DATABASE_NAME);
+ if (!\$dbMap->hasTable(" . $this->getTableMapClass() . "::TABLE_NAME)) {
+ \$dbMap->addTableObject(new ".$this->getTableMapClass()."());
+ }
}
";
}
@@ -725,8 +726,8 @@ public function addClearRelatedInstancePool()
}
return $this->renderTemplate('tableMapClearRelatedInstancePool', array(
- 'tableName' => $table->getName(),
- 'relatedClassNames' => $relatedClassNames,
+ 'tableName' => $table->getName(),
+ 'relatedClassNames' => $relatedClassNames,
));
}
@@ -786,6 +787,8 @@ protected function addGetPrimaryKeyHash(&$script)
* @param int \$offset The 0-based offset for reading from the resultset row.
* @param string \$indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME
* TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
+ *
+ * @return string The primary key hash of the row
*/
public static function getPrimaryKeyHashFromRow(\$row, \$offset = 0, \$indexType = TableMap::TYPE_NUM)
{";
@@ -835,13 +838,15 @@ public static function getPrimaryKeyFromRow(\$row, \$offset = 0, \$indexType = T
$n = 0;
if ($table->hasCompositePrimaryKey()) {
- $pks = array();
foreach ($table->getColumns() as $col) {
if (!$col->isLazyLoad()) {
if ($col->isPrimaryKey()) {
- $pks[] = '\$pks[] = (' . $col->getPhpType() . ') ' . "\$row[\$indexType == TableMap::TYPE_NUM
- ? $n + \$offset
- : self::translateFieldName('{$col->getPhpName()}', TableMap::TYPE_PHPNAME, \$indexType)]";
+ $script .= '
+ $pks[] = (' . $col->getPhpType() . ') ' . "\$row[
+ \$indexType == TableMap::TYPE_NUM
+ ? $n + \$offset
+ : self::translateFieldName('{$col->getPhpName()}', TableMap::TYPE_PHPNAME, \$indexType)
+ ];";
}
$n++;
}
@@ -849,7 +854,7 @@ public static function getPrimaryKeyFromRow(\$row, \$offset = 0, \$indexType = T
$script .= "
- return \$pks;";
+ return \$pks;";
} else {
$pk = "''";
@@ -857,18 +862,17 @@ public static function getPrimaryKeyFromRow(\$row, \$offset = 0, \$indexType = T
if (!$col->isLazyLoad()) {
if ($col->isPrimaryKey()) {
$pk = '(' . $col->getPhpType() . ') ' . "\$row[
- \$indexType == TableMap::TYPE_NUM
- ? $n + \$offset
- : self::translateFieldName('{$col->getPhpName()}', TableMap::TYPE_PHPNAME, \$indexType)
- ]";
+ \$indexType == TableMap::TYPE_NUM
+ ? $n + \$offset
+ : self::translateFieldName('{$col->getPhpName()}', TableMap::TYPE_PHPNAME, \$indexType)
+ ]";
}
$n++;
}
}
$script .= "
-
- return " . $pk . ";";
+ return " . $pk . ";";
}
$script .= "
@@ -911,6 +915,8 @@ protected function addGetOMClass_Inheritance(&$script)
* @param boolean \$withPrefix Whether or not to return the path with the class name
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
+ *
+ * @return string The OM class
*/
public static function getOMClass(\$row, \$colnum, \$withPrefix = true)
{
@@ -1049,6 +1055,7 @@ public static function populateObject(\$row, \$offset = 0, \$indexType = TableMa
\$cls = static::getOMClass(\$row, \$offset, false);";
}
$script .= "
+ /** @var {$this->getObjectClassName()} \$obj */
\$obj = new \$cls();
\$col = \$obj->hydrate(\$row, \$offset, false, \$indexType);
{$this->getTableMapClassName()}::addInstanceToPool(\$obj, \$key);
@@ -1103,12 +1110,14 @@ public static function populateObjects(DataFetcherInterface \$dataFetcher)
// class must be set each time from the record row
\$cls = static::getOMClass(\$row, 0);
\$cls = preg_replace('#\.#', '\\\\', \$cls);
+ /** @var {$this->getObjectClassName()} \$obj */
" . $this->buildObjectInstanceCreationCode('$obj', '$cls') . "
\$obj->hydrate(\$row);
\$results[] = \$obj;
{$this->getTableMapClassName()}::addInstanceToPool(\$obj, \$key);";
} else {
$script .= "
+ /** @var {$this->getObjectClassName()} \$obj */
" . $this->buildObjectInstanceCreationCode('$obj', '$cls') . "
\$obj->hydrate(\$row);
\$results[] = \$obj;
@@ -1296,9 +1305,11 @@ public static function doDelete(\$values, ConnectionInterface \$con = null)
\$query = " . $this->getQueryClassName() . "::create()->mergeWith(\$criteria);
- if (\$values instanceof Criteria) { {$this->getTableMapClassName()}::clearInstancePool();
+ if (\$values instanceof Criteria) {
+ {$this->getTableMapClassName()}::clearInstancePool();
} elseif (!is_object(\$values)) { // it's a primary key, or an array of pks
- foreach ((array) \$values as \$singleval) { {$this->getTableMapClassName()}::removeInstanceFromPool(\$singleval);
+ foreach ((array) \$values as \$singleval) {
+ {$this->getTableMapClassName()}::removeInstanceFromPool(\$singleval);
}
}
View
10 src/Propel/Generator/Builder/Om/templates/baseObjectMethods.php
@@ -49,7 +49,7 @@ public function isNew()
*/
public function setNew($b)
{
- $this->new = (Boolean) $b;
+ $this->new = (boolean) $b;
}
/**
@@ -68,7 +68,7 @@ public function isDeleted()
*/
public function setDeleted($b)
{
- $this->deleted = (Boolean) $b;
+ $this->deleted = (boolean) $b;
}
/**
@@ -97,8 +97,7 @@ public function resetModified($col = null)
*/
public function equals($obj)
{
- $thisclazz = get_class($this);
- if (!is_object($obj) || !($obj instanceof $thisclazz)) {
+ if (!$obj instanceof static) {
return false;
}
@@ -106,8 +105,7 @@ public function equals($obj)
return true;
}
- if (null === $this->getPrimaryKey()
- || null === $obj->getPrimaryKey()) {
+ if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) {
return false;
}
View
10 src/Propel/Generator/Builder/Om/templates/tableMapClearRelatedInstancePool.php
@@ -4,9 +4,9 @@
*/
public static function clearRelatedInstancePool()
{
- // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool,
+ // Invalidate objects in related instance pools,
// since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
- <?php foreach ($relatedClassNames as $relatedClassName) : ?>
- <?= $relatedClassName ?>::clearInstancePool();
- <?php endforeach; ?>
- }
+ <?php foreach ($relatedClassNames as $relatedClassName) : ?>
+ <?= $relatedClassName ?>::clearInstancePool();
+ <?php endforeach; ?>
+}
View
16 src/Propel/Generator/Model/Table.php
@@ -32,7 +32,7 @@
class Table extends ScopedMappingModel implements IdMethod
{
use BehaviorableTrait;
-
+
/**
* @var Column[]
*/
@@ -225,7 +225,7 @@ public function applyBehaviors()
}
}
}
-
+
protected function registerBehavior(Behavior $behavior)
{
$behavior->setTable($this);
@@ -566,7 +566,7 @@ public function addColumn($col)
/**
* Adds several columns at once.
- *
+ *
* @param Column[] $columns An array of Column instance
*/
public function addColumns(array $columns)
@@ -708,7 +708,7 @@ public function addReferrer(ForeignKey $fk)
/**
* Returns the list of references to this table.
*
- * @return array
+ * @return ForeignKey[]
*/
public function getReferrers()
{
@@ -965,7 +965,7 @@ public function getGeneratorConfig()
return $this->database->getGeneratorConfig();
}
-
+
/**
* Returns whether or not the table behaviors offer additional builders.
@@ -1256,7 +1256,7 @@ public function isReadOnly()
/**
* Makes this database in read-only mode.
- *
+ *
* @param boolean $flag True by default
*/
public function setReadOnly($flag = true)
@@ -1447,7 +1447,7 @@ public function getForeignKeys()
/**
* Returns a Collection of parameters relevant for the chosen
* id generation method.
- *
+ *
* @return IdMethodParameter[]
*/
public function getIdMethodParameters()
@@ -1712,7 +1712,7 @@ public function isForReferenceOnly()
/**
* Returns whether or not to determine if code/sql gets created for this table.
* Table will be skipped, if set to true.
- *
+ *
* @param boolean $flag
*/
public function setForReferenceOnly($flag = true)
View
12 src/Propel/Runtime/Map/TableMap.php
@@ -512,10 +512,12 @@ public function getColumns()
/**
* Add a primary key column to this Table.
*
- * @param string $columnName A String with the column name.
- * @param string $type A string specifying the Propel type.
- * @param boolean $isNotNull Whether column does not allow NULL values.
- * @param $size An int specifying the size.
+ * @param string $columnName A String with the column name.
+ * @param string $phpName A string representing the PHP name.
+ * @param string $type A string specifying the Propel type.
+ * @param boolean $isNotNull Whether column does not allow NULL values.
+ * @param int $size An int specifying the size.
+ * @param string $defaultValue The default value for this column.
* @return \Propel\Runtime\Map\ColumnMap Newly added PrimaryKey column.
*/
public function addPrimaryKey($columnName, $phpName, $type, $isNotNull = false, $size = null, $defaultValue = null)
@@ -527,6 +529,7 @@ public function addPrimaryKey($columnName, $phpName, $type, $isNotNull = false,
* Add a foreign key column to the table.
*
* @param string $columnName A String with the column name.
+ * @param string $phpName A string representing the PHP name.
* @param string $type A string specifying the Propel type.
* @param string $fkTable A String with the foreign key table name.
* @param string $fkColumn A String with the foreign key column name.
@@ -544,6 +547,7 @@ public function addForeignKey($columnName, $phpName, $type, $fkTable, $fkColumn,
* Add a foreign primary key column to the table.
*
* @param string $columnName A String with the column name.
+ * @param string $phpName A string representing the PHP name.
* @param string $type A string specifying the Propel type.
* @param string $fkTable A String with the foreign key table name.
* @param string $fkColumn A String with the foreign key column name.
View
3  tests/Propel/Tests/Generator/Behavior/AggregateColumn/AggregateColumnBehaviorTest.php
@@ -10,6 +10,7 @@
namespace Propel\Tests\Generator\Behavior\AggregateColumn;
+use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Tests\Bookstore\Behavior\AggregateColumn;
use Propel\Tests\Bookstore\Behavior\AggregateComment;
use Propel\Tests\Bookstore\Behavior\AggregateCommentQuery;
@@ -251,7 +252,7 @@ public function delete(ConnectionInterface $con = null)
class TestableAggregateCommentQuery extends AggregateCommentQuery
{
- public static function create($modelAlias = null, $criteria = null)
+ public static function create($modelAlias = null, Criteria $criteria = null)
{
return new TestableAggregateCommentQuery();
}
View
2  tests/Propel/Tests/Generator/Builder/Om/QueryBuilderTest.php
@@ -1095,7 +1095,7 @@ public function testPruneCompositeKey()
class myCustomBookQuery extends BookQuery
{
- public static function create($modelAlias = null, $criteria = null)
+ public static function create($modelAlias = null, Criteria $criteria = null)
{
if ($criteria instanceof myCustomBookQuery) {
return $criteria;
Something went wrong with that request. Please try again.