Skip to content

Commit

Permalink
Merge pull request #75 from tarfin-labs/WEB-4724-basvuru-makinesi-dis…
Browse files Browse the repository at this point in the history
…indaki-makinelerin-loglari-kapatilabilir

Web 4724 basvuru makinesi disindaki makinelerin loglari kapatilabilir
  • Loading branch information
yidemir authored Feb 1, 2024
2 parents a38e519 + 21a4b12 commit eea942b
Show file tree
Hide file tree
Showing 22 changed files with 195 additions and 118 deletions.
26 changes: 12 additions & 14 deletions src/Actor/Machine.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Machine implements Castable, JsonSerializable, Stringable
* It takes a `MachineDefinition` object as a parameter and
* assigns it to the `$definition` property of the instance.
*
* @param MachineDefinition $definition The machine definition object.
* @param MachineDefinition $definition The machine definition object.
*/
protected function __construct(
MachineDefinition $definition,
Expand All @@ -62,7 +62,7 @@ protected function __construct(
* `MachineDefinition`. It returns a new instance of the `Machine` class,
* encapsulating the provided definition.
*
* @param MachineDefinition $definition The definition to initialize the machine with.
* @param MachineDefinition $definition The definition to initialize the machine with.
*
* @return self The newly created machine instance.
*/
Expand Down Expand Up @@ -101,8 +101,8 @@ public static function definition(): ?MachineDefinition
* provided definition and state. If the definition is `null`, it attempts
* to retrieve the definition using the `definition()` method.
*
* @param \Tarfinlabs\EventMachine\Definition\MachineDefinition|array|null $definition The definition to initialize the machine with.
* @param \Tarfinlabs\EventMachine\Actor\State|string|null $state The initial state of the machine.
* @param \Tarfinlabs\EventMachine\Definition\MachineDefinition|array|null $definition The definition to initialize the machine with.
* @param \Tarfinlabs\EventMachine\Actor\State|string|null $state The initial state of the machine.
*
* @return self The newly created and initialized machine instance.
*/
Expand Down Expand Up @@ -131,7 +131,7 @@ public static function create(
* it uses the machine's initial state. If a string is provided, it restores
* the state using the `restoreStateFromRootEventId()` method.
*
* @param \Tarfinlabs\EventMachine\Actor\State|string|null $state The initial state or root event identifier.
* @param \Tarfinlabs\EventMachine\Actor\State|string|null $state The initial state or root event identifier.
*
* @return self The started machine instance.
*/
Expand All @@ -153,16 +153,14 @@ public function start(State|string|null $state = null): self
* updates the machine's state and handles validation guards. If the event
* should be persisted, it calls the `persist()` method.
*
* @param \Tarfinlabs\EventMachine\Behavior\EventBehavior|array|string $event The event to send to the machine.
* @param bool $shouldPersist Whether to persist the state change.
* @param \Tarfinlabs\EventMachine\Behavior\EventBehavior|array|string $event The event to send to the machine.
*
* @return State The updated state of the machine.
*
* @throws Exception
*/
public function send(
EventBehavior|array|string $event,
bool $shouldPersist = true,
): State {
if ($this->state !== null) {
$lock = Cache::lock('mre:'.$this->state->history->first()->root_event_id, 60);
Expand All @@ -187,7 +185,7 @@ public function send(
default => $this->definition->transition($event, $this->state)
};

if ($shouldPersist === true) {
if ($this->definition->shouldPersist) {
$this->persist();
}

Expand Down Expand Up @@ -265,7 +263,7 @@ public function persist(): ?State
* identifier. It reconstructs the state of the machine from the queried
* events and returns the restored state.
*
* @param string $key The root event identifier to restore state from.
* @param string $key The root event identifier to restore state from.
*
* @return State The restored state of the machine.
*
Expand Down Expand Up @@ -299,7 +297,7 @@ public function restoreStateFromRootEventId(string $key): State
* context data. It utilizes the behavior configuration of the machine's
* definition or defaults to the `ContextManager` class.
*
* @param array $persistedContext The persisted context data.
* @param array $persistedContext The persisted context data.
*
* @return ContextManager The restored context manager instance.
*/
Expand All @@ -321,7 +319,7 @@ protected function restoreContext(array $persistedContext): ContextManager
* This method retrieves the current state definition from the machine's
* definition ID map using the provided machine value.
*
* @param array $machineValue The machine value containing the ID of the state definition.
* @param array $machineValue The machine value containing the ID of the state definition.
*
* @return StateDefinition The restored current state definition.
*/
Expand All @@ -337,7 +335,7 @@ protected function restoreCurrentStateDefinition(array $machineValue): StateDefi
* MachineEvent. It determines the source type and constructs the EventBehavior
* object accordingly.
*
* @param MachineEvent $machineEvent The MachineEvent object representing the event.
* @param MachineEvent $machineEvent The MachineEvent object representing the event.
*
* @return EventBehavior The restored EventBehavior object.
*/
Expand Down Expand Up @@ -380,7 +378,7 @@ protected function restoreCurrentEventBehavior(MachineEvent $machineEvent): Even
* failures. If any guard fails, it constructs and throws a
* `MachineValidationException` with detailed error messages.
*
* @param int $lastPreviousEventNumber The last previous event sequence number.
* @param int $lastPreviousEventNumber The last previous event sequence number.
*
* @throws MachineValidationException If any validation guards fail.
*/
Expand Down
20 changes: 10 additions & 10 deletions src/Actor/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class State
/**
* Constructs a new instance of the class.
*
* @param ContextManager $context The context manager instance.
* @param StateDefinition|null $currentStateDefinition The current state definition, or null if not set.
* @param EventBehavior|null $currentEventBehavior The current event behavior, or null if not set.
* @param Collection|null $history The history collection, or null if not set.
* @param ContextManager $context The context manager instance.
* @param StateDefinition|null $currentStateDefinition The current state definition, or null if not set.
* @param EventBehavior|null $currentEventBehavior The current event behavior, or null if not set.
* @param Collection|null $history The history collection, or null if not set.
*/
public function __construct(
public ContextManager $context,
Expand All @@ -60,7 +60,7 @@ protected function updateMachineValueFromState(): void
/**
* Sets the current state definition for the machine.
*
* @param StateDefinition $stateDefinition The state definition to set.
* @param StateDefinition $stateDefinition The state definition to set.
*
* @return self The current object instance.
*/
Expand All @@ -75,9 +75,9 @@ public function setCurrentStateDefinition(StateDefinition $stateDefinition): sel
/**
* Sets the internal event behavior for the machine.
*
* @param InternalEvent $type The internal event type.
* @param string|null $placeholder The optional placeholder parameter.
* @param array|null $payload The optional payload array.
* @param InternalEvent $type The internal event type.
* @param string|null $placeholder The optional placeholder parameter.
* @param array|null $payload The optional payload array.
*
* @return self The current object instance.
*/
Expand All @@ -102,7 +102,7 @@ public function setInternalEventBehavior(
/**
* Sets the current event behavior for the machine.
*
* @param EventBehavior $currentEventBehavior The event behavior to set.
* @param EventBehavior $currentEventBehavior The event behavior to set.
*
* @return self The current object instance.
*/
Expand Down Expand Up @@ -142,7 +142,7 @@ public function setCurrentEventBehavior(EventBehavior $currentEventBehavior, boo
/**
* Checks if the given value matches the current state's value.
*
* @param string $value The value to be checked.
* @param string $value The value to be checked.
*
* @return bool Returns true if the value matches the current state's value; otherwise, returns false.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/Behavior/EventBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ abstract class EventBehavior extends Data
/**
* Creates a new instance of the class.
*
* @param null|string|Optional $type The type of the object. Default is null.
* @param null|array|Optional $payload The payload to be associated with the object. Default is null.
* @param mixed $actor Actor performing the event. Default is null.
* @param int|Optional $version The version number of the object. Default is 1.
* @param SourceType $source The source type of the object. Default is SourceType::EXTERNAL.
* @param null|string|Optional $type The type of the object. Default is null.
* @param null|array|Optional $payload The payload to be associated with the object. Default is null.
* @param mixed $actor Actor performing the event. Default is null.
* @param int|Optional $version The version number of the object. Default is 1.
* @param SourceType $source The source type of the object. Default is SourceType::EXTERNAL.
*
* @return void
*/
Expand Down
22 changes: 11 additions & 11 deletions src/Behavior/InvokableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class InvokableBehavior
/**
* Constructs a new instance of the class.
*
* @param Collection|null $eventQueue The event queue collection. Default is null.
* @param Collection|null $eventQueue The event queue collection. Default is null.
*
* @return void
*/
Expand All @@ -44,7 +44,7 @@ public function __construct(protected ?Collection $eventQueue = null)
/**
* Raises an event by adding it to the event queue.
*
* @param \Tarfinlabs\EventMachine\Behavior\EventBehavior|array $eventBehavior The event definition object to be raised.
* @param \Tarfinlabs\EventMachine\Behavior\EventBehavior|array $eventBehavior The event definition object to be raised.
*/
public function raise(EventBehavior|array $eventBehavior): void
{
Expand All @@ -58,10 +58,10 @@ public function raise(EventBehavior|array $eventBehavior): void
* "$requiredContext" property are present in the given context. It returns
* the key of the first missing attribute if any, otherwise it returns null.
*
* @param ContextManager $context The context to be checked.
* @param ContextManager $context The context to be checked.
*
* @return string|null The key of the first missing attribute, or null if all
* required attributes are present.
* @return string|null The key of the first missing attribute, or null if all
* required attributes are present.
*/
public function hasMissingContext(ContextManager $context): ?string
{
Expand Down Expand Up @@ -91,7 +91,7 @@ public function hasMissingContext(ContextManager $context): ?string
* in the given ContextManager instance. If any required context property is missing,
* it throws a MissingMachineContextException.
*
* @param ContextManager $context The context to be validated.
* @param ContextManager $context The context to be validated.
*/
public function validateRequiredContext(ContextManager $context): void
{
Expand Down Expand Up @@ -125,12 +125,12 @@ public static function getType(): string
* based on the provided state, event behavior, and action arguments.
* The injected values are added to an array and returned.
*
* @param callable $actionBehavior The invokable behavior to inject parameters for.
* @param State $state The state object used for parameter matching.
* @param EventBehavior|null $eventBehavior The event behavior used for parameter matching. (Optional)
* @param array|null $actionArguments The action arguments used for parameter matching. (Optional)
* @param callable $actionBehavior The invokable behavior to inject parameters for.
* @param State $state The state object used for parameter matching.
* @param EventBehavior|null $eventBehavior The event behavior used for parameter matching. (Optional)
* @param array|null $actionArguments The action arguments used for parameter matching. (Optional)
*
* @return array The injected invokable behavior parameters.
* @return array The injected invokable behavior parameters.
*
* @throws \ReflectionException
*/
Expand Down
24 changes: 12 additions & 12 deletions src/ContextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
/**
* Get a value from the context by its key.
*
* @param string $key The key of the value to retrieve.
* @param string $key The key of the value to retrieve.
*
* @return mixed The value associated with the given key, or null if the key does not exist.
*/
Expand All @@ -55,8 +55,8 @@ public function get(string $key): mixed
* subclass of the class of the object, the value is set as
* a property of the object.
*
* @param string $key The key for which to set the value.
* @param mixed $value The value to set for the given key.
* @param string $key The key for which to set the value.
* @param mixed $value The value to set for the given key.
*/
public function set(string $key, mixed $value): mixed
{
Expand All @@ -82,10 +82,10 @@ public function set(string $key, mixed $value): mixed
*
* @param string $key The key to check for existence.
* @param string|null $type The type to check for the value. If null,
* only existence is checked.
* only existence is checked.
*
* @return bool True if the key exists and (if a type is specified)
* its value is of the given type. False otherwise.
* @return bool True if the key exists and (if a type is specified)
* its value is of the given type. False otherwise.
*/
public function has(string $key, ?string $type = null): bool
{
Expand All @@ -107,7 +107,7 @@ public function has(string $key, ?string $type = null): bool
/**
* Remove a key-value pair from the context by its key.
*
* @param string $key The key to remove from the context.
* @param string $key The key to remove from the context.
*/
public function remove(string $key): void
{
Expand Down Expand Up @@ -137,7 +137,7 @@ public function selfValidate(): void
* static from() method and returns it.
* If validation fails, it throws a MachineContextValidationException.
*
* @param array<mixed>|Arrayable<string, mixed> $payload The payload to be validated and created from.
* @param array<mixed>|Arrayable<string, mixed> $payload The payload to be validated and created from.
*
* @return static A new instance of the class created from the payload.
*/
Expand All @@ -157,8 +157,8 @@ public static function validateAndCreate(array|Arrayable $payload): static
/**
* Set a value in the context by its name.
*
* @param string $name The name of the value to set.
* @param mixed $value The value to set.
* @param string $name The name of the value to set.
* @param mixed $value The value to set.
*/
public function __set(string $name, mixed $value): void
{
Expand All @@ -168,7 +168,7 @@ public function __set(string $name, mixed $value): void
/**
* Magic method to dynamically retrieve a value from the context by its key.
*
* @param string $name The key of the value to retrieve.
* @param string $name The key of the value to retrieve.
*
* @return mixed The value associated with the given key, or null if the key does not exist.
*/
Expand All @@ -180,7 +180,7 @@ public function __get(string $name): mixed
/**
* Checks if a property is set on the object.
*
* @param string $name The name of the property to check.
* @param string $name The name of the property to check.
*
* @return bool True if the property exists and is set, false otherwise.
*/
Expand Down
Loading

0 comments on commit eea942b

Please sign in to comment.