https://github.com/amethyst-php/action
https://github.com/amethyst-php/action
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/amethyst-php/action
- Owner: amethyst-php
- License: mit
- Created: 2019-08-27T18:11:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-04T18:13:33.000Z (about 2 years ago)
- Last Synced: 2025-08-04T21:44:29.253Z (11 months ago)
- Language: PHP
- Size: 233 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# amethyst-action
[](https://github.com/amethyst-php/action/actions)
[Amethyst](https://github.com/amethyst-php/amethyst) package.
# Requirements
PHP 7.1 and later.
## Installation
You can install it via [Composer](https://getcomposer.org/) by typing the following command:
```bash
composer require amethyst/action
```
The package will automatically register itself.
## Documentation
[Read](docs/index.md)
## Testing
Configure the .env file before launching `./vendor/bin/phpunit`
## Dummy
Let's create a simple workflow, the goal is to log the message of an event when is fired.
`app/Events/DummyEvent.php`
```php
message = $message;
}
public function getData()
{
return [
'message' => $this->message
];
}
}
```
`app/Actions/LogAction.php`
```php
'text'
];
}
public function dispatch(Closure $next, Bag $data)
{
Log::info($data->message);
$next($data);
}
}
```
`app/Actions/EventListenerAction.php`
```php
data->event], function ($event_name, $events) use ($next, $data) {
$next($data->merge(new Bag($events[0]->getData())));
});
}
}
```
Now remains only data entry
```php
use Amethyst\Managers\ActionManager;
use Amethyst\Managers\WorkflowManager;
use Amethyst\Managers\WorkflowNode;
use Amethyst\Managers\AggregatorManager;
use App\Actions\LogAction;
use App\Actions\EventListenerAction;
use App\Events\DummyEvent;
use Symfony\Component\Yaml\Yaml;
app('amethyst.workflow')->addType('log', LogAction::class);
app('amethyst.workflow')->addType('event-listener', EventListenerAction::class);
$actionManager = new ActionManager();
$logAction = $actionManager->createOrFail([
'name' => 'Log',
'payload' => Yaml::dump([
'class' => 'log',
'arguments' => []
])
])->getResource();
$eventListenerAction = $actionManager->createOrFail([
'name' => 'Event Listener',
'payload' => Yaml::dump([
'class' => 'event-listener',
'arguments' => []
])
])->getResource();
$workflowManager = new WorkflowManager();
$aggregatorManager = new AggregatorManager();
$workflow = $workflowManager->createOrFail([
'name' => 'Log events'
])->getResource();
$node1 = $workflowNodeManager->createOrFail([
'workflow_id' => $workflow->id,
'target_type' => 'action',
'target_id' => $eventListeneAction->id,
'data' => Yaml::dump([
'event' => DummyEvent::class
]),
])->getResource();
$node2 = $workflowNodeManager->createOrFail([
'workflow_id' => $workflow->id,
'target_type' => 'action',
'target_id' => $logAction->id
])->getResource();
$aggregatorManager->createOrFail([
'source_type' => 'workflow-node',
'source_id' => $node1->id,
'aggregate_type' => 'workflow-node',
'aggregate_type' => $node2->id
]);
```