Skip to content
Browse files

Merge with Propel/master

  • Loading branch information...
1 parent 573fe8c commit 242350646cd61ef3a70c2bf13a088443e6d45d39 @rozwell rozwell committed Aug 4, 2012
Showing with 850 additions and 491 deletions.
  1. +44 −0 CHANGELOG
  2. +1 −1 generator/build.properties-sample
  3. +2 −1 generator/default.properties
  4. +1 −1 generator/lib/behavior/nestedset/NestedSetBehaviorObjectBuilderModifier.php
  5. +14 −10 generator/lib/builder/om/ExtensionQueryBuilder.php
  6. +105 −60 generator/lib/builder/om/OMBuilder.php
  7. +15 −12 generator/lib/builder/om/PHP5ExtensionObjectBuilder.php
  8. +14 −10 generator/lib/builder/om/PHP5ExtensionPeerBuilder.php
  9. +289 −274 generator/lib/builder/om/PHP5ObjectBuilder.php
  10. +16 −11 generator/lib/builder/om/PHP5PeerBuilder.php
  11. +35 −24 generator/lib/builder/om/QueryBuilder.php
  12. +3 −3 generator/lib/builder/util/XmlToAppData.php
  13. +2 −2 generator/lib/config/QuickGeneratorConfig.php
  14. +12 −3 generator/lib/model/Table.php
  15. +13 −10 generator/lib/platform/DefaultPlatform.php
  16. +4 −4 generator/lib/platform/MysqlPlatform.php
  17. +3 −3 generator/lib/platform/PropelPlatformInterface.php
  18. +0 −1 generator/lib/platform/SqlitePlatform.php
  19. +3 −3 generator/lib/util/PropelQuickBuilder.php
  20. +1 −1 runtime/lib/Propel.php
  21. +39 −1 runtime/lib/collection/PropelObjectCollection.php
  22. +59 −52 runtime/lib/om/BaseObject.php
  23. +10 −0 test/fixtures/generator/behavior/Foobar.php
  24. +3 −3 test/testsuite/generator/behavior/DelegateBehaviorTest.php
  25. +32 −0 test/testsuite/generator/behavior/NamespacedBehaviorTest.php
  26. +16 −0 test/testsuite/generator/model/TableTest.php
  27. +1 −1 test/testsuite/runtime/collection/PropelCollectionTest.php
  28. +113 −0 test/testsuite/runtime/collection/PropelObjectCollectionTest.php
