<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
juststeveking / laravel-business-process example snippets
use JustSteveKing\BusinessProcess\Process;
final class PurchaseProduct extends Process
{
protected array $tasks = [
CheckStockLevel::class,
ProcessOrder::class,
DecreaseStockLevel::class,
NotifyWarehouse::class,
EmailCustomer::class,
];
}
use JustSteveKing\BusinessProcess\Contracts\TaskContract;
final class CheckStockLevel implements TaskContract
{
public function __invoke(ProcessPayload $payload, Closure $next): mixed
{
// perform your logic here with the passed in payload.
return $next($payload);
}
}
use JustSteveKing\BusinessProcess\Contracts\ProcessPayload;
final class PurchaseProductPayload implements ProcessPayload
{
public function __construct(
// add whatever public properties you need here
public int $product,
public int $user,
public int $order,
) {}
}
final class PurchaseController
{
public function __construct(
private readonly PurchaseProduct $process,
) {}
public function __invoke(PurchaseRequest $request, int $product): JsonResponse
{
try {
$this->process->run(
payload: $request->payload(),
);
} catch (Throwable $exception) {
// Handle exception
}
// return response.
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.