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
!!! TASK: Rework AbstractDoctrineProjection for composibility & expli… #137
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,111 +12,85 @@ | |
*/ | ||
|
||
use Neos\EventSourcing\Exception; | ||
use Neos\EventSourcing\Projection\AbstractBaseProjector; | ||
use Neos\EventSourcing\Projection\ProjectorInterface; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* A base class for Doctrine-based projectors | ||
* | ||
* @api | ||
*/ | ||
abstract class AbstractDoctrineProjector extends AbstractBaseProjector | ||
abstract class AbstractDoctrineProjector implements ProjectorInterface | ||
{ | ||
/** | ||
* @Flow\Inject | ||
* @var DoctrineProjectionPersistenceManager | ||
* @var DoctrineProjectionState | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guess this could be removed then |
||
*/ | ||
protected $projectionPersistenceManager; | ||
|
||
/** | ||
* Initialize the Read Model class name | ||
* Make sure to call this method as parent when overriding it in a concrete projector. | ||
* | ||
* @return void | ||
* @throws Exception | ||
*/ | ||
protected function initializeObject() | ||
{ | ||
if ($this->readModelClassName === null) { | ||
if (substr(get_class($this), -9, 9) !== 'Projector') { | ||
throw new Exception(sprintf('The class name "%s" doesn\'t end in "Projector" so the Read Model class name can\'t be determined automatically. Please set the "readModelClassName" field it in your concrete projector.', get_class($this)), 1476799474); | ||
} | ||
$this->readModelClassName = substr(get_class($this), 0, -9); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code moved a few lines down |
||
} | ||
} | ||
|
||
/** | ||
* Retrieves an object with the given $identifier. | ||
* For use in the concrete projector. | ||
* Concrete projectors may override this property for setting the class name of the Read Model to a non-conventional name | ||
* | ||
* @param mixed $identifier | ||
* @return object an instance of $this->readModelClassName or NULL if no matching object could be found | ||
* @var string | ||
* @api | ||
*/ | ||
public function get($identifier) | ||
{ | ||
return $this->projectionPersistenceManager->get($this->getReadModelClassName(), $identifier); | ||
} | ||
protected $readModelClassName; | ||
|
||
/** | ||
* Adds an object to this repository. | ||
* For use in the concrete projector. | ||
* The state of this projection | ||
* | ||
* @param object $object The object to add | ||
* @return void | ||
* @var DoctrineProjectionState | ||
* @api | ||
*/ | ||
protected function add($object) | ||
{ | ||
$this->projectionPersistenceManager->add($object); | ||
} | ||
protected $state; | ||
|
||
/** | ||
* Schedules a modified object for persistence. | ||
* For use in the concrete projector. | ||
* Returns the class name of the (main) Read Model of the concrete projector | ||
* | ||
* @param object $object The modified object | ||
* @return void | ||
* @throws \Neos\Flow\Persistence\Exception\IllegalObjectTypeException | ||
* @api | ||
* @return string | ||
*/ | ||
protected function update($object) | ||
public function getReadModelClassName(): string | ||
{ | ||
$this->projectionPersistenceManager->update($object); | ||
return $this->readModelClassName; | ||
} | ||
|
||
/** | ||
* Removes an object from the projector's persistence. | ||
* For use in the concrete projector. | ||
* Initialize the Read Model class name | ||
* Make sure to call this method as parent when overriding it in a concrete projector. | ||
* | ||
* @param object $object The object to remove | ||
* @return void | ||
* @api | ||
* @throws Exception | ||
*/ | ||
protected function remove($object) | ||
protected function initializeObject() | ||
{ | ||
$this->projectionPersistenceManager->remove($object); | ||
if ($this->readModelClassName === null) { | ||
if (substr(get_class($this), -9, 9) !== 'Projector') { | ||
throw new Exception(sprintf('The class name "%s" doesn\'t end in "Projector" so the Read Model class name can\'t be determined automatically. Please set the "readModelClassName" field it in your concrete projector.', get_class($this)), 1476799474); | ||
} | ||
$this->readModelClassName = substr(get_class($this), 0, -9); | ||
} | ||
$this->state = new DoctrineProjectionState($this->readModelClassName); | ||
} | ||
|
||
/** | ||
* Removes all objects of this repository as if remove() was called for all of them. | ||
* For usage in the concrete projector. | ||
* @inheritdoc | ||
* | ||
* @return void | ||
* @api | ||
*/ | ||
public function reset() | ||
{ | ||
$this->projectionPersistenceManager->drop($this->getReadModelClassName()); | ||
$this->state->reset(); | ||
} | ||
|
||
/** | ||
* If this projection is currently empty | ||
* @inheritdoc | ||
* | ||
* @return bool | ||
*/ | ||
public function isEmpty() | ||
{ | ||
return $this->projectionPersistenceManager->count($this->getReadModelClassName()) === 0; | ||
return $this->state->isEmpty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related, but a left-over it seems