<?php
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/*
services:
foo:
class: Foo
abstract: true
arguments:
- '@bar'
bar:
class: Bar
baz:
class: Baz
qux:
class: Qux
parent: foo
public: true
arguments:
- '@baz'
*/
abstract class Foo
{
private $bar;
public function __construct(Bar $bar)
{
$this->bar = $bar;
}
}
class Bar{}
class Baz{}
class Qux extends Foo
{
private $baz;
public function __construct(Bar $bar, Baz $baz)
{
$this->baz = $baz;
parent::__construct($bar);
}
}
class MyExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$serviceYmlDir = __DIR__ . '/Resources/config';
$loader = new YamlFileLoader($container, new FileLocator($serviceYmlDir));
$loader->load('service.yml');
}
}
$container = new ContainerBuilder();
$extension = new MyExtension();
$extension->load([], $container);
$container->compile();
dump(
$container->get('qux')
);