mailpoet
/
lib
/
Automation
/
Engine
/
Endpoints
/
Automations
/
AutomationsCreateFromTemplateEndpoint.php
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
AutomationsCreateFromTemplateEndpoint.php
42 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\Builder\CreateAutomationFromTemplateController; |
| 12 | use MailPoet\Automation\Engine\Mappers\AutomationMapper; |
| 13 | use MailPoet\Validator\Builder; |
| 14 | |
| 15 | class AutomationsCreateFromTemplateEndpoint extends Endpoint { |
| 16 | /** @var CreateAutomationFromTemplateController */ |
| 17 | private $createAutomationFromTemplateController; |
| 18 | |
| 19 | /** @var AutomationMapper */ |
| 20 | private $automationMapper; |
| 21 | |
| 22 | public function __construct( |
| 23 | CreateAutomationFromTemplateController $createAutomationFromTemplateController, |
| 24 | AutomationMapper $automationMapper |
| 25 | ) { |
| 26 | $this->createAutomationFromTemplateController = $createAutomationFromTemplateController; |
| 27 | $this->automationMapper = $automationMapper; |
| 28 | } |
| 29 | |
| 30 | public function handle(Request $request): Response { |
| 31 | $slug = $request->getParam('slug'); |
| 32 | $automation = $this->createAutomationFromTemplateController->createAutomation(is_string($slug) ? $slug : ''); |
| 33 | return new Response($this->automationMapper->buildAutomation($automation)); |
| 34 | } |
| 35 | |
| 36 | public static function getRequestSchema(): array { |
| 37 | return [ |
| 38 | 'slug' => Builder::string()->required(), |
| 39 | ]; |
| 40 | } |
| 41 | } |
| 42 |