Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Commit

Permalink
Merge 1e7040b into 782620b
Browse files Browse the repository at this point in the history
  • Loading branch information
liuggio committed Jun 26, 2013
2 parents 782620b + 1e7040b commit e74594b
Show file tree
Hide file tree
Showing 21 changed files with 263 additions and 150 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"phpmd/phpmd": "1.4.*",
"squizlabs/php_codesniffer": "1.4.*",
"zendframework/zend-stdlib": "2.*",
"satooshi/php-coveralls": "~0.6"
"satooshi/php-coveralls": "~0.6",
"pimple/pimple": "1.0.*"
},
"autoload": {
"psr-0": {
Expand Down
5 changes: 3 additions & 2 deletions src/ChangeSet/Change.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ class Change
{
private $object;
private $snapshot;

public function __construct($object, $compute = false)
{
$this->object = $object;

if ($compute) {
$this->snapshot = (array) $this->object;
$this->snapshot = (array)$this->object;
}
}

public function isDirty()
{
if (isset($this->snapshot)) {
return $this->snapshot !== (array) $this->object;
return $this->snapshot !== (array)$this->object;
}

// No need to compute - we don't have a snapshot
Expand Down
4 changes: 2 additions & 2 deletions src/ChangeSet/ChangeSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public function remove($object)
public function isTracking($object)
{
return isset($this->managedInstances[$object])
|| isset($this->newInstances[$object])
|| isset($this->removedInstances[$object]); // maybe should not check this?
|| isset($this->newInstances[$object])
|| isset($this->removedInstances[$object]); // maybe should not check this?
}

public function clean()
Expand Down
3 changes: 2 additions & 1 deletion src/ChangeSet/ChangeSetListener/IdentityMapSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use Zend\EventManager\EventInterface;
use ChangeSet\IdentityMap\IdentityMapInterface;

class IdentityMapSynchronizer extends AbstractListenerAggregate
class IdentityMapSynchronizer extends AbstractListenerAggregate implements IdentityMapSynchronizerInterface
{
public function __construct(IdentityMapInterface $identityMap)
{
$this->identityMap = $identityMap;
}

public function attach(EventManagerInterface $eventManager)
{
$this->listeners[] = $eventManager->attach('add', array($this, 'addToIdentityMap'));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace ChangeSet\ChangeSetListener;

use Zend\EventManager\EventInterface;

Interface IdentityMapSynchronizerInterface
{
public function addToIdentityMap(EventInterface $event);

public function removeFromIdentityMap(EventInterface $event);
}
15 changes: 8 additions & 7 deletions src/ChangeSet/Committer/SimpleLoggingCommitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@
class SimpleLoggingCommitter implements CommitterInterface
{
public $operations = array();

public function commit(ChangeSet $changeSet)
{
$this->operations = array();

foreach ($changeSet->getNew() as $insert) {
$this->addChange('insert', $insert);
$this->addChange('insert', $insert);
}

foreach ($changeSet->getChangedManaged() as $update) {
$this->addChange('update', $update);
$this->addChange('update', $update);
}

foreach ($changeSet->getRemoved() as $delete) {
$this->addChange('delete', $delete);
$this->addChange('delete', $delete);
}
}

private function addChange($type, $object)
{
$this->operations[] = array(
Expand Down
9 changes: 9 additions & 0 deletions src/ChangeSet/Container/Container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace ChangeSet\Container;

use Pimple;

class Container extends Pimple
{
}
14 changes: 14 additions & 0 deletions src/ChangeSet/Container/IdentityExtractorContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace ChangeSet\Container;

use Pimple;

class IdentityExtractorContainer extends Pimple implements IdentityExtractorContainerInterface
{

public function getExtractor($className)
{
return $this[$className];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace ChangeSet\Container;

Interface IdentityExtractorContainerInterface
{

public function getExtractor($className);
}
14 changes: 14 additions & 0 deletions src/ChangeSet/Container/RepositoryContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace ChangeSet\Container;

use Pimple;

class RepositoryContainer extends Pimple implements RepositoryContainerInterface
{

public function getObjectRepository($className)
{
return $this[$className];
}
}
9 changes: 9 additions & 0 deletions src/ChangeSet/Container/RepositoryContainerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace ChangeSet\Container;

Interface RepositoryContainerInterface
{

public function getObjectRepository($className);
}
12 changes: 0 additions & 12 deletions src/ChangeSet/IdentityExtractor/IdentityExtractorFactory.php

This file was deleted.

11 changes: 5 additions & 6 deletions src/ChangeSet/IdentityMap/IdentityMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ChangeSet\IdentityMap;

use ChangeSet\IdentityExtractor\IdentityExtractorFactory;
use ChangeSet\Container\IdentityExtractorContainerInterface;
use SplObjectStorage;

// @todo implement collection interfaces?
Expand All @@ -12,9 +12,9 @@ class IdentityMap implements IdentityMapInterface
private $objects;
private $identityExtractorFactory;

public function __construct()
public function __construct(IdentityExtractorContainerInterface $IdentityExtractorFactory)
{
$this->identityExtractorFactory = new IdentityExtractorFactory();
$this->identityExtractorFactory = $IdentityExtractorFactory;
$this->objects = new SplObjectStorage();
}

Expand All @@ -27,7 +27,7 @@ public function add($object)
->getEncodedIdentifier($object);

if (null !== $id) {
$success = ! isset($this->map[$id]);
$success = !isset($this->map[$id]);
$this->map[$id] = $object;
$this->objects[$object] = $id;

Expand All @@ -39,7 +39,7 @@ public function add($object)

public function remove($object)
{
if (! isset($this->objects[$object])) {
if (!isset($this->objects[$object])) {
return false;
}

Expand All @@ -50,7 +50,6 @@ public function remove($object)

public function get($className, $id)
{
// @todo reuse the identity extractor here!
$hash = $this
->identityExtractorFactory
->getExtractor($className)
Expand Down
20 changes: 0 additions & 20 deletions src/ChangeSet/ObjectLoader/ObjectLoaderFactory.php

This file was deleted.

1 change: 1 addition & 0 deletions src/ChangeSet/ObjectLoader/SimpleObjectLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class SimpleObjectLoader implements ObjectLoaderInterface
{
private $unitOfWork;

public function __construct(UnitOfWorkInterface $unitOfWork)
{
$this->unitOfWork = $unitOfWork;
Expand Down
8 changes: 4 additions & 4 deletions src/ChangeSet/ObjectManager/SimpleObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

namespace ChangeSet\ObjectManager;

use ChangeSet\ObjectRepository\ObjectRepositoryFactory;
use ChangeSet\Container\RepositoryContainerInterface;

class SimpleObjectManager implements ObjectManagerInterface
{
protected $objectRepositoryFactory;

public function __construct(ObjectRepositoryFactory $objectRepositoryFactory)
public function __construct(RepositoryContainerInterface $objectRepositoryFactory)
{
$this->objectRepositoryFactory = $objectRepositoryFactory;
$this->repositoryContainer = $objectRepositoryFactory;
}

public function getRepository($className)
{
return $this->objectRepositoryFactory->getObjectRepository($className);
return $this->repositoryContainer->getObjectRepository($className);
}

public function flush()
Expand Down
53 changes: 53 additions & 0 deletions src/ChangeSet/ObjectRepository/ObjectRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace ChangeSet\ObjectRepository;

use ChangeSet\UnitOfWork\UnitOfWorkInterface;
use ChangeSet\ObjectLoader\ObjectLoaderInterface;
use ChangeSet\IdentityMap\IdentityMapInterface;
use ChangeSet\ObjectRepository\ObjectRepositoryInterface;

abstract class ObjectRepository implements ObjectRepositoryInterface
{
protected $unitOfWork;
protected $objectLoader;
protected $identityMap;
protected $entityClassName;

public function __construct(
UnitOfWorkInterface $unitOfWork,
ObjectLoaderInterface $objectLoader,
IdentityMapInterface $identityMap,
$entityClassName
)
{
$this->unitOfWork = $unitOfWork;
$this->objectLoader = $objectLoader;
$this->identityMap = $identityMap;
$this->entityClassName = $entityClassName;
}

abstract public function add($object);

abstract public function remove($object);

abstract public function get($id);

abstract public function getReference($id);

/**
* @param mixed $entityClassName
*/
public function setEntityClassName($entityClassName)
{
$this->entityClassName = $entityClassName;
}

/**
* @return mixed
*/
public function getEntityClassName()
{
return $this->entityClassName;
}
}
32 changes: 0 additions & 32 deletions src/ChangeSet/ObjectRepository/ObjectRepositoryFactory.php

This file was deleted.

17 changes: 2 additions & 15 deletions src/ChangeSet/ObjectRepository/SimpleObjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,12 @@

namespace ChangeSet\ObjectRepository;

use ChangeSet\UnitOfWork\UnitOfWorkInterface;
use ChangeSet\ObjectLoader\ObjectLoaderInterface;
use ChangeSet\UnitOfWork\UnitOfWorkInterface;
use ChangeSet\IdentityMap\IdentityMapInterface;

class SimpleObjectRepository implements ObjectRepositoryInterface
class SimpleObjectRepository extends ObjectRepository implements ObjectRepositoryInterface
{
protected $unitOfWork;
protected $objectLoader;
protected $identityMap;
public function __construct(
UnitOfWorkInterface $unitOfWork,
ObjectLoaderInterface $objectLoader,
IdentityMapInterface $identityMap
) {
$this->unitOfWork = $unitOfWork;
$this->objectLoader = $objectLoader;
$this->identityMap = $identityMap;
}

public function add($object)
{
$this->unitOfWork->registerNew($object);
Expand Down

0 comments on commit e74594b

Please sign in to comment.