Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\WebhookBundle\Event;
|
||||
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class WebhookBuilderEvent extends Event
|
||||
{
|
||||
private array $events = [];
|
||||
|
||||
public function __construct(
|
||||
private TranslatorInterface $translator,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event for the event list.
|
||||
*
|
||||
* @param string $key - a unique identifier; it is recommended that it be namespaced i.e. lead.mytrigger
|
||||
* @param array $event - can contain the following keys:
|
||||
* 'label' => (required) what to display in the list
|
||||
* 'description' => (optional) short description of event
|
||||
*/
|
||||
public function addEvent($key, array $event): void
|
||||
{
|
||||
if (array_key_exists($key, $this->events)) {
|
||||
throw new InvalidArgumentException("The key, '$key' is already used by another webhook event. Please use a different key.");
|
||||
}
|
||||
|
||||
$event['label'] = $this->translator->trans($event['label']);
|
||||
$event['description'] = (isset($event['description'])) ? $this->translator->trans($event['description']) : '';
|
||||
|
||||
$this->events[$key] = $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get webhook events.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEvents()
|
||||
{
|
||||
static $sorted = false;
|
||||
|
||||
if (empty($sorted)) {
|
||||
uasort($this->events, fn ($a, $b): int => strnatcasecmp(
|
||||
$a['label'], $b['label']));
|
||||
$sorted = true;
|
||||
}
|
||||
|
||||
return $this->events;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\WebhookBundle\Event;
|
||||
|
||||
use Mautic\CoreBundle\Event\CommonEvent;
|
||||
use Mautic\WebhookBundle\Entity\Webhook;
|
||||
|
||||
class WebhookEvent extends CommonEvent
|
||||
{
|
||||
/**
|
||||
* @var Webhook
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* @param bool $isNew
|
||||
* @param string $reason
|
||||
*/
|
||||
public function __construct(
|
||||
Webhook $webhook,
|
||||
protected $isNew = false,
|
||||
private $reason = '',
|
||||
) {
|
||||
$this->entity = $webhook;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Webhook entity.
|
||||
*
|
||||
* @return Webhook
|
||||
*/
|
||||
public function getWebhook()
|
||||
{
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Webhook entity.
|
||||
*/
|
||||
public function setWebhook(Webhook $webhook): void
|
||||
{
|
||||
$this->entity = $webhook;
|
||||
}
|
||||
|
||||
public function setReason($reason): void
|
||||
{
|
||||
$this->reason = $reason;
|
||||
}
|
||||
|
||||
public function getReason(): string
|
||||
{
|
||||
return $this->reason;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mautic\WebhookBundle\Event;
|
||||
|
||||
use Mautic\WebhookBundle\Entity\Webhook;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
class WebhookNotificationEvent extends Event
|
||||
{
|
||||
private bool $canSend = true;
|
||||
|
||||
public function __construct(private Webhook $webhook)
|
||||
{
|
||||
}
|
||||
|
||||
public function getWebhook(): Webhook
|
||||
{
|
||||
return $this->webhook;
|
||||
}
|
||||
|
||||
public function setCanSend(bool $canSend): void
|
||||
{
|
||||
$this->canSend = $canSend;
|
||||
}
|
||||
|
||||
public function canSend(): bool
|
||||
{
|
||||
return $this->canSend;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\WebhookBundle\Event;
|
||||
|
||||
use Mautic\CoreBundle\Event\CommonEvent;
|
||||
use Mautic\WebhookBundle\Entity\Webhook;
|
||||
use Mautic\WebhookBundle\Entity\WebhookQueue;
|
||||
|
||||
class WebhookQueueEvent extends CommonEvent
|
||||
{
|
||||
/**
|
||||
* @param bool $isNew
|
||||
*/
|
||||
public function __construct(
|
||||
WebhookQueue $webhookQueue,
|
||||
protected Webhook $webhook,
|
||||
$isNew = false,
|
||||
) {
|
||||
$this->entity = $webhookQueue;
|
||||
$this->isNew = $isNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the WebhookQueue entity.
|
||||
*
|
||||
* @return WebhookQueue
|
||||
*/
|
||||
public function getWebhookQueue()
|
||||
{
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the WebhookQueue entity.
|
||||
*/
|
||||
public function setWebhookQueue(WebhookQueue $webhookQueue): void
|
||||
{
|
||||
$this->entity = $webhookQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Webhook entity.
|
||||
*
|
||||
* @return Webhook
|
||||
*/
|
||||
public function getWebhook()
|
||||
{
|
||||
return $this->webhook;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Webhook entity.
|
||||
*/
|
||||
public function setWebhook(Webhook $webhook): void
|
||||
{
|
||||
$this->webhook = $webhook;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mautic\WebhookBundle\Event;
|
||||
|
||||
use Mautic\LeadBundle\Entity\Lead;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
class WebhookRequestEvent extends Event
|
||||
{
|
||||
public function __construct(
|
||||
private Lead $contact,
|
||||
private string $url,
|
||||
private array $headers,
|
||||
private array $payload,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getUrl(): string
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function setUrl(string $url): void
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
public function setHeaders(array $headers): void
|
||||
{
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
public function getPayload(): array
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
public function setPayload(array $payload): void
|
||||
{
|
||||
$this->payload = $payload;
|
||||
}
|
||||
|
||||
public function getContact(): Lead
|
||||
{
|
||||
return $this->contact;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user