diff --git a/README.md b/README.md index 17c5cca..1a17616 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ class YourModel extends DomainModel ```php class DomainRule implements DomainRuleInterface { - public function on() + public static function on() { return YourModel::CREATION; } diff --git a/Tests/Event/DelayedListenerTest.php b/Tests/Event/DelayedListenerTest.php index ad42253..4719363 100644 --- a/Tests/Event/DelayedListenerTest.php +++ b/Tests/Event/DelayedListenerTest.php @@ -78,7 +78,7 @@ public function __construct(EntityManager $entityManager) $this->entityManager = $entityManager; } - public function after() + public static function after() { return [\FakeModel::class => 'action']; } @@ -168,7 +168,7 @@ public function __construct(EntityManager $entityManager) $this->entityManager = $entityManager; } - public function after() + public static function after() { return [\FakeModel::class => 'action']; } diff --git a/Tests/Event/DomainEventDispatcherTest.php b/Tests/Event/DomainEventDispatcherTest.php index 4751940..dfd6736 100644 --- a/Tests/Event/DomainEventDispatcherTest.php +++ b/Tests/Event/DomainEventDispatcherTest.php @@ -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'; } @@ -81,7 +81,7 @@ public function execute(DomainEvent $event) ); } - public function on() + public static function on() { return ['foo.changed', 'bar.changed']; } @@ -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']; } @@ -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'; } diff --git a/Tests/Symfony/DependencyInjection/CompilerPass/RegisterDomainRulesCompilerPassTest.php b/Tests/Symfony/DependencyInjection/CompilerPass/RegisterDomainRulesCompilerPassTest.php index 348485b..428181c 100644 --- a/Tests/Symfony/DependencyInjection/CompilerPass/RegisterDomainRulesCompilerPassTest.php +++ b/Tests/Symfony/DependencyInjection/CompilerPass/RegisterDomainRulesCompilerPassTest.php @@ -80,7 +80,7 @@ class FooRule implements DomainRuleInterface { public function execute(DomainEvent $event) {} - public function on() + public static function on() { return 'test.event'; } diff --git a/composer.json b/composer.json index fe52573..326aa0f 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "php": ">=7.1", "symfony/event-dispatcher": "^4.3|^5.0", "doctrine/doctrine-bundle": "^1.8|^2.0", - "doctrine/orm": "^2.6.3" + "doctrine/orm": "^2.6.3", + "symfony/proxy-manager-bridge": "^4.4" }, "authors": [ { diff --git a/docs/domain_event_dispatcher.md b/docs/domain_event_dispatcher.md index 980ae7a..ace1533 100644 --- a/docs/domain_event_dispatcher.md +++ b/docs/domain_event_dispatcher.md @@ -24,7 +24,7 @@ $dispatcher->addRule(new class implements DomainRuleInterface { // add some specific behavior } - public function on() { + public static function on() { return 'on.event'; } }); @@ -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 } }); diff --git a/src/Integration/Symfony/DependencyInjection/CompilerPass/RegisterDomainRulesCompilerPass.php b/src/Integration/Symfony/DependencyInjection/CompilerPass/RegisterDomainRulesCompilerPass.php index c008502..f8885b0 100644 --- a/src/Integration/Symfony/DependencyInjection/CompilerPass/RegisterDomainRulesCompilerPass.php +++ b/src/Integration/Symfony/DependencyInjection/CompilerPass/RegisterDomainRulesCompilerPass.php @@ -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), ]); diff --git a/src/Rule/DomainRuleInterface.php b/src/Rule/DomainRuleInterface.php index 5f76223..65ad5f4 100644 --- a/src/Rule/DomainRuleInterface.php +++ b/src/Rule/DomainRuleInterface.php @@ -9,5 +9,5 @@ interface DomainRuleInterface extends RuleInterface * * @return array|string */ - public function on(); + public static function on(); } diff --git a/src/Rule/PostPersistDomainRuleInterface.php b/src/Rule/PostPersistDomainRuleInterface.php index 40b9db4..5f06d05 100644 --- a/src/Rule/PostPersistDomainRuleInterface.php +++ b/src/Rule/PostPersistDomainRuleInterface.php @@ -15,5 +15,5 @@ interface PostPersistDomainRuleInterface extends RuleInterface * * @return array|string */ - public function after(); + public static function after(); }