Files
piratepoet/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsGetEndpoint.php
Jan Jakes 4aa323b612 Extract data-carrying classes to dedicated namespace
We need a separation of "Step" as an interface vs. "Step" as a serializable data structure.

[MAILPOET-4515]
2022-08-08 13:23:57 +02:00

39 lines
1.2 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Automation\Engine\Endpoints\Workflows;
use DateTimeImmutable;
use MailPoet\Automation\Engine\API\Endpoint;
use MailPoet\Automation\Engine\API\Request;
use MailPoet\Automation\Engine\API\Response;
use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
class WorkflowsGetEndpoint extends Endpoint {
/** @var WorkflowStorage */
private $workflowStorage;
public function __construct(
WorkflowStorage $workflowStorage
) {
$this->workflowStorage = $workflowStorage;
}
public function handle(Request $request): Response {
$workflows = $this->workflowStorage->getWorkflows();
return new Response(array_map(function (Workflow $workflow) {
return $this->buildWorkflow($workflow);
}, $workflows));
}
private function buildWorkflow(Workflow $workflow): array {
return [
'id' => $workflow->getId(),
'name' => $workflow->getName(),
'status' => $workflow->getStatus(),
'created_at' => $workflow->getCreatedAt()->format(DateTimeImmutable::W3C),
'updated_at' => $workflow->getUpdatedAt()->format(DateTimeImmutable::W3C),
];
}
}