1.8.0
Introduce service extensions by type
The ExtendingModule::extensions(): array
will allow you to return an array of Extensions for your Services. Those Extensions will be added to your Services after registration. Each Extension will return a callable function which will receive the original Service and the primary Container (read-only).
Sometimes it is desirable to extend a service by its type. Extending modules can do that now as well:
<?php
use Inpsyde\Modularity\Module\ExtendingModule;
use Psr\Log\{LoggerInterface, LoggerAwareInterface};
class LoggerAwareExtensionModule implements ExtendingModule
{
public function extensions() : array
{
return [
'@instanceof<\Psr\Log\LoggerAwareInterface>' => static function(
LoggerAwareInterface $service,
ContainerInterface $c
): ExtendedService {
if ($c->has(LoggerInterface::class)) {
$service->setLogger($c->get(LoggerInterface::class));
}
return $service;
}
];
}
}
This code will extend all Services which implement the Psr\Log\LoggerAwareInterface
-interface automatically.
Read more about the changes here: https://github.com/inpsyde/modularity/blob/1.8.0/docs/Modules.md#extending-by-type
psalm-types for complex service/extension/factory type hints
There were 2 new pslam-types
introduced and centralized to reuse them in several places via pslam-import-type
:
Service
-->callable(ContainerInterface $container):mixed
ExtendingService
->callable(mixed $service, ContainerInterface $container):mixed
Misc
Full Changelog: 1.7.4...1.8.0