diff --git a/ChangeLog b/ChangeLog index 7e891db..a1bdf40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2024-12-07 Francois Suter (Idéative) * Verify compatibility with PHP 8.4 + * Verify service availability when a service is requested 2024-11-26 Francois Suter (Idéative) diff --git a/Classes/Exception/UnavailableServiceException.php b/Classes/Exception/UnavailableServiceException.php new file mode 100644 index 0000000..b58af85 --- /dev/null +++ b/Classes/Exception/UnavailableServiceException.php @@ -0,0 +1,23 @@ +connectors[$type])) { /** @var ConnectorBase $connector */ $connector = $this->connectors[$type]; + if (!$connector->isAvailable()) { + throw new UnavailableServiceException( + sprintf( + 'Connector service for type %s is not available.', + $type + ), + 1733675709 + ); + } $connector->setParameters($parameters); return $connector; } diff --git a/Documentation/Developers/ConnectorApi/Index.rst b/Documentation/Developers/ConnectorApi/Index.rst index 42aeac8..95d7a5e 100644 --- a/Documentation/Developers/ConnectorApi/Index.rst +++ b/Documentation/Developers/ConnectorApi/Index.rst @@ -60,9 +60,10 @@ initialize() isAvailable() - This method can be called when a connector service is about to be used - to check if it is available or not. It is expected to return a boolean value - accordingly. + This method is called when a connector service is requested via the registry. + It is designed to check whether the service is actually available or not. + It is expected to return a boolean value accordingly. If the service is not available, + the registry will throw a :php:`\Cobweb\Svconnector\Exception\UnavailableServiceException`. Input none diff --git a/Documentation/Installation/Index.rst b/Documentation/Installation/Index.rst index 69f5dcb..b01354b 100644 --- a/Documentation/Installation/Index.rst +++ b/Documentation/Installation/Index.rst @@ -41,6 +41,10 @@ Instead, parameters must be passed when getting the connector from the registry: $service = $connectorRegistry->getServiceForType('json', $parameters); +When :code:`getServiceForType()` is called, the connector's :code:`isAvailable()` method is +now called. If the connector is not available a :php:`\Cobweb\Svconnector\Exception\UnavailableServiceException` +is thrown. + This version also provides :ref:`events ` in replacement of existing hooks for all connector services. All hooks have been deprecated and will be removed in the next major version. Please update your code if you have developed custom connectors.