Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Introducing data-mapper and unit of work. #795

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
620d2f0
Implemented data-mapper.
Oct 12, 2014
3de3c4b
Implemented roughly working update mechanism
Nov 3, 2014
fef250a
implemented lazy loading for non-relation fields
Nov 5, 2014
2895c80
More CrossRelation stuff
Nov 18, 2014
4add32d
More componenents.
marcj Dec 12, 2014
3509bff
More stuff.
marcj Jan 3, 2015
40fe9ca
more tests green
marcj Jan 4, 2015
a10e4bd
more tests green
marcj Jan 4, 2015
d406816
Started converting Sortable to new Component system.
marcj Jan 18, 2015
b88b3ca
backup
marcj Feb 26, 2015
e3c88e4
More stuff
marcj May 8, 2015
3cace39
fixed issue with having two or more relations on the same local column
marcj May 10, 2015
4b95472
Added filterByPrimaryKeys, useQuery and correct join methods to query…
marcj May 11, 2015
bf4ff82
Made AggregateFieldBehavior more workable and thus some tests green.
marcj May 12, 2015
6df10dc
Added nested sessions, to allow using a session in its events again. …
marcj May 25, 2015
39bb204
made first AggregateField tests green
marcj May 30, 2015
0db9e6e
made all AggregateField tests green, fixed SqlitePlatform name genera…
marcj Jun 4, 2015
7bb1a9e
Added SQLite support. Started with converting Archiveable behavior.
marcj Jun 6, 2015
cbf5baf
Added Archiveable support and made SchemaReader support the old schema
marcj Jun 7, 2015
31c5508
Made almost 10% test suite green. Started with implementing concrete …
marcj Jun 16, 2015
be30308
More concrete inheritance fixes
marcj Jun 17, 2015
bc9ea26
removed debugging stuff
marcj Jun 17, 2015
25d5ec2
Fixed ConcreteInheritanceTest, extracted Repository behavior hooks in…
marcj Jun 17, 2015
2b0a007
Made concrete inheritance tests completely green
marcj Jun 17, 2015
ecb97cc
Started with implementing delegateBehavior
marcj Jun 17, 2015
943e2a3
Fixed DelegateBehavior tests
marcj Jun 18, 2015
741da41
Allow inserting custom auto-increment if allowed.
marcj Jun 19, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions UPDATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ The generated model is automatically updated once you rebuild your model.
The classes used by Propel internally to build the object model were renamed. This affects your project if you extended one of these classes.

