Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\SmsBundle\Callback;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Mautic\SmsBundle\Exception\NumberNotFoundException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
interface CallbackInterface
|
||||
{
|
||||
/**
|
||||
* Returns a "transport" string to match the URL path /sms/{transport}/callback.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTransportName();
|
||||
|
||||
/**
|
||||
* Return all contacts that match whatever identifiers the service provides (likely number).
|
||||
*
|
||||
* @return ArrayCollection
|
||||
*
|
||||
* @throws NumberNotFoundException
|
||||
* @throws BadRequestHttpException
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function getContacts(Request $request);
|
||||
|
||||
/**
|
||||
* Extract the message in the reply from the request.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws BadRequestHttpException
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function getMessage(Request $request);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\SmsBundle\Callback;
|
||||
|
||||
use Mautic\SmsBundle\Exception\CallbackHandlerNotFound;
|
||||
|
||||
class HandlerContainer
|
||||
{
|
||||
/**
|
||||
* @var CallbackInterface[]
|
||||
*/
|
||||
private ?array $handlers = null;
|
||||
|
||||
public function registerHandler(CallbackInterface $handler): void
|
||||
{
|
||||
$this->handlers[$handler->getTransportName()] = $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CallbackInterface
|
||||
*
|
||||
* @throws CallbackHandlerNotFound
|
||||
*/
|
||||
public function getHandler($transportName)
|
||||
{
|
||||
if (!isset($this->handlers[$transportName])) {
|
||||
throw new CallbackHandlerNotFound("$transportName has not been registered");
|
||||
}
|
||||
|
||||
return $this->handlers[$transportName];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user