Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mautic\PointBundle\Event;
|
||||
|
||||
use Mautic\PointBundle\Entity\Group;
|
||||
|
||||
final class GroupEvent
|
||||
{
|
||||
public function __construct(
|
||||
private Group $entity,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getGroup(): Group
|
||||
{
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
public function setGroup(Group $group): void
|
||||
{
|
||||
$this->entity = $group;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mautic\PointBundle\Event;
|
||||
|
||||
use Mautic\LeadBundle\Entity\Lead;
|
||||
use Mautic\PointBundle\Entity\GroupContactScore;
|
||||
|
||||
final class GroupScoreChangeEvent
|
||||
{
|
||||
public function __construct(
|
||||
private GroupContactScore $groupContactScore,
|
||||
private int $oldScore,
|
||||
private int $newScore,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getGroupContactScore(): GroupContactScore
|
||||
{
|
||||
return $this->groupContactScore;
|
||||
}
|
||||
|
||||
public function getContact(): Lead
|
||||
{
|
||||
return $this->groupContactScore->getContact();
|
||||
}
|
||||
|
||||
public function getNewScore(): int
|
||||
{
|
||||
return $this->newScore;
|
||||
}
|
||||
|
||||
public function getOldScore(): int
|
||||
{
|
||||
return $this->oldScore;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PointBundle\Event;
|
||||
|
||||
use Mautic\CoreBundle\Event\CommonEvent;
|
||||
use Mautic\LeadBundle\Entity\Lead;
|
||||
use Mautic\PointBundle\Entity\Point;
|
||||
|
||||
class PointActionEvent extends CommonEvent
|
||||
{
|
||||
public function __construct(
|
||||
protected Point $point,
|
||||
protected Lead $lead,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Point
|
||||
*/
|
||||
public function getPoint()
|
||||
{
|
||||
return $this->point;
|
||||
}
|
||||
|
||||
public function setPoint(Point $point): void
|
||||
{
|
||||
$this->point = $point;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Lead
|
||||
*/
|
||||
public function getLead()
|
||||
{
|
||||
return $this->lead;
|
||||
}
|
||||
|
||||
public function setLead(Lead $lead): void
|
||||
{
|
||||
$this->lead = $lead;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PointBundle\Event;
|
||||
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class PointBuilderEvent extends Event
|
||||
{
|
||||
private array $actions = [];
|
||||
|
||||
public function __construct(
|
||||
private TranslatorInterface $translator,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an action to the list of available .
|
||||
*
|
||||
* @param string $key - a unique identifier; it is recommended that it be namespaced i.e. lead.action
|
||||
* @param array $action - can contain the following keys:
|
||||
* 'label' => (required) what to display in the list
|
||||
* 'description' => (optional) short description of event
|
||||
* 'template' => (optional) template to use for the action's HTML in the point builder
|
||||
* i.e AcmeMyBundle:PointAction:theaction.html.twig
|
||||
* 'formType' => (optional) name of the form type SERVICE for the action; will use a default form with point change only
|
||||
* 'formTypeOptions' => (optional) array of options to pass to formType
|
||||
* 'callback' => (optional) callback function that will be passed when the action is triggered; return true to
|
||||
* change the configured points or false to ignore the action
|
||||
* The callback function can receive the following arguments by name (via ReflectionMethod::invokeArgs())
|
||||
* Mautic\LeadBundle\Entity\Lead $lead
|
||||
* $eventDetails - variable sent from firing function to call back function
|
||||
* array $action = array(
|
||||
* 'id' => int
|
||||
* 'type' => string
|
||||
* 'name' => string
|
||||
* 'properties' => array()
|
||||
* )
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function addAction($key, array $action): void
|
||||
{
|
||||
if (array_key_exists($key, $this->actions)) {
|
||||
throw new InvalidArgumentException("The key, '$key' is already used by another action. Please use a different key.");
|
||||
}
|
||||
|
||||
// check for required keys and that given functions are callable
|
||||
$this->verifyComponent(
|
||||
['group', 'label'],
|
||||
['callback'],
|
||||
$action
|
||||
);
|
||||
|
||||
// translate the label and group
|
||||
$action['label'] = $this->translator->trans($action['label']);
|
||||
$action['group'] = $this->translator->trans($action['group']);
|
||||
|
||||
$this->actions[$key] = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getActions()
|
||||
{
|
||||
uasort($this->actions, fn ($a, $b): int => strnatcasecmp(
|
||||
$a['label'], $b['label']));
|
||||
|
||||
return $this->actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of actions supported by the choice form field.
|
||||
*/
|
||||
public function getActionList(): array
|
||||
{
|
||||
$list = [];
|
||||
$actions = $this->getActions();
|
||||
foreach ($actions as $k => $a) {
|
||||
$list[$k] = $a['label'];
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getActionChoices(): array
|
||||
{
|
||||
$choices = [];
|
||||
foreach ($this->actions as $k => $c) {
|
||||
$choices[$c['group']][$c['label']] = $k;
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
private function verifyComponent(array $keys, array $methods, array $component): void
|
||||
{
|
||||
foreach ($keys as $k) {
|
||||
if (!array_key_exists($k, $component)) {
|
||||
throw new InvalidArgumentException("The key, '$k' is missing.");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($methods as $m) {
|
||||
if (isset($component[$m]) && !is_callable($component[$m], true)) {
|
||||
throw new InvalidArgumentException($component[$m].' is not callable. Please ensure that it exists and that it is a fully qualified namespace.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PointBundle\Event;
|
||||
|
||||
use Mautic\CoreBundle\Event\CommonEvent;
|
||||
use Mautic\PointBundle\Entity\Point;
|
||||
|
||||
class PointEvent extends CommonEvent
|
||||
{
|
||||
/**
|
||||
* @param bool $isNew
|
||||
*/
|
||||
public function __construct(Point &$point, $isNew = false)
|
||||
{
|
||||
$this->entity = &$point;
|
||||
$this->isNew = $isNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Point
|
||||
*/
|
||||
public function getPoint()
|
||||
{
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
public function setPoint(Point $point): void
|
||||
{
|
||||
$this->entity = $point;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PointBundle\Event;
|
||||
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class TriggerBuilderEvent extends Event
|
||||
{
|
||||
private array $events = [];
|
||||
|
||||
public function __construct(
|
||||
private TranslatorInterface $translator,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an action to the list of available .
|
||||
*
|
||||
* @param string $key - a unique identifier; it is recommended that it be namespaced i.e. lead.action
|
||||
* @param array $event - can contain the following keys:
|
||||
* 'label' => (required) what to display in the list
|
||||
* 'description' => (optional) short description of event
|
||||
* 'template' => (optional) template to use for the action's HTML in the point builder
|
||||
* i.e AcmeMyBundle:PointAction:theaction.html.twig
|
||||
* 'formType' => (optional) name of the form type SERVICE for the action
|
||||
* 'formTypeOptions' => (optional) array of options to pass to formType
|
||||
* 'callback' => (required) callback function that will be passed when the action is triggered
|
||||
* The callback function can receive the following arguments by name (via ReflectionMethod::invokeArgs())
|
||||
* Mautic\PointBundle\Entity\TriggerEvent $event
|
||||
* Mautic\LeadBundle\Entity\Lead $lead
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
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 action. Please use a different key.");
|
||||
}
|
||||
|
||||
// check for required keys and that given functions are callable
|
||||
$this->verifyComponent(
|
||||
['group', 'label'],
|
||||
['callback'],
|
||||
$event
|
||||
);
|
||||
|
||||
// Support for old way with callback and new event based system
|
||||
// Could be removed after all events will be refactored to events. The key 'eventName' will be mandatory and 'callback' will be removed.
|
||||
if (!array_key_exists('callback', $event) && !array_key_exists('eventName', $event)) {
|
||||
throw new InvalidArgumentException("One of the 'callback' or 'eventName' has to be provided. Use 'eventName' for new code");
|
||||
}
|
||||
|
||||
$event['label'] = $this->translator->trans($event['label']);
|
||||
$event['group'] = $this->translator->trans($event['group']);
|
||||
$event['description'] = (isset($event['description'])) ? $this->translator->trans($event['description']) : '';
|
||||
|
||||
$this->events[$key] = $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getEvents()
|
||||
{
|
||||
uasort($this->events, fn ($a, $b): int => strnatcasecmp(
|
||||
$a['label'], $b['label']));
|
||||
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
private function verifyComponent(array $keys, array $methods, array $component): void
|
||||
{
|
||||
foreach ($keys as $k) {
|
||||
if (!array_key_exists($k, $component)) {
|
||||
throw new InvalidArgumentException("The key, '$k' is missing.");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($methods as $m) {
|
||||
if (isset($component[$m]) && !is_callable($component[$m], true)) {
|
||||
throw new InvalidArgumentException($component[$m].' is not callable. Please ensure that it exists and that it is a fully qualified namespace.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PointBundle\Event;
|
||||
|
||||
use Mautic\CoreBundle\Event\CommonEvent;
|
||||
use Mautic\PointBundle\Entity\Trigger;
|
||||
|
||||
class TriggerEvent extends CommonEvent
|
||||
{
|
||||
/**
|
||||
* @var Trigger
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* @param bool $isNew
|
||||
*/
|
||||
public function __construct(
|
||||
Trigger &$trigger,
|
||||
protected $isNew = false,
|
||||
) {
|
||||
$this->entity = &$trigger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Trigger
|
||||
*/
|
||||
public function getTrigger()
|
||||
{
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
public function setTrigger(Trigger $trigger): void
|
||||
{
|
||||
$this->entity = $trigger;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PointBundle\Event;
|
||||
|
||||
use Mautic\LeadBundle\Entity\Lead;
|
||||
use Mautic\PointBundle\Entity\TriggerEvent as TriggerEventEntity;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
class TriggerExecutedEvent extends Event
|
||||
{
|
||||
private ?bool $result = null;
|
||||
|
||||
public function __construct(
|
||||
private TriggerEventEntity $triggerEvent,
|
||||
private Lead $lead,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TriggerEventEntity
|
||||
*/
|
||||
public function getTriggerEvent()
|
||||
{
|
||||
return $this->triggerEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Lead
|
||||
*/
|
||||
public function getLead()
|
||||
{
|
||||
return $this->lead;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
public function setSucceded(): void
|
||||
{
|
||||
$this->result = true;
|
||||
}
|
||||
|
||||
public function setFailed(): void
|
||||
{
|
||||
$this->result = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user