Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mautic\LeadBundle\DataObject;
|
||||
|
||||
use Mautic\CoreBundle\Form\DataTransformer\BarStringTransformer;
|
||||
use Mautic\LeadBundle\Exception\InvalidContactFieldTokenException;
|
||||
|
||||
/**
|
||||
* A value object representation of a contact field token.
|
||||
*/
|
||||
class ContactFieldToken
|
||||
{
|
||||
private string $fieldAlias;
|
||||
|
||||
private ?string $defaultValue;
|
||||
|
||||
/**
|
||||
* @throws InvalidContactFieldTokenException
|
||||
*/
|
||||
public function __construct(
|
||||
private string $fullToken,
|
||||
) {
|
||||
$this->parse(trim($fullToken));
|
||||
}
|
||||
|
||||
public function getFullToken(): string
|
||||
{
|
||||
return $this->fullToken;
|
||||
}
|
||||
|
||||
public function getFieldAlias(): string
|
||||
{
|
||||
return $this->fieldAlias;
|
||||
}
|
||||
|
||||
public function getDefaultValue(): ?string
|
||||
{
|
||||
return $this->defaultValue;
|
||||
}
|
||||
|
||||
private function parse(string $fullToken): void
|
||||
{
|
||||
preg_match('/^{contactfield=(.*?)}$/', $fullToken, $matches);
|
||||
|
||||
if (empty($matches[1])) {
|
||||
throw new InvalidContactFieldTokenException("'{$fullToken}' is not a valid contact field token. A valid token example: '{contactfield=firstname|John}'");
|
||||
}
|
||||
|
||||
$barStringTransformer = new BarStringTransformer();
|
||||
$array = $barStringTransformer->reverseTransform($matches[1]);
|
||||
$this->fieldAlias = $array[0];
|
||||
$this->defaultValue = $array[1] ?? null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\LeadBundle\DataObject;
|
||||
|
||||
class LeadManipulator
|
||||
{
|
||||
/**
|
||||
* If true then the manipulator was logged and should not be logged for the second time.
|
||||
*/
|
||||
private bool $logged = false;
|
||||
|
||||
/**
|
||||
* @param ?string $bundleName
|
||||
* @param ?string $objectName
|
||||
* @param ?int $objectId
|
||||
* @param ?string $objectDescription
|
||||
*/
|
||||
public function __construct(
|
||||
private $bundleName = null,
|
||||
private $objectName = null,
|
||||
private $objectId = null,
|
||||
private $objectDescription = null,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?string
|
||||
*/
|
||||
public function getBundleName()
|
||||
{
|
||||
return $this->bundleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?string
|
||||
*/
|
||||
public function getObjectName()
|
||||
{
|
||||
return $this->objectName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?int
|
||||
*/
|
||||
public function getObjectId()
|
||||
{
|
||||
return $this->objectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?string
|
||||
*/
|
||||
public function getObjectDescription()
|
||||
{
|
||||
return $this->objectDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the manipulator was logged already or not.
|
||||
*/
|
||||
public function wasLogged(): bool
|
||||
{
|
||||
return $this->logged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set manipulator as logged so it wouldn't be logged for the second time in the same request.
|
||||
*/
|
||||
public function setAsLogged(): void
|
||||
{
|
||||
$this->logged = true;
|
||||
}
|
||||
|
||||
public function getManipulatedBy(): string
|
||||
{
|
||||
if ($this->objectDescription) {
|
||||
return (string) $this->objectDescription;
|
||||
}
|
||||
|
||||
return $this->getManipulatorKey();
|
||||
}
|
||||
|
||||
public function getManipulatorKey(): string
|
||||
{
|
||||
$objectParts = [];
|
||||
if ($this->bundleName) {
|
||||
$objectParts[] = $this->bundleName;
|
||||
}
|
||||
if ($this->objectName) {
|
||||
$objectParts[] = $this->objectName;
|
||||
}
|
||||
if ($this->objectId) {
|
||||
$objectParts[] = $this->objectId;
|
||||
}
|
||||
|
||||
return implode(':', $objectParts);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user