Skip to content

Instantly share code, notes, and snippets.

@reindert-vetter
Last active June 1, 2023 10:26
Show Gist options
  • Save reindert-vetter/cef0cd3c058fa7e6c0162198f21aaf16 to your computer and use it in GitHub Desktop.
Save reindert-vetter/cef0cd3c058fa7e6c0162198f21aaf16 to your computer and use it in GitHub Desktop.
order history handlers
<?php
namespace App\Services;
use Carbon\Carbon;
class OrderHistoryHandlersPipe
{
const PROVIDERS = [
CommentsHandlerProvider::class,
RuleHandlerProvider::class,
AccountingHandlerProvider::class,
StandardHistoryHandlerProvider::class,
];
/**
* @return OrderHistoryHandler[]
*/
public static function get(): array
{
/** @var OrderHistoryHandler[] $history */
$handlers = collect();
foreach (self::PROVIDERS as $provider) {
$handlers = array_merge($handlers, (new $provider())->getHistoryHandlers());
}
return $handlers->sort('date')->pagination(1, 100, 'desc');
}
}
interface OrderHistoryHandler
{
/**
* @return array|OrderHistoryHandlerInterface[]
*/
public function getHistoryHandlers(): array;
}
interface OrderHistoryHandlerInterface
{
/**
* @return ActionInterface[]
*/
public function actions(): array;
public function driver(): string;
public function date(): Carbon;
public function error(): string;
}
interface ActionInterface
{
public function url(): string;
public function method(): string;
public function body(): string;
// name or icon
public function name(): array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment