diff --git a/composer.json b/composer.json index b468d0d..9d92771 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "beberlei/assert": "@stable", "jms/serializer": "^3.28.0", "psr/log": "^1.0 || ^2.0 || ^3.0", + "psr/event-dispatcher": "^1.0.0", "doctrine/annotations": "@stable" }, "suggest": { diff --git a/src/CXml/Processor/Event/CXmlProcessEvent.php b/src/CXml/Processor/Event/CXmlProcessEvent.php new file mode 100644 index 0000000..90db811 --- /dev/null +++ b/src/CXml/Processor/Event/CXmlProcessEvent.php @@ -0,0 +1,28 @@ +cxml = $cxml; + $this->context = $context; + } + + public function getCxml(): CXml + { + return $this->cxml; + } + + public function getContext(): Context + { + return $this->context; + } +} diff --git a/src/CXml/Processor/Processor.php b/src/CXml/Processor/Processor.php index 7cd2662..561ac2d 100644 --- a/src/CXml/Processor/Processor.php +++ b/src/CXml/Processor/Processor.php @@ -21,7 +21,9 @@ use CXml\Model\Response\Response; use CXml\Model\Response\ResponsePayloadInterface; use CXml\Model\Status; +use CXml\Processor\Event\CXmlProcessEvent; use CXml\Processor\Exception\CXmlProcessException; +use Psr\EventDispatcher\EventDispatcherInterface; class Processor { @@ -108,15 +110,18 @@ class Processor private HeaderProcessor $headerProcessor; private HandlerRegistryInterface $handlerRegistry; private Builder $builder; + private ?EventDispatcherInterface $eventDispatcher; public function __construct( HeaderProcessor $requestProcessor, HandlerRegistryInterface $handlerRepository, - Builder $builder + Builder $builder, + EventDispatcherInterface $eventDispatcher = null ) { $this->headerProcessor = $requestProcessor; $this->handlerRegistry = $handlerRepository; $this->builder = $builder; + $this->eventDispatcher = $eventDispatcher; } /** @@ -127,6 +132,10 @@ public function process(CXml $cxml, Context $context = null): ?CXml $context ??= Context::create(); $context->setCXml($cxml); + if ($this->eventDispatcher) { + $this->eventDispatcher->dispatch(new CXmlProcessEvent($cxml, $context)); + } + $request = $cxml->getRequest(); if ($request) { return $this->processRequest($request, $context);