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

Load Rules lazyly #70

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class YourModel extends DomainModel
```php
class DomainRule implements DomainRuleInterface
{
public function on()
public static function on()
{
return YourModel::CREATION;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Event/DelayedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct(EntityManager $entityManager)
$this->entityManager = $entityManager;
}

public function after()
public static function after()
{
return [\FakeModel::class => 'action'];
}
Expand Down Expand Up @@ -168,7 +168,7 @@ public function __construct(EntityManager $entityManager)
$this->entityManager = $entityManager;
}

public function after()
public static function after()
{
return [\FakeModel::class => 'action'];
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/Event/DomainEventDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function execute(DomainEvent $event)
$event->getSubject()->setLowerFoo(strtolower($event->getSubject()->getFoo()));
}

public function on()
public static function on()
{
return 'foo.changed';
}
Expand Down Expand Up @@ -81,7 +81,7 @@ public function execute(DomainEvent $event)
);
}

public function on()
public static function on()
{
return ['foo.changed', 'bar.changed'];
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public function testItRaiseOnPostPersist()
{
// Objects needed
$rule = new class() implements PostPersistDomainRuleInterface {
public function after()
public static function after()
{
return [\FakeModel::class => 'action'];
}
Expand Down Expand Up @@ -173,12 +173,12 @@ public function testItRaiseRuleInBothCases()
// Objects needed
$rule = new class() implements PostPersistDomainRuleInterface, DomainRuleInterface {
private $i = 0;
public function after()
public static function after()
{
return [\FakeModel::class => 'action'];
}

public function on()
public static function on()
{
return 'previous_action';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class FooRule implements DomainRuleInterface
{
public function execute(DomainEvent $event) {}

public function on()
public static function on()
{
return 'test.event';
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"php": ">=7.1",
"symfony/event-dispatcher": "^4.3|^5.0",
"doctrine/doctrine-bundle": "^1.8",
"doctrine/orm": "^2.6.3"
"doctrine/orm": "^2.6.3",
"symfony/proxy-manager-bridge": "^4.4"
melicerte marked this conversation as resolved.
Show resolved Hide resolved
},
"authors": [
{
Expand Down
4 changes: 2 additions & 2 deletions docs/domain_event_dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $dispatcher->addRule(new class implements DomainRuleInterface {
// add some specific behavior
}

public function on() {
public static function on() {
return 'on.event';
}
});
Expand All @@ -44,7 +44,7 @@ $dispatcher->addRule(new class implements PostPersistDomainRuleInterface {
// add some specific behavior
}

public function after() {
public static function after() {
return 'on.event'; // You have to specify the model
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function process(ContainerBuilder $container)
$this->addListenerForEventsInDefinition($id, $class, $attribute, $definition);
}
} else {
$def->setLazy(true);
$definition->addMethodCall('addRule', [
new Reference($id),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/DomainRuleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ interface DomainRuleInterface extends RuleInterface
*
* @return array|string
*/
public function on();
public static function on();
}
2 changes: 1 addition & 1 deletion src/Rule/PostPersistDomainRuleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ interface PostPersistDomainRuleInterface extends RuleInterface
*
* @return array|string
*/
public function after();
public static function after();
}