'Symfony: Load Extensioin without Bundle
I have a Symfony 5.4 application. I have created a sso_settings.yml within my config/packages/ folder.
There is no bundle structure, so I created a DependencyInjection Folder under my src/ folder with the file AppConfiguration.php and the file AppExtension.php.
Because I have no bundle, I registered my Extension in my Kernel.php class with
protected function build(ContainerBuilder $container): void
{
$container->registerExtension(new AppExtension());
}
AppConfiguration.php
<?php
declare(strict_types=1);
namespace App\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class AppConfiguration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('sso_settings');
$treeBuilder->getRootNode()
->children()
->arrayNode('siam_role_hierarchy')
->useAttributeAsKey('id')
->prototype('scalar')
->end()
->end()
->end()
;
return $treeBuilder;
}
}
AppExtension.php
<?php
declare(strict_types=1);
namespace App\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
class AppExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new AppConfiguration();
$processedConfig = $this->processConfiguration($configuration, $configs);
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../../config/packages')
);
$loader->load('sso_settings.yaml');
}
public function getAlias(): string
{
return 'sso_settings';
}
}
The path to the sso_settings.yaml is correct.
But now I get this error:
There is no extension able to load the configuration for "sso_settings" (in "/var/www/app/src/DependencyInjection/../../config/packages/sso_settings.yaml"). Looked for namespace "sso_settings", found "none".
Can someone help me with this? I cannot find the issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