Replace... With...
OMBuilder.php AbstractOMBuilder.php
ObjectBuilder.php AbstractObjectBuilder.php
OMBuilder.php AbstractBuilder.php
ObjectBuilder.php __removed__
PeerBuilder.php __removed__
PHP5ExtensionObjectBuilder.php ExtensionObjectBuilder.php
PHP5ExtensionPeerBuilder.php __removed__
Expand Down
2 changes: 1 addition & 1 deletion autoload.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ if (file_exists($file = __DIR__.'/vendor/autoload.php')) {
$loader->add('Propel\Tests', array(
__DIR__ . '/tests',
__DIR__ . '/tests/Fixtures/bookstore/build/classes',
__DIR__ . '/tests/Fixtures/bookstore-packaged/build/classes',
__DIR__ . '/tests/Fixtures/schemas/build/classes',
__DIR__ . '/tests/Fixtures/quoting/build/classes'
));
$loader->register();
} elseif (file_exists($file = __DIR__ . '/vendor/Symfony/Component/ClassLoader/UniversalClassLoader.php')) {
require_once $file;

Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
"symfony/finder": "~2.3",
"symfony/validator": "~2.3",
"symfony/filesystem": "~2.3",
"symfony/event-dispatcher": "~2.3",
"symfony/config": "~2.3",
"psr/log": "~1.0"
"psr/log": "~1.0",
"gossi/php-code-generator": "dev-master",
"mustache/mustache": "~2.6"
},
"require-dev": {
"behat/behat": "~2.4",
Expand All @@ -36,6 +39,9 @@
"autoload": {
"psr-0": {
"Propel": "src/"
},
"psr-4": {
"MJS\\TopSort\\": "/Users/marc/bude/topsort/src/"
}
},
"bin": [
Expand Down
40 changes: 19 additions & 21 deletions resources/dtd/database.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ PHP class or method name.
to lowercase.
-->

<!ELEMENT database (external-schema*, table+, behavior*)>
<!ELEMENT database (external-schema*, entity+, behavior*)>
<!ATTLIST database
name CDATA #IMPLIED
defaultIdMethod (native|none) "none"
Expand All @@ -47,10 +47,10 @@ PHP class or method name.
note: the interface="true", requires that useManagers=true in the
properties file.
-->
<!ELEMENT table (column+,(foreign-key|index|unique|id-method-parameter|behavior|vendor)*)>
<!ATTLIST table
<!ELEMENT entity (field+,(relation|index|unique|id-method-parameter|behavior|vendor)*)>
<!ATTLIST entity
name CDATA #REQUIRED
phpName CDATA #IMPLIED
tableName CDATA #IMPLIED
idMethod (native|autoincrement|sequence|none|null) "null"
skipSql (true|false) "false"
readOnly (true|false) "false"
Expand All @@ -63,7 +63,7 @@ PHP class or method name.
baseClass CDATA #IMPLIED
alias CDATA #IMPLIED
interface CDATA #IMPLIED
phpNamingMethod (nochange|underscore|phpname) #IMPLIED
tableNamingMethod (nochange|underscore|phpname) #IMPLIED
heavyIndexing (true|false) #IMPLIED
identifierQuoting (true|false) #IMPLIED
description CDATA #IMPLIED
Expand All @@ -76,11 +76,9 @@ PHP class or method name.
value CDATA #REQUIRED
>

<!ELEMENT column ((inheritance|vendor)*)>
<!ATTLIST column
<!ELEMENT field ((inheritance|vendor)*)>
<!ATTLIST field
name CDATA #REQUIRED
phpName CDATA #IMPLIED
tableMapName CDATA #IMPLIED
primaryKey (true|false) "false"
required (true|false) "false"
type
Expand Down Expand Up @@ -116,13 +114,13 @@ PHP class or method name.
extends CDATA #IMPLIED
>

<!ELEMENT foreign-key (reference+, vendor*)>
<!ATTLIST foreign-key
foreignTable CDATA #REQUIRED
foreignSchema CDATA #IMPLIED
<!ELEMENT relation (reference*, vendor*)>
<!ATTLIST relation
target CDATA #REQUIRED
field CDATA #IMPLIED
name CDATA #IMPLIED
phpName CDATA #IMPLIED
refPhpName CDATA #IMPLIED
refFieldName CDATA #IMPLIED
refName CDATA #IMPLIED
onUpdate (CASCADE|cascade|SETNULL|setnull|RESTRICT|restrict|NONE|none) "none"
onDelete (CASCADE|cascade|SETNULL|setnull|RESTRICT|restrict|NONE|none) "none"
skipSql (true|false) "false"
Expand All @@ -134,7 +132,7 @@ PHP class or method name.
foreign CDATA #REQUIRED
>

<!ELEMENT index (index-column+,vendor*)>
<!ELEMENT index (index-field+,vendor*)>
<!ATTLIST index
name CDATA #IMPLIED
>
Expand All @@ -144,19 +142,19 @@ PHP class or method name.
name CDATA #IMPLIED
>

<!ELEMENT index-column (vendor*)>
<!ATTLIST index-column
<!ELEMENT index-field (vendor*)>
<!ATTLIST index-field
name CDATA #REQUIRED
size CDATA #IMPLIED
>

<!ELEMENT unique (unique-column+)>
<!ELEMENT unique (unique-field+)>
<!ATTLIST unique
name CDATA #IMPLIED
>

<!ELEMENT unique-column (vendor*)>
<!ATTLIST unique-column
<!ELEMENT unique-field (vendor*)>
<!ATTLIST unique-field
name CDATA #REQUIRED
>

Expand Down
16 changes: 8 additions & 8 deletions src/Propel/Common/Config/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public function getSection($section)
* is expressed by:
* <code>'database.adapter.mysql.tableType</code>
*
* @param $name The name of property, expressed as a dot separated level hierarchy
* @throws Propel\Common\Config\Exception\InvalidArgumentException
* @param string $name The name of property, expressed as a dot separated level hierarchy
* @throws \Propel\Common\Config\Exception\InvalidArgumentException
* @return mixed The configuration property
*/
public function getConfigProperty($name)
Expand Down Expand Up @@ -164,16 +164,16 @@ protected function load($fileName, $extraConf)
$finder->in($dirs)->depth(0)->files()->name($fileName . '.{php,inc,ini,properties,yaml,yml,xml,json}');
$files = iterator_to_array($finder);

$distfinder = new Finder();
$distfinder->in($dirs)->depth(0)->files()->name($fileName . '.{php,inc,ini,properties,yaml,yml,xml,json}.dist');
$distfiles = iterator_to_array($distfinder);
$distFinder = new Finder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO you should try to avoid such kind of CS changes.. the diff will be already huge and hard to review because of the changes in a lot of places all over the lib

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO some few CS changes shouldn't hurt in a PR that has several ten thousand line changes.

$distFinder->in($dirs)->depth(0)->files()->name($fileName . '.{php,inc,ini,properties,yaml,yml,xml,json}.dist');
$distFiles = iterator_to_array($distFinder);

$numFiles = count($files);
$numDistFiles = count($distfiles);
$numDistFiles = count($distFiles);

//allow to load only .dist file
if (0 === $numFiles && 1 === $numDistFiles) {
$files = $distfiles;
$files = $distFiles;
$numFiles = 1;
}

Expand Down Expand Up @@ -212,7 +212,7 @@ protected function load($fileName, $extraConf)
protected function process($extraConf = null)
{
if (null === $extraConf && count($this->config) <= 0) {
return null;
return;
}

$processor = new Processor();
Expand Down
17 changes: 9 additions & 8 deletions src/Propel/Common/Config/PropelConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected function addRuntimeSection(ArrayNodeDefinition $node)
->addDefaultsIfNotSet()
->fixXmlConfig('connection')
->children()
->scalarNode('defaultConnection')->isRequired()->end()
->scalarNode('defaultConnection')->defaultValue('default')->end()
->arrayNode('connections')
->prototype('scalar')->end()
->end()
Expand Down Expand Up @@ -283,8 +283,6 @@ protected function addGeneratorSection(ArrayNodeDefinition $node)
->fixXmlConfig('connection')
->children()
->scalarNode('defaultConnection')->isRequired()->end()
->scalarNode('tablePrefix')->end()
->scalarNode('platformClass')->defaultValue('\\Propel\\Generator\\Platform\\MysqlPlatform')->end()
->scalarNode('targetPackage')->end()
->booleanNode('packageObjectModel')->defaultTrue()->end()
->booleanNode('namespaceAutoPackage')->defaultTrue()->end()
Expand Down Expand Up @@ -330,14 +328,17 @@ protected function addGeneratorSection(ArrayNodeDefinition $node)
->addDefaultsIfNotSet()
->children()
->scalarNode('object')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\ObjectBuilder')->end()
->scalarNode('objectstub')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\ExtensionObjectBuilder')->end()
->scalarNode('activerecordtrait')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\ActiveRecordTraitBuilder')->end()
->scalarNode('objectmultiextend')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\MultiExtendObjectBuilder')->end()
->scalarNode('repository')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\RepositoryBuilder')->end()
->scalarNode('repositorystub')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\StubRepositoryBuilder')->end()
->scalarNode('query')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\QueryBuilder')->end()
->scalarNode('querystub')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\ExtensionQueryBuilder')->end()
->scalarNode('proxy')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\ProxyBuilder')->end()
->scalarNode('querystub')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\StubQueryBuilder')->end()
->scalarNode('queryinheritance')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\QueryInheritanceBuilder')->end()
->scalarNode('queryinheritancestub')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\ExtensionQueryInheritanceBuilder')->end()
->scalarNode('tablemap')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\TableMapBuilder')->end()
->scalarNode('interface')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\InterfaceBuilder')->end()
->scalarNode('queryinheritancestub')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\StubQueryInheritanceBuilder')->end()
->scalarNode('inheritanceentitymap')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\EntityMapInheritanceBuilder')->end()
->scalarNode('entitymap')->cannotBeEmpty()->defaultValue('\Propel\Generator\Builder\Om\EntityMapBuilder')->end()
->scalarNode('datasql')->cannotBeEmpty()->end()
->end()
->end()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
* @license MIT License
*/

namespace Propel\Generator\Behavior\AggregateColumn;
namespace Propel\Generator\Behavior\AggregateField;

use Propel\Generator\Builder\Om\ObjectBuilder;
use Propel\Generator\Builder\Om\AbstractBuilder;
use Propel\Generator\Model\Behavior;

/**
* Keeps an aggregate column updated with related table
*
* @author François Zaninotto
*/
class AggregateColumnBehavior extends Behavior
class AggregateFieldBehavior extends Behavior
{
// default parameters value
protected $parameters = array(
'name' => null,
'expression' => null,
'condition' => null,
'foreign_table' => null,
'foreign_entity' => null,
'foreign_schema' => null,
);

Expand Down Expand Up @@ -64,13 +64,13 @@ public function modifyTable()
$relationBehavior->setName('aggregate_column_relation');
$relationBehavior->setId('aggregate_column_relation_'.$this->getId());
$relationBehavior->addParameter(array('name' => 'foreign_table', 'value' => $table->getName()));
$relationBehavior->addParameter(array('name' => 'aggregate_name', 'value' => $this->getColumn()->getPhpName()));
$relationBehavior->addParameter(array('name' => 'update_method', 'value' => 'update' . $this->getColumn()->getPhpName()));
$relationBehavior->addParameter(array('name' => 'aggregate_name', 'value' => $this->getColumn()->getName()));
$relationBehavior->addParameter(array('name' => 'update_method', 'value' => 'update' . $this->getColumn()->getName()));
$foreignTable->addBehavior($relationBehavior);
}
}

public function objectMethods(ObjectBuilder $builder)
public function objectMethods(AbstractBuilder $builder)
{
if (!$this->getParameter('foreign_table')) {
throw new \InvalidArgumentException(sprintf('You must define a \'foreign_table\' parameter for the \'aggregate_column\' behavior in the \'%s\' table', $this->getTable()->getName()));
Expand All @@ -86,7 +86,7 @@ public function objectMethods(ObjectBuilder $builder)
* @param ObjectBuilder $builder
* @return string
*/
protected function addObjectCompute(ObjectBuilder $builder)
protected function addObjectCompute(AbstractBuilder $builder)
{
$conditions = array();
if ($this->getParameter('condition')) {
Expand All @@ -97,7 +97,7 @@ protected function addObjectCompute(ObjectBuilder $builder)
$database = $this->getTable()->getDatabase();
foreach ($this->getForeignKey()->getColumnObjectsMapping() as $index => $columnReference) {
$conditions[] = $columnReference['local']->getFullyQualifiedName() . ' = :p' . ($index + 1);
$bindings[$index + 1] = $columnReference['foreign']->getPhpName();
$bindings[$index + 1] = $columnReference['foreign']->getName();
}
$tableName = $database->getTablePrefix() . $this->getParameter('foreign_table');
if ($database->getPlatform()->supportsSchemas() && $this->getParameter('foreign_schema')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @license MIT License
*/

namespace Propel\Generator\Behavior\AggregateColumn;
namespace Propel\Generator\Behavior\AggregateField;

use Propel\Generator\Model\Behavior;

Expand All @@ -17,11 +17,11 @@
*
* @author François Zaninotto
*/
class AggregateColumnRelationBehavior extends Behavior
class AggregateFieldRelationBehavior extends Behavior
{
// default parameters value
protected $parameters = array(
'foreign_table' => '',
'foreign_entity' => '',
'update_method' => '',
'aggregate_name' => '',
);
Expand Down Expand Up @@ -140,7 +140,7 @@ protected function addQueryFindRelated($builder)
$relationName = $this->getRelationName($builder);

$builder->declareClassNamespace(
$foreignKey->getForeignTable()->getPhpName() . 'Query',
$foreignKey->getForeignTable()->getName() . 'Query',
$foreignKey->getForeignTable()->getNamespace()
);

Expand Down Expand Up @@ -168,7 +168,7 @@ protected function addQueryUpdateRelated($builder)

protected function getForeignTable()
{
return $this->getTable()->getDatabase()->getTable($this->getParameter('foreign_table'));
return $this->getEntity()->getDatabase()->getEntity($this->getParameter('foreign_entity'));
}

protected function getForeignKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @return mixed The scalar result from the aggregate query
*/
public function compute<?=$column->getPhpName()?>(ConnectionInterface $con)
public function compute<?=$column->getName()?>(ConnectionInterface $con)
{
$stmt = $con->prepare('<?=$sql?>');
<?php foreach ($bindings as $key => $binding):?>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

/**
* Updates the aggregate column <?=$column->getName()?>
*
* @param ConnectionInterface $con A connection object
*/
public function update<?=$column->getName()?>(ConnectionInterface $con)
{
$this->set<?=$column->getName()?>($this->compute<?=$column->getName()?>($con));
$this->save($con);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/**
* Finds the related <?=$foreignTable->getPhpName()?> objects and keep them for later
* Finds the related <?=$foreignTable->getName()?> objects and keep them for later
*
* @param ConnectionInterface $con A connection object
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function archive(ConnectionInterface $con = null)
}
$this->copyInto($archive, $deepCopy = false, $makeNew = false);
<?php if ($archivedAtColumn): ?>
$archive->set<?php echo $archivedAtColumn->getPhpName() ?>(time());
$archive->set<?php echo $archivedAtColumn->getName() ?>(time());
<?php endif; ?>
$archive->save(<?php if (!$hasArchiveClass): ?>$con<?php endif; ?>);

Expand Down
Loading