From d96d8144483369e32f61de74c2c99fa5fad484db Mon Sep 17 00:00:00 2001 From: Yunus Emre Nalbant Date: Fri, 16 Feb 2024 16:54:46 +0300 Subject: [PATCH 1/7] feat: Add `make()` and `run()` static methods in `ActionBehavior` --- src/Behavior/ActionBehavior.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/Behavior/ActionBehavior.php b/src/Behavior/ActionBehavior.php index 086181f..f8f3964 100644 --- a/src/Behavior/ActionBehavior.php +++ b/src/Behavior/ActionBehavior.php @@ -4,6 +4,8 @@ namespace Tarfinlabs\EventMachine\Behavior; +use Tarfinlabs\EventMachine\ContextManager; + /** * ActionBehavior class. * @@ -12,4 +14,35 @@ */ abstract class ActionBehavior extends InvokableBehavior { + /** + * Invokes the method with the given parameters. + * + * @param ContextManager $context Provides access to the context in which the method is being invoked. + * @param EventBehavior $eventBehavior The event behavior associated with the method invocation. + * @param array|null $arguments Optional parameters to be passed to the method. + */ + abstract public function __invoke( + ContextManager $context, + EventBehavior $eventBehavior, + ?array $arguments = null, + ): void; + + /** + * Resolve the Action from the container. + */ + public static function make(): mixed + { + return app(static::class); + } + + /** + * Run the Action by resolving it from the container and invoke it. + * + * @param mixed ...$arguments + * + */ + public static function run(...$arguments): mixed + { + return static::make()(...$arguments); + } } From e24a7cbed672b5fb97c8ad0ae859d42aa97d6028 Mon Sep 17 00:00:00 2001 From: YunusEmreNalbant Date: Fri, 16 Feb 2024 13:55:11 +0000 Subject: [PATCH 2/7] chore: Fix styling --- src/Behavior/ActionBehavior.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Behavior/ActionBehavior.php b/src/Behavior/ActionBehavior.php index f8f3964..5bd8f0f 100644 --- a/src/Behavior/ActionBehavior.php +++ b/src/Behavior/ActionBehavior.php @@ -39,7 +39,6 @@ public static function make(): mixed * Run the Action by resolving it from the container and invoke it. * * @param mixed ...$arguments - * */ public static function run(...$arguments): mixed { From f13a59b517e9e22c004faf874bc3885596da75f4 Mon Sep 17 00:00:00 2001 From: Yunus Emre Nalbant Date: Mon, 19 Feb 2024 09:02:34 +0300 Subject: [PATCH 3/7] remove: Removed redundant `make` and `run` methods from `ActionBehavior` --- src/Behavior/ActionBehavior.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/Behavior/ActionBehavior.php b/src/Behavior/ActionBehavior.php index f8f3964..dbe7da3 100644 --- a/src/Behavior/ActionBehavior.php +++ b/src/Behavior/ActionBehavior.php @@ -26,23 +26,4 @@ abstract public function __invoke( EventBehavior $eventBehavior, ?array $arguments = null, ): void; - - /** - * Resolve the Action from the container. - */ - public static function make(): mixed - { - return app(static::class); - } - - /** - * Run the Action by resolving it from the container and invoke it. - * - * @param mixed ...$arguments - * - */ - public static function run(...$arguments): mixed - { - return static::make()(...$arguments); - } } From 82795945635d5b0107af235fb41d3e30cf2548e9 Mon Sep 17 00:00:00 2001 From: Yunus Emre Nalbant Date: Mon, 19 Feb 2024 09:03:02 +0300 Subject: [PATCH 4/7] add: `make` and `run` methods to `InvokableBehavior` --- src/Behavior/InvokableBehavior.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Behavior/InvokableBehavior.php b/src/Behavior/InvokableBehavior.php index 6d923fc..6e7a505 100644 --- a/src/Behavior/InvokableBehavior.php +++ b/src/Behavior/InvokableBehavior.php @@ -167,4 +167,23 @@ public static function injectInvokableBehaviorParameters( return $invocableBehaviorParameters; } + + /** + * This method is used to create an instance of the invoking class. + */ + public static function make(): mixed + { + return app(static::class); + } + + /** + * This method creates an instance of the invoking class and calls it as a callable, passing any provided arguments. + * + * @param mixed ...$arguments + * + */ + public static function run(...$arguments): mixed + { + return static::make()(...$arguments); + } } From e0fc51b65782e381d49eeb0b5755197578951654 Mon Sep 17 00:00:00 2001 From: YunusEmreNalbant Date: Mon, 19 Feb 2024 06:03:46 +0000 Subject: [PATCH 5/7] chore: Fix styling --- src/Behavior/InvokableBehavior.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Behavior/InvokableBehavior.php b/src/Behavior/InvokableBehavior.php index 6e7a505..9c2197e 100644 --- a/src/Behavior/InvokableBehavior.php +++ b/src/Behavior/InvokableBehavior.php @@ -180,7 +180,6 @@ public static function make(): mixed * This method creates an instance of the invoking class and calls it as a callable, passing any provided arguments. * * @param mixed ...$arguments - * */ public static function run(...$arguments): mixed { From b8a899645a57d1d6aad74b7a0896130c171654d6 Mon Sep 17 00:00:00 2001 From: Yunus Emre Nalbant Date: Mon, 19 Feb 2024 09:31:09 +0300 Subject: [PATCH 6/7] remove: `__invoke` method from `ActionBehavior` --- src/Behavior/ActionBehavior.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/Behavior/ActionBehavior.php b/src/Behavior/ActionBehavior.php index dbe7da3..1b3d8cb 100644 --- a/src/Behavior/ActionBehavior.php +++ b/src/Behavior/ActionBehavior.php @@ -14,16 +14,4 @@ */ abstract class ActionBehavior extends InvokableBehavior { - /** - * Invokes the method with the given parameters. - * - * @param ContextManager $context Provides access to the context in which the method is being invoked. - * @param EventBehavior $eventBehavior The event behavior associated with the method invocation. - * @param array|null $arguments Optional parameters to be passed to the method. - */ - abstract public function __invoke( - ContextManager $context, - EventBehavior $eventBehavior, - ?array $arguments = null, - ): void; } From fdb449603f6991712f8a8dbb9ca404ba39028cb8 Mon Sep 17 00:00:00 2001 From: YunusEmreNalbant Date: Mon, 19 Feb 2024 06:31:35 +0000 Subject: [PATCH 7/7] chore: Fix styling --- src/Behavior/ActionBehavior.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Behavior/ActionBehavior.php b/src/Behavior/ActionBehavior.php index 1b3d8cb..086181f 100644 --- a/src/Behavior/ActionBehavior.php +++ b/src/Behavior/ActionBehavior.php @@ -4,8 +4,6 @@ namespace Tarfinlabs\EventMachine\Behavior; -use Tarfinlabs\EventMachine\ContextManager; - /** * ActionBehavior class. *