一个简单的解决方案是使用symplify/config-transformer。
首先,安装:
composer req symplify/config-transformer
然后简单地说:
vendor/bin/config-transformer switch-format app/config/whatever.yaml -i yaml -o xml
您可以对整个目录执行此操作,也可以切换到基于 PHP 的配置:
vendor/bin/config-transformer switch-format app/config -i xml -o php
完成后,您可能必须编辑您的App\Kernel
,因为默认情况下它主要只加载 YML 文件(和一些 PHP 配置文件)。
如果从默认的 5.3 内核开始,并且已将所有配置转换为 XML,则需要更改文件:
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
protected function configureContainer(ContainerConfigurator $container): void
{
$container->import('../config/{packages}/*.xml');
$container->import('../config/{packages}/'.$this->environment.'/*.xml');
$container->import('../config/services.xml');
$container->import('../config/{services}_'.$this->environment.'.xml');
}
protected function configureRoutes(RoutingConfigurator $routes): void
{
$routes->import('../config/{routes}/'.$this->environment.'/*.xml');
$routes->import('../config/{routes}/*.xml');
$routes->import('../config/routes.xml');
}
}