Add CommentSubject and Payload
[PREMIUM-248]
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace MailPoet\Automation\Integrations\WordPress\Payloads;
|
||||||
|
|
||||||
|
use MailPoet\Automation\Engine\Integration\Payload;
|
||||||
|
use MailPoet\Automation\Engine\WordPress;
|
||||||
|
|
||||||
|
class CommentPayload implements Payload {
|
||||||
|
/** @var int */
|
||||||
|
private $commentId;
|
||||||
|
|
||||||
|
/** @var WordPress */
|
||||||
|
private $wp;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
int $commentId,
|
||||||
|
WordPress $wp
|
||||||
|
) {
|
||||||
|
$this->commentId = $commentId;
|
||||||
|
$this->wp = $wp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCommentId(): int {
|
||||||
|
return $this->commentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getComment(): ?\WP_Comment {
|
||||||
|
$comment = $this->wp->getComment($this->commentId);
|
||||||
|
return $comment instanceof \WP_Comment ? $comment : null;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,50 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace MailPoet\Automation\Integrations\WordPress\Subjects;
|
||||||
|
|
||||||
|
use MailPoet\Automation\Engine\Data\Subject as SubjectData;
|
||||||
|
use MailPoet\Automation\Engine\Integration\Payload;
|
||||||
|
use MailPoet\Automation\Engine\Integration\Subject;
|
||||||
|
use MailPoet\Automation\Engine\WordPress;
|
||||||
|
use MailPoet\Automation\Integrations\WordPress\Payloads\CommentPayload;
|
||||||
|
use MailPoet\Validator\Builder;
|
||||||
|
use MailPoet\Validator\Schema\ObjectSchema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @implements Subject<CommentPayload>
|
||||||
|
*/
|
||||||
|
class CommentSubject implements Subject {
|
||||||
|
const KEY = 'wordpress:comment';
|
||||||
|
|
||||||
|
/** @var WordPress */
|
||||||
|
private $wp;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
WordPress $wp
|
||||||
|
) {
|
||||||
|
$this->wp = $wp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKey(): string {
|
||||||
|
return self::KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string {
|
||||||
|
return __('Comment', 'mailpoet');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArgsSchema(): ObjectSchema {
|
||||||
|
return Builder::object([
|
||||||
|
'comment_id' => Builder::integer()->required(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFields(): array {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPayload(SubjectData $subjectData): Payload {
|
||||||
|
$commentId = (int)$subjectData->getArgs()['comment_id'];
|
||||||
|
return new CommentPayload($commentId, $this->wp);
|
||||||
|
}
|
||||||
|
}
|
@@ -3,19 +3,26 @@
|
|||||||
namespace MailPoet\Automation\Integrations\WordPress;
|
namespace MailPoet\Automation\Integrations\WordPress;
|
||||||
|
|
||||||
use MailPoet\Automation\Engine\Registry;
|
use MailPoet\Automation\Engine\Registry;
|
||||||
|
use MailPoet\Automation\Integrations\WordPress\Subjects\CommentSubject;
|
||||||
use MailPoet\Automation\Integrations\WordPress\Subjects\UserSubject;
|
use MailPoet\Automation\Integrations\WordPress\Subjects\UserSubject;
|
||||||
|
|
||||||
class WordPressIntegration {
|
class WordPressIntegration {
|
||||||
/** @var UserSubject */
|
/** @var UserSubject */
|
||||||
private $userSubject;
|
private $userSubject;
|
||||||
|
|
||||||
|
/** @var CommentSubject */
|
||||||
|
private $commentSubject;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
UserSubject $userSubject
|
UserSubject $userSubject,
|
||||||
|
CommentSubject $commentSubject
|
||||||
) {
|
) {
|
||||||
$this->userSubject = $userSubject;
|
$this->userSubject = $userSubject;
|
||||||
|
$this->commentSubject = $commentSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register(Registry $registry): void {
|
public function register(Registry $registry): void {
|
||||||
$registry->addSubject($this->userSubject);
|
$registry->addSubject($this->userSubject);
|
||||||
|
$registry->addSubject($this->commentSubject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user