AutomationTemplateEmailPreviewEndpoint.php
1 month ago
AutomationTemplateGetEndpoint.php
1 year ago
AutomationTemplatesGetEndpoint.php
2 years ago
AutomationVersionsGetEndpoint.php
2 months ago
AutomationsCreateFromTemplateEndpoint.php
2 months ago
AutomationsDeleteEndpoint.php
2 years ago
AutomationsDuplicateEndpoint.php
2 years ago
AutomationsGetEndpoint.php
9 months ago
AutomationsPutEndpoint.php
2 months ago
index.php
3 years ago
AutomationTemplatesGetEndpoint.php
40 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Engine\Endpoints\Automations; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\API\REST\Request; |
| 9 | use MailPoet\API\REST\Response; |
| 10 | use MailPoet\Automation\Engine\API\Endpoint; |
| 11 | use MailPoet\Automation\Engine\Data\AutomationTemplate; |
| 12 | use MailPoet\Automation\Engine\Registry; |
| 13 | use MailPoet\Validator\Builder; |
| 14 | |
| 15 | class AutomationTemplatesGetEndpoint extends Endpoint { |
| 16 | /** @var Registry */ |
| 17 | private $registry; |
| 18 | |
| 19 | public function __construct( |
| 20 | Registry $registry |
| 21 | ) { |
| 22 | $this->registry = $registry; |
| 23 | } |
| 24 | |
| 25 | public function handle(Request $request): Response { |
| 26 | /** @var string|null $category */ |
| 27 | $category = $request->getParam('category'); |
| 28 | $templates = array_values($this->registry->getTemplates($category ? strval($category) : null)); |
| 29 | return new Response(array_map(function (AutomationTemplate $automation) { |
| 30 | return $automation->toArray(); |
| 31 | }, $templates)); |
| 32 | } |
| 33 | |
| 34 | public static function getRequestSchema(): array { |
| 35 | return [ |
| 36 | 'category' => Builder::string(), |
| 37 | ]; |
| 38 | } |
| 39 | } |
| 40 |