Skip to content

Instantly share code, notes, and snippets.

@vudaltsov
Last active June 23, 2020 09:45
Show Gist options
  • Save vudaltsov/09109d1d845dbc988a48efa280292ff9 to your computer and use it in GitHub Desktop.
Save vudaltsov/09109d1d845dbc988a48efa280292ff9 to your computer and use it in GitHub Desktop.
Symfony decorator
<?php
declare(strict_types=1);
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
final class A implements I, LoggerAwareInterface
{
use LoggerAwareTrait;
}
<?php
declare(strict_types=1);
final class Decorator implements I
{
private I $i;
public function __construct(I $i)
{
$this->i = $i;
}
}
<?php
declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $di): void {
$services = $di
->services()
->defaults()
->autowire()
->autoconfigure()
;
$services->set(A::class);
$services
->set(Decorator::class)
->decorate(A::class)
;
$services->alias(I::class, A::class);
};
<?php
declare(strict_types=1);
interface I
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment