Skip to content

Commit c5e51eb

Browse files
committed
wip
1 parent 6641a2b commit c5e51eb

22 files changed

+178
-349
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ phpstan.neon
3030
testbench.yaml
3131
# /docs
3232
/coverage
33+
34+
/packages/**

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
],
2424
"require": {
25-
"php": "^8.1",
25+
"php": "^8.3",
2626
"solution-forest/workflow-engine-core": "*",
2727
"spatie/laravel-package-tools": "^1.16",
2828
"illuminate/contracts": "^10.0||^11.0||^12.0",
@@ -49,7 +49,10 @@
4949
"autoload": {
5050
"psr-4": {
5151
"SolutionForest\\WorkflowEngine\\Laravel\\": "src/"
52-
}
52+
},
53+
"files": [
54+
"src/helpers.php"
55+
]
5356
},
5457
"autoload-dev": {
5558
"psr-4": {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SolutionForest\WorkflowEngine\Laravel\Adapters;
6+
7+
use Illuminate\Contracts\Events\Dispatcher;
8+
use SolutionForest\WorkflowEngine\Contracts\EventDispatcher;
9+
10+
/**
11+
* Laravel adapter for the workflow engine event dispatcher.
12+
*
13+
* This adapter bridges Laravel's event system with the framework-agnostic
14+
* event dispatcher interface used by the workflow engine core.
15+
*/
16+
class LaravelEventDispatcher implements EventDispatcher
17+
{
18+
public function __construct(
19+
private readonly Dispatcher $dispatcher
20+
) {}
21+
22+
public function dispatch(object $event): void
23+
{
24+
$this->dispatcher->dispatch($event);
25+
}
26+
}

src/Adapters/LaravelLogger.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SolutionForest\WorkflowEngine\Laravel\Adapters;
6+
7+
use Illuminate\Log\LogManager;
8+
use SolutionForest\WorkflowEngine\Contracts\Logger;
9+
10+
/**
11+
* Laravel adapter for the workflow engine logger.
12+
*
13+
* This adapter bridges Laravel's logging system with the framework-agnostic
14+
* logger interface used by the workflow engine core.
15+
*/
16+
class LaravelLogger implements Logger
17+
{
18+
public function __construct(
19+
private readonly LogManager $logger
20+
) {}
21+
22+
public function info(string $message, array $context = []): void
23+
{
24+
$this->logger->info($message, $context);
25+
}
26+
27+
public function error(string $message, array $context = []): void
28+
{
29+
$this->logger->error($message, $context);
30+
}
31+
32+
public function debug(string $message, array $context = []): void
33+
{
34+
$this->logger->debug($message, $context);
35+
}
36+
37+
public function warning(string $message, array $context = []): void
38+
{
39+
$this->logger->warning($message, $context);
40+
}
41+
}

src/Models/WorkflowInstance.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace SolutionForest\WorkflowEngine\Laravel\Models;
44

55
use Illuminate\Database\Eloquent\Model;
6-
use Illuminate\Database\Eloquent\Casts\Attribute;
76
use SolutionForest\WorkflowEngine\Core\WorkflowDefinition;
87
use SolutionForest\WorkflowEngine\Core\WorkflowInstance as CoreWorkflowInstance;
98
use SolutionForest\WorkflowEngine\Core\WorkflowState;

src/Providers/WorkflowEngineServiceProvider.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace SolutionForest\WorkflowEngine\Laravel\Providers;
44

5-
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
65
use Illuminate\Database\DatabaseManager;
7-
use SolutionForest\WorkflowEngine\Laravel\Commands\LaravelWorkflowEngineCommand;
86
use SolutionForest\WorkflowEngine\Contracts\StorageAdapter;
97
use SolutionForest\WorkflowEngine\Core\WorkflowEngine;
8+
use SolutionForest\WorkflowEngine\Laravel\Commands\LaravelWorkflowEngineCommand;
109
use SolutionForest\WorkflowEngine\Laravel\Storage\DatabaseStorage;
1110
use Spatie\LaravelPackageTools\Package;
1211
use Spatie\LaravelPackageTools\PackageServiceProvider;
@@ -45,11 +44,25 @@ public function register(): void
4544
};
4645
});
4746

47+
// Register event dispatcher adapter
48+
$this->app->singleton(\SolutionForest\WorkflowEngine\Contracts\EventDispatcher::class, function ($app) {
49+
return new \SolutionForest\WorkflowEngine\Laravel\Adapters\LaravelEventDispatcher(
50+
$app->make(\Illuminate\Contracts\Events\Dispatcher::class)
51+
);
52+
});
53+
54+
// Register logger adapter
55+
$this->app->singleton(\SolutionForest\WorkflowEngine\Contracts\Logger::class, function ($app) {
56+
return new \SolutionForest\WorkflowEngine\Laravel\Adapters\LaravelLogger(
57+
$app->make(\Illuminate\Log\LogManager::class)
58+
);
59+
});
60+
4861
// Register workflow engine
4962
$this->app->singleton(WorkflowEngine::class, function ($app): WorkflowEngine {
5063
return new WorkflowEngine(
5164
$app->make(StorageAdapter::class),
52-
$app->make(EventDispatcher::class)
65+
$app->make(\SolutionForest\WorkflowEngine\Contracts\EventDispatcher::class)
5366
);
5467
});
5568

src/helpers.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use SolutionForest\WorkflowEngine\Core\WorkflowEngine;
6+
use SolutionForest\WorkflowEngine\Core\WorkflowInstance;
7+
8+
if (! function_exists('workflow')) {
9+
/**
10+
* Get the workflow engine instance from the Laravel container.
11+
*/
12+
function workflow(): WorkflowEngine
13+
{
14+
return app(WorkflowEngine::class);
15+
}
16+
}
17+
18+
if (! function_exists('start_workflow')) {
19+
/**
20+
* Start a new workflow.
21+
*/
22+
function start_workflow(string $id, array $definition, array $context = []): string
23+
{
24+
return workflow()->start($id, $definition, $context);
25+
}
26+
}
27+
28+
if (! function_exists('get_workflow')) {
29+
/**
30+
* Get a workflow instance by ID.
31+
*/
32+
function get_workflow(string $id): WorkflowInstance
33+
{
34+
return workflow()->getInstance($id);
35+
}
36+
}
37+
38+
if (! function_exists('cancel_workflow')) {
39+
/**
40+
* Cancel a workflow.
41+
*/
42+
function cancel_workflow(string $id, string $reason = 'Cancelled'): void
43+
{
44+
workflow()->cancel($id, $reason);
45+
}
46+
}
47+
48+
if (! function_exists('list_workflows')) {
49+
/**
50+
* List workflows.
51+
*/
52+
function list_workflows(array $filters = []): array
53+
{
54+
return workflow()->listWorkflows($filters);
55+
}
56+
}

tests/Actions/ECommerce/CreateShipmentAction.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

tests/Actions/ECommerce/FraudCheckAction.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)