View
44 CHANGELOG
@@ -1,5 +1,49 @@
# Changelog Of The Propel 1.6 Branch #
+## 2012-07-30: Version 1.6.7 ##
+
+38cfc9e Update generator/build.properties-sample
+f90dfa9 fix for issue 425
+74ee4e1 fix for issue 425
+88e21e6 Avoid blank line in object stub class
+8709d3a Fix tests
+cefc9ef More CS fixes
+e1e1078 Fix doc blocks
+29c9db3 Fix NULL => null
+3c1717b Improve code generation to follow PSR recommendations
+6bae0ca Changed FIXME to TODO
+bfef0d7 Changed comments
+5e9dfc1 PropelSQLParser with delimiter and fixed tests
+39d7958 fix for issue 425
+9667675 SQL Parser Delimiter Tests
+8cafbd6 Merge remote-tracking branch 'upstream/master' into delimiter-trigger-parser
+5522fbf fix test to pass on platform with EOF != \n
+cad1ac6 fix test 2 new relations added to book ;) for issue #421
+a9097da this fix issue #409 thank to toaotc for the patch
+2ca7067 add test to prove issue #409
+e84c67c add chaining in PropelObjectCollection::toKeyValue
+5dd5394 Revert "Fix platform loading" as it breaks multiple builds using the runtime config
+55fef69 Fix regression that removed Persistent interfaces in base classes
+d87e9a5 Add test that prove a regression
+7c7a608 Fix composer config
+c476e50 Add generator classes to the classmap
+0d1515d Added column positioning ability to mysql migration
+66e7a59 fixes translateFieldname and concrete inheritance
+3c891ed add test to show the inheritance issue with php5.4
+66f91c9 Fix platform loading
+2874edb fix call on a non object ;)
+790b3e4 [aggregate_column behavior] computeCall call reduced from n+1 to 1 or 2 fix #403, add computeCall on main object save() add isAlreadyInSave(),
+ddd028c add test to prove to much query on aggregate_column behavior
+c36fc7f Add back previous include but change the order of the include path
+c107e8e Issue #388: Fix propel-gen path issues Fixes an issue with the check for the propel-gen home-path in propel-gen script Fixes an issue with classes being redeclared because of custom include in phing.php (code is not there in the phing.php version from phing itself)
+9731032 Fix collection cache overriding existing one when related object are fetched with criteria
+f371602 Fix data loss where parent object won't save related objects when fetched with criteria
+3a3ad2c Fixed Versionable Object Modifier not to reload object collection after populateFromVersion
+dde4460 Fix joining related object
+abc7fc8 Change ObjectBuilder to reload related objects when collection is partially loaded
+05b7e1d Fixed possible bug
+5d9517a Improved SQLParser to work with triggers in additional .sql files
+
## 2012-07-02: Version 1.6.6 ##
17edd0f Prepare 1.6.6 release
View
2 generator/build.properties-sample
@@ -84,7 +84,7 @@ propel.home = .
# or php4 (experimental).
#
# packageObjectModel
-# Sets whether Propel is packaging ObjectModel fro several
+# Sets whether Propel is packaging ObjectModel for several
# [package].schema.xml files. The <database package="packageName">
# attribute has to be set then. (warning: this is experimental!)
#
View
3 generator/default.properties
@@ -16,7 +16,7 @@
#
# -------------------------------------------------------------------
-propel.version = 1.6.7-dev
+propel.version = 1.6.7
propel.home = .
@@ -86,6 +86,7 @@ propel.addGenericAccessors = true
propel.addGenericMutators = true
propel.addSaveMethod = true
propel.addTimeStamp = false
+propel.addClassLevelComment = true
propel.addValidateMethod = true
propel.addIncludes = false
propel.addHooks = true
View
2 generator/lib/behavior/nestedset/NestedSetBehaviorObjectBuilderModifier.php
@@ -716,7 +716,7 @@ public function addNestedSetChild($objectName)
if (\$this->collNestedSetChildren === null) {
\$this->initNestedSetChildren();
}
- if (!\$this->collNestedSetChildren->contains($objectName)) { // only add it if the **same** object is not already associated
+ if (!in_array($objectName, \$this->collNestedSetChildren->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
\$this->collNestedSetChildren[]= $objectName;
{$objectName}->setParent(\$this);
}
View
24 generator/lib/builder/om/ExtensionQueryBuilder.php
@@ -56,30 +56,34 @@ protected function addClassOpen(&$script)
$tableDesc = $table->getDescription();
$baseClassname = $this->getQueryBuilder()->getClassname();
- $script .= "
+ if ($this->getBuildProperty('addClassLevelComment')) {
+ $script .= "
/**
* Skeleton subclass for performing query and update operations on the '$tableName' table.
*
* $tableDesc
*";
- if ($this->getBuildProperty('addTimeStamp')) {
- $now = strftime('%c');
- $script .= "
+ if ($this->getBuildProperty('addTimeStamp')) {
+ $now = strftime('%c');
+ $script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
- }
- $script .= "
+ }
+ $script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
- */
-class ".$this->getClassname()." extends $baseClassname {
-";
+ */";
+ }
+
+ $script .= "
+class ".$this->getClassname()." extends $baseClassname
+{";
}
/**
@@ -102,7 +106,7 @@ protected function addClassBody(&$script)
protected function addClassClose(&$script)
{
$script .= "
-} // " . $this->getClassname() . "
+}
";
$this->applyBehaviorModifier('extensionQueryFilter', $script, "");
}
View
165 generator/lib/builder/om/OMBuilder.php
@@ -44,24 +44,28 @@ public function build()
$this->validateModel();
$script = '';
+
if ($this->isAddIncludes()) {
$this->addIncludes($script);
}
+
$this->addClassOpen($script);
$this->addClassBody($script);
$this->addClassClose($script);
if ($useStatements = $this->getUseStatements($ignoredNamespace = $this->getNamespace())) {
$script = $useStatements . $script;
}
+
if ($namespaceStatement = $this->getNamespaceStatement()) {
$script = $namespaceStatement . $script;
}
- //if($this->getTable()->getName() == 'book_club_list') die($ignoredNamespace);
- return "<" . "?php
+ $script = "<?php
" . $script;
+
+ return $this->clean($script);
}
/**
@@ -498,66 +502,107 @@ protected function isAddIncludes()
}
/**
- * Checks whether any registered behavior on that table has a modifier for a hook
- * @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
- * @param string $modifier The name of the modifier object providing the method in the behavior
- * @return boolean
- */
- public function hasBehaviorModifier($hookName, $modifier)
- {
- $modifierGetter = 'get' . $modifier;
- foreach ($this->getTable()->getBehaviors() as $behavior) {
- if (method_exists($behavior->$modifierGetter(), $hookName)) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Checks whether any registered behavior on that table has a modifier for a hook
- * @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
- * @param string $modifier The name of the modifier object providing the method in the behavior
+ * Checks whether any registered behavior on that table has a modifier for a hook
+ * @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
+ * @param string $modifier The name of the modifier object providing the method in the behavior
+ * @return boolean
+ */
+ public function hasBehaviorModifier($hookName, $modifier)
+ {
+ $modifierGetter = 'get' . $modifier;
+ foreach ($this->getTable()->getBehaviors() as $behavior) {
+ if (method_exists($behavior->$modifierGetter(), $hookName)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Checks whether any registered behavior on that table has a modifier for a hook
+ * @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
+ * @param string $modifier The name of the modifier object providing the method in the behavior
* @param string &$script The script will be modified in this method.
- */
- public function applyBehaviorModifierBase($hookName, $modifier, &$script, $tab = " ")
- {
- $modifierGetter = 'get' . $modifier;
- foreach ($this->getTable()->getBehaviors() as $behavior) {
- $modifier = $behavior->$modifierGetter();
- if (method_exists($modifier, $hookName)) {
- if (strpos($hookName, 'Filter') !== false) {
- // filter hook: the script string will be modified by the behavior
- $modifier->$hookName($script, $this);
- } else {
- // regular hook: the behavior returns a string to append to the script string
- if (!$addedScript = $modifier->$hookName($this)) {
- continue;
- }
- $script .= "
+ */
+ public function applyBehaviorModifierBase($hookName, $modifier, &$script, $tab = " ")
+ {
+ $modifierGetter = 'get' . $modifier;
+ foreach ($this->getTable()->getBehaviors() as $behavior) {
+ $modifier = $behavior->$modifierGetter();
+
+ if (method_exists($modifier, $hookName)) {
+ if (strpos($hookName, 'Filter') !== false) {
+ // filter hook: the script string will be modified by the behavior
+ $modifier->$hookName($script, $this);
+ } else {
+ // regular hook: the behavior returns a string to append to the script string
+ if (!$addedScript = $modifier->$hookName($this)) {
+ continue;
+ }
+
+ $script .= "
" . $tab . '// ' . $behavior->getName() . " behavior
";
- $script .= preg_replace('/^/m', $tab, $addedScript);
- }
- }
- }
- }
-
- /**
- * Checks whether any registered behavior content creator on that table exists a contentName
- * @param string $contentName The name of the content as called from one of this class methods, e.g. "parentClassname"
- * @param string $modifier The name of the modifier object providing the method in the behavior
- */
- public function getBehaviorContentBase($contentName, $modifier)
- {
- $modifierGetter = 'get' . $modifier;
- foreach ($this->getTable()->getBehaviors() as $behavior) {
- $modifier = $behavior->$modifierGetter();
- if (method_exists($modifier, $contentName)) {
- return $modifier->$contentName($this);
- }
- }
- }
+ $script .= preg_replace('/^/m', $tab, $addedScript);
+ }
+ }
+ }
+ }
+ /**
+ * Checks whether any registered behavior content creator on that table exists a contentName
+ * @param string $contentName The name of the content as called from one of this class methods, e.g. "parentClassname"
+ * @param string $modifier The name of the modifier object providing the method in the behavior
+ */
+ public function getBehaviorContentBase($contentName, $modifier)
+ {
+ $modifierGetter = 'get' . $modifier;
+ foreach ($this->getTable()->getBehaviors() as $behavior) {
+ $modifier = $behavior->$modifierGetter();
+ if (method_exists($modifier, $contentName)) {
+ return $modifier->$contentName($this);
+ }
+ }
+ }
+
+ /**
+ * Most of the code comes from the PHP-CS-Fixer project
+ */
+ private function clean($content)
+ {
+ // trailing whitespaces
+ $content = preg_replace('/[ \t]*$/m', '', $content);
+
+ // indentation
+ $content = preg_replace_callback('/^([ \t]+)/m', function ($matches) use ($content) {
+ return str_replace("\t", ' ', $matches[0]);
+ }, $content);
+
+ // line feed
+ $content = str_replace("\r\n", "\n", $content);
+
+ // Unused "use" statements
+ preg_match_all('/^use (?P<class>[^\s;]+)(?:\s+as\s+(?P<alias>.*))?;/m', $content, $matches, PREG_SET_ORDER);
+ foreach ($matches as $match) {
+ if (isset($match['alias'])) {
+ $short = $match['alias'];
+ } else {
+ $parts = explode('\\', $match['class']);
+ $short = array_pop($parts);
+ }
+
+ preg_match_all('/\b'.$short.'\b/i', str_replace($match[0]."\n", '', $content), $m);
+ if (!count($m[0])) {
+ $content = str_replace($match[0]."\n", '', $content);
+ }
+ }
+
+ // end of line
+ if (strlen($content) && "\n" != substr($content, -1)) {
+ $content = $content."\n";
+ }
+
+ return $content;
+ }
}
View
27 generator/lib/builder/om/PHP5ExtensionObjectBuilder.php
@@ -77,30 +77,34 @@ protected function addClassOpen(&$script)
break;
}
- $script .= "
+ if ($this->getBuildProperty('addClassLevelComment')) {
+ $script .= "
/**
* Skeleton subclass for representing a row from the '$tableName' table.
*
* $tableDesc
*";
- if ($this->getBuildProperty('addTimeStamp')) {
- $now = strftime('%c');
- $script .= "
+ if ($this->getBuildProperty('addTimeStamp')) {
+ $now = strftime('%c');
+ $script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
- }
- $script .= "
+ }
+ $script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
- */
-".($table->isAbstract() ? "abstract " : "")."class ".$this->getClassname()." extends $baseClassname {
-";
+ */";
+ }
+
+ $script .= "
+".($table->isAbstract() ? "abstract " : "")."class ".$this->getClassname()." extends $baseClassname
+{";
}
/**
@@ -122,9 +126,8 @@ protected function addClassBody(&$script)
protected function addClassClose(&$script)
{
$script .= "
-} // " . $this->getClassname() . "
+}
";
$this->applyBehaviorModifier('extensionObjectFilter', $script, "");
}
-
-} // PHP5ExtensionObjectBuilder
+}
View
24 generator/lib/builder/om/PHP5ExtensionPeerBuilder.php
@@ -77,30 +77,34 @@ protected function addClassOpen(&$script)
break;
}
- $script .= "
+ if ($this->getBuildProperty('addClassLevelComment')) {
+ $script .= "
/**
* Skeleton subclass for performing query and update operations on the '$tableName' table.
*
* $tableDesc
*";
- if ($this->getBuildProperty('addTimeStamp')) {
- $now = strftime('%c');
- $script .= "
+ if ($this->getBuildProperty('addTimeStamp')) {
+ $now = strftime('%c');
+ $script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
- }
- $script .= "
+ }
+ $script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
- */
-class ".$this->getClassname()." extends $baseClassname {
-";
+ */";
+ }
+
+ $script .= "
+class ".$this->getClassname()." extends $baseClassname
+{";
}
/**
@@ -124,7 +128,7 @@ protected function addClassBody(&$script)
protected function addClassClose(&$script)
{
$script .= "
-} // " . $this->getClassname() . "
+}
";
$this->applyBehaviorModifier('extensionPeerFilter', $script, "");
}
View
563 generator/lib/builder/om/PHP5ObjectBuilder.php
289 additions, 274 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
27 generator/lib/builder/om/PHP5PeerBuilder.php
@@ -98,19 +98,25 @@ protected function addClassOpen(&$script)
$tableName = $this->getTable()->getName();
$tableDesc = $this->getTable()->getDescription();
- $script .= "
+ if ($this->getBuildProperty('addClassLevelComment')) {
+ $script .= "
/**
* Base static class for performing query and update operations on the '$tableName' table.
*
* $tableDesc
*";
- if ($this->getBuildProperty('addTimeStamp')) {
- $now = strftime('%c');
- $script .= "
+ if ($this->getBuildProperty('addTimeStamp')) {
+ $now = strftime('%c');
+ $script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
+ }
+
+ $script .= "
+ * @package propel.generator.".$this->getPackage()."
+ */";
}
$extendingPeerClass = '';
@@ -122,9 +128,8 @@ protected function addClassOpen(&$script)
}
$script .= "
- * @package propel.generator.".$this->getPackage()."
- */
-abstract class ".$this->getClassname(). $extendingPeerClass . " {
+abstract class ".$this->getClassname(). $extendingPeerClass . "
+{
";
}
@@ -991,7 +996,7 @@ protected function addGetInstanceFromPool(&$script)
* a multi-column primary key, a serialize()d version of the primary key will be returned.
*
* @param string \$key The key (@see getPrimaryKeyHash()) for this instance.
- * @return ".$this->getObjectClassname()." Found object or NULL if 1) no instance exists for specified key or 2) instance pooling has been disabled.
+ * @return ".$this->getObjectClassname()." Found object or null if 1) no instance exists for specified key or 2) instance pooling has been disabled.
* @see getPrimaryKeyHash()
*/
public static function getInstanceFromPool(\$key)
@@ -1022,7 +1027,7 @@ protected function addGetPrimaryKeyHash(&$script)
*
* @param array \$row PropelPDO resultset row.
* @param int \$startcol The 0-based offset for reading from the resultset row.
- * @return string A string version of PK or NULL if the components of primary key in result array are all null.
+ * @return string A string version of PK or null if the components of primary key in result array are all null.
*/
public static function getPrimaryKeyHashFromRow(\$row, \$startcol = 0)
{";
@@ -1044,7 +1049,7 @@ public static function getPrimaryKeyHashFromRow(\$row, \$startcol = 0)
}
$script .= "
- // If the PK cannot be derived from the row, return NULL.
+ // If the PK cannot be derived from the row, return null.
if (".implode(' && ', $cond).") {
return null;
}
@@ -1785,7 +1790,7 @@ protected static function doOnDeleteSetNull(Criteria \$criteria, PropelPDO \$con
$columnNamesF = $fk->getLocalColumns();
$columnNamesL = $fk->getForeignColumns(); // should be same num as foreign
$script .= "
- // set fkey col in related $fkClassName rows to NULL
+ // set fkey col in related $fkClassName rows to null
\$selectCriteria = new Criteria(".$this->getPeerClassname()."::DATABASE_NAME);
\$updateValues = new Criteria(".$this->getPeerClassname()."::DATABASE_NAME);";
View
59 generator/lib/builder/om/QueryBuilder.php
@@ -72,88 +72,98 @@ protected function addClassOpen(&$script)
$modelClass = $this->getStubObjectBuilder()->getClassname();
$parentClass = $this->getBehaviorContent('parentClass');
$parentClass = null === $parentClass ? 'ModelCriteria' : $parentClass;
- $script .= "
+
+ if ($this->getBuildProperty('addClassLevelComment')) {
+ $script .= "
/**
* Base class that represents a query for the '$tableName' table.
*
* $tableDesc
*";
- if ($this->getBuildProperty('addTimeStamp')) {
- $now = strftime('%c');
- $script .= "
+ if ($this->getBuildProperty('addTimeStamp')) {
+ $now = strftime('%c');
+ $script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
+ }
+ } else {
+ $script .= "
+/**";
}
// magic orderBy() methods, for IDE completion
foreach ($this->getTable()->getColumns() as $column) {
$script .= "
- * @method $queryClass orderBy" . $column->getPhpName() . "(\$order = Criteria::ASC) Order by the " . $column->getName() . " column";
+ * @method $queryClass orderBy" . $column->getPhpName() . "(\$order = Criteria::ASC) Order by the " . $column->getName() . " column";
}
$script .= "
*";
// magic groupBy() methods, for IDE completion
foreach ($this->getTable()->getColumns() as $column) {
$script .= "
- * @method $queryClass groupBy" . $column->getPhpName() . "() Group by the " . $column->getName() . " column";
+ * @method $queryClass groupBy" . $column->getPhpName() . "() Group by the " . $column->getName() . " column";
}
// override the signature of ModelCriteria::left-, right- and innerJoin to specify the class of the returned object, for IDE completion
$script .= "
*
- * @method $queryClass leftJoin(\$relation) Adds a LEFT JOIN clause to the query
- * @method $queryClass rightJoin(\$relation) Adds a RIGHT JOIN clause to the query
- * @method $queryClass innerJoin(\$relation) Adds a INNER JOIN clause to the query
+ * @method $queryClass leftJoin(\$relation) Adds a LEFT JOIN clause to the query
+ * @method $queryClass rightJoin(\$relation) Adds a RIGHT JOIN clause to the query
+ * @method $queryClass innerJoin(\$relation) Adds a INNER JOIN clause to the query
*";
// magic XXXjoinYYY() methods, for IDE completion
foreach ($this->getTable()->getForeignKeys() as $fk) {
$relationName = $this->getFKPhpNameAffix($fk);
$script .= "
- * @method $queryClass leftJoin" . $relationName . "(\$relationAlias = null) Adds a LEFT JOIN clause to the query using the " . $relationName . " relation
- * @method $queryClass rightJoin" . $relationName . "(\$relationAlias = null) Adds a RIGHT JOIN clause to the query using the " . $relationName . " relation
- * @method $queryClass innerJoin" . $relationName . "(\$relationAlias = null) Adds a INNER JOIN clause to the query using the " . $relationName . " relation
+ * @method $queryClass leftJoin" . $relationName . "(\$relationAlias = null) Adds a LEFT JOIN clause to the query using the " . $relationName . " relation
+ * @method $queryClass rightJoin" . $relationName . "(\$relationAlias = null) Adds a RIGHT JOIN clause to the query using the " . $relationName . " relation
+ * @method $queryClass innerJoin" . $relationName . "(\$relationAlias = null) Adds a INNER JOIN clause to the query using the " . $relationName . " relation
*";
}
foreach ($this->getTable()->getReferrers() as $refFK) {
$relationName = $this->getRefFKPhpNameAffix($refFK);
$script .= "
- * @method $queryClass leftJoin" . $relationName . "(\$relationAlias = null) Adds a LEFT JOIN clause to the query using the " . $relationName . " relation
- * @method $queryClass rightJoin" . $relationName . "(\$relationAlias = null) Adds a RIGHT JOIN clause to the query using the " . $relationName . " relation
- * @method $queryClass innerJoin" . $relationName . "(\$relationAlias = null) Adds a INNER JOIN clause to the query using the " . $relationName . " relation
+ * @method $queryClass leftJoin" . $relationName . "(\$relationAlias = null) Adds a LEFT JOIN clause to the query using the " . $relationName . " relation
+ * @method $queryClass rightJoin" . $relationName . "(\$relationAlias = null) Adds a RIGHT JOIN clause to the query using the " . $relationName . " relation
+ * @method $queryClass innerJoin" . $relationName . "(\$relationAlias = null) Adds a INNER JOIN clause to the query using the " . $relationName . " relation
*";
}
// override the signature of ModelCriteria::findOne() to specify the class of the returned object, for IDE completion
$script .= "
- * @method $modelClass findOne(PropelPDO \$con = null) Return the first $modelClass matching the query
- * @method $modelClass findOneOrCreate(PropelPDO \$con = null) Return the first $modelClass matching the query, or a new $modelClass object populated from the query conditions when no match is found
+ * @method $modelClass findOne(PropelPDO \$con = null) Return the first $modelClass matching the query
+ * @method $modelClass findOneOrCreate(PropelPDO \$con = null) Return the first $modelClass matching the query, or a new $modelClass object populated from the query conditions when no match is found
*";
// magic findBy() methods, for IDE completion
foreach ($this->getTable()->getColumns() as $column) {
$script .= "
- * @method $modelClass findOneBy" . $column->getPhpName() . "(" . $column->getPhpType() . " \$" . $column->getName() . ") Return the first $modelClass filtered by the " . $column->getName() . " column";
+ * @method $modelClass findOneBy" . $column->getPhpName() . "(" . $column->getPhpType() . " \$" . $column->getName() . ") Return the first $modelClass filtered by the " . $column->getName() . " column";
}
$script .= "
*";
foreach ($this->getTable()->getColumns() as $column) {
$script .= "
- * @method array findBy" . $column->getPhpName() . "(" . $column->getPhpType() . " \$" . $column->getName() . ") Return $modelClass objects filtered by the " . $column->getName() . " column";
+ * @method array findBy" . $column->getPhpName() . "(" . $column->getPhpType() . " \$" . $column->getName() . ") Return $modelClass objects filtered by the " . $column->getName() . " column";
}
- $script .= "
+
+ if ($this->getBuildProperty('addClassLevelComment')) {
+ $script .= "
*
- * @package propel.generator.".$this->getPackage()."
+ * @package propel.generator.".$this->getPackage();
+ }
+
+ $script .= "
*/
abstract class ".$this->getClassname()." extends " . $parentClass . "
-{
- ";
+{";
}
/**
@@ -218,7 +228,8 @@ protected function addClassBody(&$script)
protected function addClassClose(&$script)
{
$script .= "
-} // " . $this->getClassname() . "";
+}
+";
$this->applyBehaviorModifier('queryFilter', $script, "");
}
View
6 generator/lib/builder/util/XmlToAppData.php
@@ -61,10 +61,10 @@ class XmlToAppData
*/
public function __construct(PropelPlatformInterface $defaultPlatform = null, $defaultPackage = null, $encoding = 'iso-8859-1')
{
- $this->app = new AppData($defaultPlatform);
+ $this->app = new AppData($defaultPlatform);
$this->defaultPackage = $defaultPackage;
- $this->firstPass = true;
- $this->encoding = $encoding;
+ $this->firstPass = true;
+ $this->encoding = $encoding;
}
/**
View
4 generator/lib/config/QuickGeneratorConfig.php
@@ -10,7 +10,7 @@
require_once dirname(__FILE__) . '/GeneratorConfig.php';
require_once dirname(__FILE__) . '/GeneratorConfigInterface.php';
-require_once dirname(__FILE__) . '/../platform/DefaultPlatform.php';
+require_once dirname(__FILE__) . '/../platform/SqlitePlatform.php';
/**
*
@@ -156,7 +156,7 @@ public function setBuildProperty($name, $value)
*/
public function getConfiguredPlatform(PDO $con = null, $database = null)
{
- return new DefaultPlatform($con);
+ return new SqlitePlatform($con);
}
/**
View
15 generator/lib/model/Table.php
@@ -83,11 +83,18 @@ class Table extends ScopedElement implements IDMethod
private $idMethodParameters = array();
/**
- * Table name.
+ * Table name (with prefix if it has one).
*
* @var string
*/
private $commonName;
+
+ /**
+ * Table name without prefix. Only used for phpName generation.
+ *
+ * @var string
+ */
+ private $nonPrefixedName;
/**
* Table description.
@@ -302,6 +309,7 @@ class Table extends ScopedElement implements IDMethod
public function __construct($name = null)
{
$this->commonName = $name;
+ $this->nonPrefixedName = $name;
}
/**
@@ -312,9 +320,9 @@ public function __construct($name = null)
private function getStdSeparatedName()
{
if ($this->schema && $this->getBuildProperty('schemaAutoPrefix')) {
- return $this->schema . NameGenerator::STD_SEPARATOR_CHAR . $this->getCommonName();
+ return $this->schema . NameGenerator::STD_SEPARATOR_CHAR . $this->nonPrefixedName;
} else {
- return $this->getCommonName();
+ return $this->nonPrefixedName;
}
}
@@ -326,6 +334,7 @@ public function setupObject()
{
parent::setupObject();
$this->commonName = $this->getDatabase()->getTablePrefix() . $this->getAttribute("name");
+ $this->nonPrefixedName = $this->getAttribute('name');
// retrieves the method for converting from specified name to a PHP name.
$this->phpNamingMethod = $this->getAttribute("phpNamingMethod", $this->getDatabase()->getDefaultPhpNamingMethod());
View
23 generator/lib/platform/DefaultPlatform.php
@@ -72,9 +72,9 @@ public function getConnection()
/**
* Sets the GeneratorConfig to use in the parsing.
*
- * @param GeneratorConfig $config
+ * @param GeneratorConfigInterface $config
*/
- public function setGeneratorConfig(GeneratorConfig $config)
+ public function setGeneratorConfig(GeneratorConfigInterface $config)
{
// do nothing by default
}
@@ -322,23 +322,26 @@ public function getAddTableDDL(Table $table)
*/
public function getColumnDDL(Column $col)
{
- $domain = $col->getDomain();
-
- $ddl = array($this->quoteIdentifier($col->getName()));
+ $domain = $col->getDomain();
+ $ddl = array($this->quoteIdentifier($col->getName()));
$sqlType = $domain->getSqlType();
+
if ($this->hasSize($sqlType) && $col->isDefaultSqlType($this)) {
- $ddl []= $sqlType . $domain->printSize();
+ $ddl[] = $sqlType . $domain->printSize();
} else {
- $ddl []= $sqlType;
+ $ddl[] = $sqlType;
}
+
if ($default = $this->getColumnDefaultValueDDL($col)) {
- $ddl []= $default;
+ $ddl[] = $default;
}
+
if ($notNull = $this->getNullString($col->isNotNull())) {
- $ddl []= $notNull;
+ $ddl[] = $notNull;
}
+
if ($autoIncrement = $col->getAutoIncrementString()) {
- $ddl []= $autoIncrement;
+ $ddl[] = $autoIncrement;
}
return implode(' ', $ddl);
View
8 generator/lib/platform/MysqlPlatform.php
@@ -50,7 +50,7 @@ protected function initialize()
$this->setSchemaDomainMapping(new Domain(PropelTypes::ENUM, "TINYINT"));
}
- public function setGeneratorConfig(GeneratorConfig $generatorConfig)
+ public function setGeneratorConfig(GeneratorConfigInterface $generatorConfig)
{
if ($defaultTableEngine = $generatorConfig->getBuildProperty('mysqlTableType')) {
$this->defaultTableEngine = $defaultTableEngine;
@@ -586,12 +586,12 @@ public function getAddColumnDDLBits(Column $column)
$tableColumns = $column->getTable()->getColumns();
//default to add to top if the before-column cannot be found
- $insertPositionDDL = "FIRST";
+ $insertPositionDDL = "FIRST";
foreach($tableColumns as $i => $tableColumn) {
//we found the column, use the column before it, if its not the first
if ($tableColumn->getName() == $column->getName()) {
//we have a column that is not the first column
- if ($i>0) {
+ if ($i>0) {
$insertPositionDDL = "AFTER ".$this->quoteIdentifier($tableColumns[$i-1]->getName());
}
break;
@@ -619,7 +619,7 @@ public function getAddColumnsDDL($columns)
}
$lines[] = $this->getAddColumnDDLBits($column);
}
-
+
$pattern = "
ALTER TABLE %s
%s;
View
6 generator/lib/platform/PropelPlatformInterface.php
@@ -47,11 +47,11 @@ public function setConnection(PDO $con = null);
public function getConnection();
/**
- * Sets the GeneratorConfig which contains any generator build properties.
+ * Sets the GeneratorConfigInterface which contains any generator build properties.
*
- * @param GeneratorConfig $config
+ * @param GeneratorConfigInterface $config
*/
- public function setGeneratorConfig(GeneratorConfig $config);
+ public function setGeneratorConfig(GeneratorConfigInterface $config);
/**
* Returns the short name of the database type that this platform represents.
View
1 generator/lib/platform/SqlitePlatform.php
@@ -167,5 +167,4 @@ public function supportsMigrations()
{
return false;
}
-
}
View
6 generator/lib/util/PropelQuickBuilder.php
@@ -115,9 +115,9 @@ public function getDatabase()
{
if (null === $this->database) {
$xtad = new XmlToAppData($this->getPlatform());
- $appData = $xtad->parseString($this->schema);
- $appData->setGeneratorConfig($this->getConfig());
- $this->database = $appData->getDatabase(); // does final initialization
+ $xtad->setGeneratorConfig($this->getConfig());
+
+ $this->database = $xtad->parseString($this->schema)->getDatabase();
}
return $this->database;
View
2 runtime/lib/Propel.php
@@ -30,7 +30,7 @@ class Propel
/**
* The Propel version.
*/
- const VERSION = '1.6.7-dev';
+ const VERSION = '1.6.7';
/**
* A constant for <code>default</code>.
View
40 runtime/lib/collection/PropelObjectCollection.php
@@ -16,7 +16,6 @@
*/
class PropelObjectCollection extends PropelCollection
{
-
/**
* Save all the elements in the collection
*
@@ -317,4 +316,43 @@ public function populateRelation($relation, $criteria = null, $con = null)
return $relatedObjects;
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function search($element)
+ {
+ if ($element instanceof BaseObject) {
+ if (null !== $elt = $this->getIdenticalObject($element)) {
+ $element = $elt;
+ }
+ }
+
+ return parent::search($element);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function contains($element)
+ {
+ if ($element instanceof BaseObject) {
+ if (null !== $elt = $this->getIdenticalObject($element)) {
+ $element = $elt;
+ }
+ }
+
+ return parent::contains($element);
+ }
+
+ private function getIdenticalObject(BaseObject $object)
+ {
+ foreach ($this as $obj) {
+ if ($obj instanceof BaseObject && $obj->hashCode() === $object->hashCode()) {
+ return $obj;
+ }
+ }
+
+ return null;
+ }
}
View
111 runtime/lib/om/BaseObject.php
@@ -149,71 +149,79 @@ public function preSave(PropelPDO $con = null)
* Code to be run after persisting the object
* @param PropelPDO $con
*/
- public function postSave(PropelPDO $con = null) { }
-
- /**
- * Code to be run before inserting to database
- * @param PropelPDO $con
- * @return boolean
- */
- public function preInsert(PropelPDO $con = null)
- {
- return true;
- }
+ public function postSave(PropelPDO $con = null)
+ {
+ }
+
+ /**
+ * Code to be run before inserting to database
+ * @param PropelPDO $con
+ * @return boolean
+ */
+ public function preInsert(PropelPDO $con = null)
+ {
+ return true;
+ }
/**
* Code to be run after inserting to database
* @param PropelPDO $con
*/
- public function postInsert(PropelPDO $con = null) { }
+ public function postInsert(PropelPDO $con = null)
+ {
+ }
- /**
- * Code to be run before updating the object in database
- * @param PropelPDO $con
- * @return boolean
- */
- public function preUpdate(PropelPDO $con = null)
- {
- return true;
- }
+ /**
+ * Code to be run before updating the object in database
+ * @param PropelPDO $con
+ * @return boolean
+ */
+ public function preUpdate(PropelPDO $con = null)
+ {
+ return true;
+ }
/**
* Code to be run after updating the object in database
* @param PropelPDO $con
*/
- public function postUpdate(PropelPDO $con = null) { }
+ public function postUpdate(PropelPDO $con = null)
+ {
+ }
- /**
- * Code to be run before deleting the object in database
- * @param PropelPDO $con
- * @return boolean
- */
- public function preDelete(PropelPDO $con = null)
- {
- return true;
- }
+ /**
+ * Code to be run before deleting the object in database
+ * @param PropelPDO $con
+ * @return boolean
+ */
+ public function preDelete(PropelPDO $con = null)
+ {
+ return true;
+ }
/**
* Code to be run after deleting the object in database
* @param PropelPDO $con
*/
- public function postDelete(PropelPDO $con = null) { }
-
- /**
- * Sets the modified state for the object to be false.
- * @param string $col If supplied, only the specified column is reset.
- * @return void
- */
- public function resetModified($col = null)
- {
- if ($col !== null) {
- while (($offset = array_search($col, $this->modifiedColumns)) !== false) {
- array_splice($this->modifiedColumns, $offset, 1);
- }
- } else {
- $this->modifiedColumns = array();
+ public function postDelete(PropelPDO $con = null)
+ {
+ }
+
+ /**
+ * Sets the modified state for the object to be false.
+ * @param string $col If supplied, only the specified column is reset.
+ * @return void
+ */
+ public function resetModified($col = null)
+ {
+ if ($col !== null) {
+ while (($offset = array_search($col, $this->modifiedColumns)) !== false) {
+ array_splice($this->modifiedColumns, $offset, 1);
}
+ } else {
+ $this->modifiedColumns = array();
}
+ }
/**
* Compares this with another <code>BaseObject</code> instance. If
@@ -240,19 +248,18 @@ public function equals($obj)
}
/**
- * If the primary key is not <code>null</code>, return the hashcode of the
- * primary key. Otherwise calls <code>Object.hashCode()</code>.
+ * If the primary key is not null, return the hashcode of the
+ * primary key. Otherwise, return the hash code of the object.
*
* @return int Hashcode
*/
public function hashCode()
{
- $ok = $this->getPrimaryKey();
- if ($ok === null) {
- return crc32(serialize($this));
+ if (null !== $this->getPrimaryKey()) {
+ return crc32(serialize($this->getPrimaryKey()));
}
- return crc32(serialize($ok)); // serialize because it could be an array ("ComboKey")
+ return crc32(serialize($this));
}
/**
View
10 test/fixtures/generator/behavior/Foobar.php
@@ -0,0 +1,10 @@
+<?php
+namespace Foobar\Behavior;
+
+/**
+ * dummy class to test loading of namespaces behavior
+ */
+class Foobar extends \Behavior
+{
+
+}
View
6 test/testsuite/generator/behavior/DelegateBehaviorTest.php
@@ -258,10 +258,10 @@ public function testTablePrefixSameDatabase()
</database>
EOF;
PropelQuickBuilder::buildSchema($schema);
- $main = new FooTestTablePrefixSameDatabaseMain();
+ $main = new TestTablePrefixSameDatabaseMain();
$main->setSubtitle('bar');
- $delegate = $main->getFooTestTablePrefixSameDatabaseDelegate();
- $this->assertInstanceOf('FooTestTablePrefixSameDatabaseDelegate', $delegate);
+ $delegate = $main->getTestTablePrefixSameDatabaseDelegate();
+ $this->assertInstanceOf('TestTablePrefixSameDatabaseDelegate', $delegate);
$this->assertTrue($delegate->isNew());
$this->assertEquals('bar', $delegate->getSubtitle());
$this->assertEquals('bar', $main->getSubtitle());
View
32 test/testsuite/generator/behavior/NamespacedBehaviorTest.php
@@ -0,0 +1,32 @@
+<?php
+require_once __DIR__.'/../../../fixtures/generator/behavior/Foobar.php';
+
+class NamespacedBehaviorTest extends PHPUnit_Framework_TestCase
+{
+ /**
+ * test if issue 425 is resolved
+ */
+ public function testLoadBehavior()
+ {
+ $schema = <<< SCHEMA
+<database xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd"
+ name="default" defaultIdMethod="native">
+ <table name="dummyTable">
+ <behavior name="foobar"/>
+ <column name="dummyField1" type="char" size="36" required="true" primaryKey="true" />
+ <column name="dummyField2" type="integer" required="true" />
+ </table>
+</database>
+SCHEMA;
+
+ $generatorConfig = new \QuickGeneratorConfig();
+ $generatorConfig->setBuildProperty('behaviorFoobarClass','Foobar\\Behavior\\Foobar');
+ $builder = new \PropelQuickBuilder();
+ $builder->setConfig($generatorConfig);
+ $builder->setSchema($schema);
+ $builder->build();
+
+ $this->assertTrue(class_exists('DummyTable'),'dummy table class is correctly generated');
+ }
+}
View
16 test/testsuite/generator/model/TableTest.php
@@ -468,4 +468,20 @@ public function testIsCrossRefAttribute()
$table3 = $db->getTable("table_is_cross_ref_false");
$this->assertFalse($table3->getIsCrossRef());
}
+
+ public function testPrefixDoesntAffectPhpName () {
+ $xmlToAppData = new XmlToAppData();
+ $schema = <<<EOF
+<database name="test1" tablePrefix="pf_">
+ <table name="table1">
+ <column name="id" type="INTEGER" primaryKey="true" />
+ </table>
+</database>
+EOF;
+ $appData = $xmlToAppData->parseString($schema);
+
+ $table = $appData->getDatabase('test1')->getTable('pf_table1');
+
+ $this->assertEquals('Table1', $table->getPhpName());
+ }
}
View
2 test/testsuite/runtime/collection/PropelCollectionTest.php
@@ -405,7 +405,7 @@ public function testDiffWithNonEmptyCollectionReturnsObjectsInTheFirstCollection
$result = $col1->diff($col2);
$this->assertInstanceOf('PropelCollection', $result);
- $this->assertEquals(1, count($result));
+ $this->assertCount(1, $result);
$this->assertSame($b1, $result[0]);
}
View
113 test/testsuite/runtime/collection/PropelObjectCollectionTest.php
@@ -170,4 +170,117 @@ public function testToKeyValue()
9012 => 'Don Juan',
), $coll->toKeyValue(array('Author', 'Books', 'First', 'Id'), 'Title'));
}
+
+ public function testContainsWithNoPersistentElements()
+ {
+ $col = new PropelObjectCollection();
+ $this->assertFalse($col->contains('foo_1'), 'contains() returns false on an empty collection');
+ $data = array('bar1', 'bar2', 'bar3');
+ $col = new PropelObjectCollection($data);
+ $this->assertTrue($col->contains('bar1'), 'contains() returns true when the key exists');
+ $this->assertFalse($col->contains('bar4'), 'contains() returns false when the key does not exist');
+ }
+
+ public function testSearchWithNoPersistentElements()
+ {
+ $col = new PropelObjectCollection();
+ $this->assertFalse($col->search('bar1'), 'search() returns false on an empty collection');
+ $data = array('bar1', 'bar2', 'bar3');
+ $col = new PropelObjectCollection($data);
+ $this->assertEquals(1, $col->search('bar2'), 'search() returns the key when the element exists');
+ $this->assertFalse($col->search('bar4'), 'search() returns false when the element does not exist');
+ }
+
+ public function testContainsWithClassicBehavior()
+ {
+ $col = new PropelObjectCollection();
+ $b1 = new Book();
+ $b1->setTitle('Bar');
+ $b2 = new Book();
+ $b2->setTitle('Foo');
+
+ $this->assertFalse($col->contains($b1), 'contains() returns false on an empty collection');
+
+ $col = new PropelObjectCollection(array($b1));
+
+ $this->assertTrue($col->contains($b1), 'contains() returns true when the key exists');
+ $this->assertFalse($col->contains($b2), 'contains() returns false when the key does not exist');
+ }
+
+ public function testSearchWithClassicBehavior()
+ {
+ $col = new PropelObjectCollection();
+ $b1 = new Book();
+ $b1->setTitle('Bar');
+ $b2 = new Book();
+ $b2->setTitle('Foo');
+
+ $this->assertFalse($col->search($b1), 'search() returns false on an empty collection');
+
+ $col = new PropelObjectCollection(array($b1));
+ $this->assertEquals(0, $col->search($b1), 'search() returns the key when the element exists');
+ $this->assertFalse($col->search($b2), 'search() returns false when the element does not exist');
+ }
+
+ public function testContainsMatchesSimilarObjects()
+ {
+ $col = new PropelObjectCollection();
+ $b1 = new Book();
+ $b1->setTitle('Bar');
+ $b1->save();
+
+ $b2 = clone $b1;
+
+ $this->assertFalse($col->contains($b1), 'contains() returns false on an empty collection');
+
+ $col = new PropelObjectCollection(array($b1));
+
+ $this->assertTrue($col->contains($b1));
+ $this->assertTrue($col->contains($b2));
+ }
+
+ public function testSearchMatchesSimilarObjects()
+ {
+ $col = new PropelObjectCollection();
+ $b1 = new Book();
+ $b1->setTitle('Bar');
+ $b1->save();
+
+ $b2 = clone $b1;
+
+ $this->assertFalse($col->search($b1), 'search() returns false on an empty collection');
+
+ $col = new PropelObjectCollection(array($b1));
+ $this->assertTrue(0 === $col->search($b1));
+ $this->assertTrue(0 === $col->search($b2));
+ }
+
+ public function testContainsMatchesSimilarNewObjects()
+ {
+ $col = new PropelObjectCollection();
+ $b1 = new Book();
+ $b1->setTitle('Bar');
+ $b2 = clone $b1;
+
+ $this->assertFalse($col->contains($b1), 'contains() returns false on an empty collection');
+
+ $col = new PropelObjectCollection(array($b1));
+
+ $this->assertTrue($col->contains($b1));
+ $this->assertTrue($col->contains($b2));
+ }
+
+ public function testSearchMatchesSimilarNewObjects()
+ {
+ $col = new PropelObjectCollection();
+ $b1 = new Book();
+ $b1->setTitle('Bar');
+ $b2 = clone $b1;
+
+ $this->assertFalse($col->search($b1), 'search() returns false on an empty collection');
+
+ $col = new PropelObjectCollection(array($b1));
+ $this->assertTrue(0 === $col->search($b1));
+ $this->assertTrue(0 === $col->search($b2));
+ }
}

0 comments on commit 2423506

Please sign in to comment.
Something went wrong with that request. Please try again.