From 9f98f78ba24d2e2b004ff41c99b1a40bbbcbdfaa Mon Sep 17 00:00:00 2001 From: Francois Suter Date: Mon, 4 Nov 2024 22:01:34 +0100 Subject: [PATCH] [FOLLOWUP] Add one more event, deprecate existing hook, update documentation, references #31 --- Classes/Event/PostProcessOperationsEvent.php | 49 ++++++++++++++++++++ Classes/Event/ProcessArrayDataEvent.php | 4 ++ Classes/Event/ProcessRawDataEvent.php | 4 ++ Classes/Event/ProcessResponseEvent.php | 4 ++ Classes/Event/ProcessXmlDataEvent.php | 4 ++ Classes/Service/ConnectorBase.php | 10 +++- Documentation/Developers/Events/Index.rst | 46 ++++++++++++++++++ Documentation/Developers/Hooks/Index.rst | 6 +++ 8 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 Classes/Event/PostProcessOperationsEvent.php diff --git a/Classes/Event/PostProcessOperationsEvent.php b/Classes/Event/PostProcessOperationsEvent.php new file mode 100644 index 0000000..471df9a --- /dev/null +++ b/Classes/Event/PostProcessOperationsEvent.php @@ -0,0 +1,49 @@ +status = $data; + $this->connectorService = $connectorService; + } + + public function getConnectorService(): ConnectorServiceInterface + { + return $this->connectorService; + } + + public function getStatus(): mixed + { + return $this->status; + } + +} \ No newline at end of file diff --git a/Classes/Event/ProcessArrayDataEvent.php b/Classes/Event/ProcessArrayDataEvent.php index 80fd5f0..6be8db6 100644 --- a/Classes/Event/ProcessArrayDataEvent.php +++ b/Classes/Event/ProcessArrayDataEvent.php @@ -19,6 +19,10 @@ use Cobweb\Svconnector\Service\ConnectorServiceInterface; +/** + * Event for processing data in array format retrieved by connector services. + * Primarily meant for use in the fetchArray() method. + */ final class ProcessArrayDataEvent { protected array $data; diff --git a/Classes/Event/ProcessRawDataEvent.php b/Classes/Event/ProcessRawDataEvent.php index 85deb34..2b44f17 100644 --- a/Classes/Event/ProcessRawDataEvent.php +++ b/Classes/Event/ProcessRawDataEvent.php @@ -19,6 +19,10 @@ use Cobweb\Svconnector\Service\ConnectorServiceInterface; +/** + * Event for processing the raw data retrieved by connector services. + * Primarily meant for use in the fetchRaw() method. + */ final class ProcessRawDataEvent { protected mixed $data; diff --git a/Classes/Event/ProcessResponseEvent.php b/Classes/Event/ProcessResponseEvent.php index 02e0458..0f3b126 100644 --- a/Classes/Event/ProcessResponseEvent.php +++ b/Classes/Event/ProcessResponseEvent.php @@ -19,6 +19,10 @@ use Cobweb\Svconnector\Service\ConnectorServiceInterface; +/** + * Event for processing the raw response received by the connector service when retrieving data. + * Primarily meant for use in the query() method. + */ final class ProcessResponseEvent { protected mixed $response; diff --git a/Classes/Event/ProcessXmlDataEvent.php b/Classes/Event/ProcessXmlDataEvent.php index a81f425..b74c741 100644 --- a/Classes/Event/ProcessXmlDataEvent.php +++ b/Classes/Event/ProcessXmlDataEvent.php @@ -19,6 +19,10 @@ use Cobweb\Svconnector\Service\ConnectorServiceInterface; +/** + * Event for processing data in XML format retrieved by connector services. + * Primarily meant for use in the fetchXml() method. + */ final class ProcessXmlDataEvent { protected string $data; diff --git a/Classes/Service/ConnectorBase.php b/Classes/Service/ConnectorBase.php index 746f0df..8baf205 100644 --- a/Classes/Service/ConnectorBase.php +++ b/Classes/Service/ConnectorBase.php @@ -20,6 +20,7 @@ use Cobweb\Svconnector\Domain\Model\Dto\CallContext; use Cobweb\Svconnector\Domain\Model\Dto\ConnectionInformation; use Cobweb\Svconnector\Event\InitializeConnectorEvent; +use Cobweb\Svconnector\Event\PostProcessOperationsEvent; use Cobweb\Svconnector\Event\ProcessParametersEvent; use Cobweb\Svconnector\Exception\ConnectorRuntimeException; use Cobweb\Svconnector\Utility\ParameterParser; @@ -290,12 +291,19 @@ public function postProcessOperations(array $parameters, mixed $status): void } $hooks = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$this->extensionKey]['postProcessOperations'] ?? null; - if (is_array($hooks)) { + if (is_array($hooks) && count($hooks) > 0) { + trigger_error( + 'Using the postProcessOperations hook is deprecated. Use the PostProcessOperationsEvent instead', + E_USER_DEPRECATED + ); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$this->extensionKey]['postProcessOperations'] as $className) { $processor = GeneralUtility::makeInstance($className); $processor->postProcessOperations($this->parameters, $status, $this); } } + $this->eventDispatcher->dispatch( + new PostProcessOperationsEvent($status, $this) + ); } /** diff --git a/Documentation/Developers/Events/Index.rst b/Documentation/Developers/Events/Index.rst index e76fb33..370de7b 100644 --- a/Documentation/Developers/Events/Index.rst +++ b/Documentation/Developers/Events/Index.rst @@ -34,3 +34,49 @@ dynamic usage in the connector parameters. This event is fired after :ref`parameters have been parsed ` and allows for further manipulation of the connector parameters. + + +.. _developers-events-rawdata: + +\Cobweb\Svconnector\Event\ProcessRawDataEvent +""""""""""""""""""""""""""""""""""""""""""""" + +This event is fired after the service has retrieved data in raw format. It is designed +for use in the :code:`fetchRaw()` method. + + +.. _developers-events-arraydata: + +\Cobweb\Svconnector\Event\ProcessArrayDataEvent +""""""""""""""""""""""""""""""""""""""""""""""" + +This event is fired after the service has retrieved data in array format. It is designed +for use in the :code:`fetchArray()` method. + + +.. _developers-events-xmldata: + +\Cobweb\Svconnector\Event\ProcessXmlDataEvent +"""""""""""""""""""""""""""""""""""""""""""""" + +This event is fired after the service has retrieved data in XML format. It is designed +for use in the :code:`fetchXml()` method. + + +.. _developers-events-response: + +\Cobweb\Svconnector\Event\ProcessResponseEvent +"""""""""""""""""""""""""""""""""""""""""""""" + +This event is fired after the service has called the distant source and received a +response from that source. It is designed for use in the :code:`query()` method. + + +.. _developers-events-postprocess: + +\Cobweb\Svconnector\Event\PostProcessOperationsEvent +"""""""""""""""""""""""""""""""""""""""""""""""""""" + +This event is fired after all operations have been performed by the connector services. +Actually, it will be triggered only if the code that used the service called the +:code:`\Cobweb\Svconnector\Service\ConnectorServiceInterface::postProcessOperations()` method. diff --git a/Documentation/Developers/Hooks/Index.rst b/Documentation/Developers/Hooks/Index.rst index 99956ea..e96db3b 100644 --- a/Documentation/Developers/Hooks/Index.rst +++ b/Documentation/Developers/Hooks/Index.rst @@ -11,6 +11,12 @@ Hooks ^^^^^ +.. warning:: + + Hooks are deprecated and will be removed in the next major version of all + official connector services. Please use the :ref:`events ` + provided by svconnector instead. + It doesn't really make sense to have hooks in the base connector class, since it cannot be instantiated directly. There are quite some examples in the existing connector services and here is a list