Last active
June 23, 2020 09:45
-
-
Save vudaltsov/09109d1d845dbc988a48efa280292ff9 to your computer and use it in GitHub Desktop.
Symfony decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
use Psr\Log\LoggerAwareInterface; | |
use Psr\Log\LoggerAwareTrait; | |
final class A implements I, LoggerAwareInterface | |
{ | |
use LoggerAwareTrait; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
final class Decorator implements I | |
{ | |
private I $i; | |
public function __construct(I $i) | |
{ | |
$this->i = $i; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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