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

Web 4344 event machine behavior dependency injection #70

Merged
merged 34 commits into from
Jan 12, 2024

Conversation

deligoez
Copy link
Member

@deligoez deligoez commented Dec 5, 2023

No description provided.

…344)

This commit introduces a new class `EventCollection` in `src/EventCollection.php`. The `EventCollection` class extends the `Illuminate\Support\Collection` class.
….php` (WEB-4344)

This commit modifies the `runAction` method in `src/Definition/MachineDefinition.php` to include `EventCollection` as a parameter. It also updates the test `it can inject requested parameters` in `tests/BehaviorDependencyInjectionTest.php` to pass `EventCollection` and adds assertions to check the instance and count of `EventCollection`.
This commit modifies the `runAction` method in `src/Definition/MachineDefinition.php` to handle parameters with union types. It also adjusts the reflection process to accommodate `InvokableBehavior` instances. The changes allow the method to correctly determine the type of each parameter and assign the appropriate value.
…abase\Eloquent\Collection` (WEB-4344)

This commit modifies the `EventCollection` class in `src/EventCollection.php`. The parent class has been changed from `Illuminate\Support\Collection` to `Illuminate\Database\Eloquent\Collection`.
This commit adds a `newCollection` method to the `MachineEvent` model in `src/Models/MachineEvent.php`. This method overrides the default Eloquent collection with a custom `EventCollection`. This allows for additional methods to be available on the collection of `MachineEvent` models.
…s (WEB-4344)

This commit updates the action methods in `tests/EventStoreTest.php` and `tests/ActionTest.php`. The `EventDefinition` parameter has been replaced with `EventBehavior` in the `additionAction` and `subtractionAction` methods. This change aligns the parameter type with the actual type of event being passed to these methods.
…4344)

This commit refactors the `runAction` method in `src/Definition/MachineDefinition.php` to improve how it handles parameter types. Instead of matching the parameter type name, it now checks if the parameter type is an instance of the expected classes (`ContextManager`, `EventBehavior`, `State`, `EventCollection`).
…t (WEB-4344)

Refactor the assignment of action behavior parameters in `MachineDefinition.php` commit. Instead of assigning each parameter individually, an array of parameters is now used.
…WEB-4344)

Improve parameter assignment in `MachineDefinition.php` commit. Instead of assigning parameters individually, utilize an array for action behavior arguments when `$typeName` is 'array'.
…in `additionAction()` (WEB-4344)

Update argument variable names in the `additionAction` function in `InvokableBehaviorArgumentsTest.php` commit. Rename `ContextManager $context` to `$ctx`, `EventDefinition $eventDefinition` to `$ed`, and `array $arguments` to `$arguments`.
…ds (WEB-4344)

In this commit, the `__invoke()` method in various behavior and guard classes within the EventMachine framework is replaced by the `definition()` method returning a `Closure`. This change affects multiple files, including `ActionBehavior`, `GuardBehavior`, `ResultBehavior`, and several specific action and guard implementations in tests. The refactor streamlines the invocation process and enhances the flexibility in defining behavior and guard logic. Specifically, it allows the encapsulation of the logic within a `Closure`, providing a more concise and manageable approach. This change is a significant shift in the method of defining behaviors and guards, moving towards a more functional style of programming within the framework.
…n `MachineDefinition.php` (WEB-4344)

This commit modifies the `runAction` method in `src/Definition/MachineDefinition.php`. The way `InvokableBehavior` instances are handled has been updated. Instead of using a `ReflectionMethod` to get the parameters of the `__invoke` method, a `ReflectionFunction` is now used on the result of the `definition()` method. The action behavior is then executed by invoking the `definition()` method directly if the behavior is an instance of `InvokableBehavior`, or the behavior itself otherwise.
…Branch` method (WEB-4344)

This commit modifies the `getFirstValidTransitionBranch` method in `src/Definition/TransitionDefinition.php`. The method now supports `InvokableBehavior` instances for guard behaviors. It uses reflection to determine the parameters of the guard behavior and passes the appropriate arguments based on the parameter types. This change allows for more flexible guard behaviors in transition definitions.
The __invoke methods in GuardBehavior, ActionBehavior, and ResultBehavior classes have been removed as they were not adding any specific functionality. Also, the InvokableBehavior class has been simplified by removing the redundant __invoke method and the unnecessary dependency on Closure. These changes make the code simpler and easier to maintain.
Changed ReflectionFunction to ReflectionMethod for actionBehavior and guardBehavior. Simplified execution of both behaviors by removing unnecessary condition checks. The code is more straightforward now and this also simplifies the InvokableBehavior class.
… and Guard classes

In Action and Guard classes, definitions were initialized with Closures. This change substitutes those Closures with direct imperative function calls. This approach optimizes execution, simplifies the Invokable Behavior and reduces code complexity.
The runActions method in TransitionBranch.php now includes ReflectionException in the docblock to enhance user understanding. The ReflectionException error indicates issues with retrieving information about classes, interfaces, and methods during runtime, thus this helps users better anticipate potential problem points in this method.
…aviors

Added a new static function `injectInvokableBehaviorParameters` to the `InvokableBehavior` class. This function injects parameters into invokable behaviors and it's utilized in `MachineDefinition` and `TransitionDefinition` classes, replacing and simplifying duplicated code. This update enhances the overall maintenance and readability of the code.
Introduced a new ReflectionUnionType to the InvokableBehavior class to centralize parameter injection for invokable behaviors. Enhanced the readability and maintenance of the code by simplifying the reflection logic used in MachineDefinition and TransitionDefinition classes.
@deligoez deligoez requested a review from aydinfatih December 5, 2023 19:18
tests/ActionTest.php Outdated Show resolved Hide resolved
tests/ActionTest.php Outdated Show resolved Hide resolved
The pint command in the composer.json file has been updated to include --config flag. This specifies the configuration file to use when running the pint command, improving flexibility in running lint checks.
The type annotation for the variable $resultBehavior in the Machine.php file has been changed from \Tarfinlabs\EventMachine\Behavior\ResultBehavior to callable. This change ensures the $resultBehavior variable can accept any callable function, thereby making the code more versatile.
The class method definition in ResultBehavior has been refactored to an invokable. A previous anonymous function definition has been replaced with the __invoke magic method, offering a more concise syntax and enhancing the object's versatility by making it directly callable.
@deligoez deligoez self-assigned this Jan 12, 2024
@deligoez deligoez merged commit 450a5ef into main Jan 12, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants