CommentSubject.php
2 years ago
PostSubject.php
2 years ago
UserSubject.php
5 months ago
index.php
3 years ago
CommentSubject.php
61 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Integrations\WordPress\Subjects; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Automation\Engine\Data\Subject as SubjectData; |
| 9 | use MailPoet\Automation\Engine\Integration\Payload; |
| 10 | use MailPoet\Automation\Engine\Integration\Subject; |
| 11 | use MailPoet\Automation\Engine\WordPress; |
| 12 | use MailPoet\Automation\Integrations\WordPress\Fields\CommentFieldsFactory; |
| 13 | use MailPoet\Automation\Integrations\WordPress\Payloads\CommentPayload; |
| 14 | use MailPoet\Validator\Builder; |
| 15 | use MailPoet\Validator\Schema\ObjectSchema; |
| 16 | |
| 17 | /** |
| 18 | * @implements Subject<CommentPayload> |
| 19 | */ |
| 20 | class CommentSubject implements Subject { |
| 21 | const KEY = 'wordpress:comment'; |
| 22 | |
| 23 | /** @var WordPress */ |
| 24 | private $wp; |
| 25 | |
| 26 | /** @var CommentFieldsFactory */ |
| 27 | private $commentFieldsFactory; |
| 28 | |
| 29 | public function __construct( |
| 30 | WordPress $wp, |
| 31 | CommentFieldsFactory $commentFieldsFactory |
| 32 | ) { |
| 33 | $this->wp = $wp; |
| 34 | $this->commentFieldsFactory = $commentFieldsFactory; |
| 35 | } |
| 36 | |
| 37 | public function getKey(): string { |
| 38 | return self::KEY; |
| 39 | } |
| 40 | |
| 41 | public function getName(): string { |
| 42 | // translators: automation subject (entity entering automation) title |
| 43 | return __('Comment', 'mailpoet'); |
| 44 | } |
| 45 | |
| 46 | public function getArgsSchema(): ObjectSchema { |
| 47 | return Builder::object([ |
| 48 | 'comment_id' => Builder::integer()->required(), |
| 49 | ]); |
| 50 | } |
| 51 | |
| 52 | public function getFields(): array { |
| 53 | return $this->commentFieldsFactory->getFields(); |
| 54 | } |
| 55 | |
| 56 | public function getPayload(SubjectData $subjectData): Payload { |
| 57 | $commentId = (int)$subjectData->getArgs()['comment_id']; |
| 58 | return new CommentPayload($commentId, $this->wp); |
| 59 | } |
| 60 | } |
| 61 |