Skip to content

Commit fe52abe

Browse files
fix(di): replace XML services with PHP config for Symfony 8
Symfony 8 removed DependencyInjection XML loaders. Load `api_context.php` via PhpFileLoader and ContainerConfigurator; service definitions match the previous XML (public ApiContext with autowire; DoctrineResetManager private, not autowired). Co-authored-by: Zakhar <zahar.guzenko@gmail.com>
1 parent de68ded commit fe52abe

3 files changed

Lines changed: 25 additions & 15 deletions

File tree

src/DependencyInjection/BehatApiContextExtension.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Symfony\Component\Config\FileLocator;
99
use Symfony\Component\DependencyInjection\ContainerBuilder;
1010
use Symfony\Component\DependencyInjection\Extension\Extension;
11-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
11+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
1212

1313
class BehatApiContextExtension extends Extension
1414
{
@@ -18,7 +18,7 @@ public function load(array $configs, ContainerBuilder $container): void
1818
/** @var array<string, mixed> $config */
1919
$config = $this->processConfiguration($configuration, $configs);
2020

21-
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
21+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
2222

2323
$this->loadApiContext($config, $loader, $container);
2424
}
@@ -28,10 +28,10 @@ public function load(array $configs, ContainerBuilder $container): void
2828
*/
2929
private function loadApiContext(
3030
array $config,
31-
XmlFileLoader $loader,
31+
PhpFileLoader $loader,
3232
ContainerBuilder $container
3333
): void {
34-
$this->safeLoad($loader, 'api_context.xml');
34+
$this->safeLoad($loader, 'api_context.php');
3535

3636
$this->configureKernelResetManagers(
3737
$config,
@@ -62,7 +62,7 @@ private function configureKernelResetManagers(
6262
}
6363
}
6464

65-
private function safeLoad(XmlFileLoader $loader, string $file): void
65+
private function safeLoad(PhpFileLoader $loader, string $file): void
6666
{
6767
$loader->load($file);
6868
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use BehatApiContext\Context\ApiContext;
6+
use BehatApiContext\Service\ResetManager\DoctrineResetManager;
7+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
8+
9+
return static function (ContainerConfigurator $container): void {
10+
$services = $container->services();
11+
12+
$services->set(ApiContext::class)
13+
->public()
14+
->autowire()
15+
->autoconfigure();
16+
17+
$services->set(DoctrineResetManager::class)
18+
->autowire(false)
19+
->autoconfigure(false);
20+
};

src/Resources/config/api_context.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)