Skip to content

1.8.0

Compare
Choose a tag to compare
@Chrico Chrico released this 14 May 06:14
· 20 commits to master since this release
c6855a6

Introduce service extensions by type

by @gmazzap in #44

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

by @Chrico in #46

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