简体   繁体   中英

loading resource security.yml symfony3

I try to extend my file security.yml in app with my security.yml in my own bundle but I've this error :

InvalidArgumentException in YamlFileLoader.php line 431:
There is no extension able to load the configuration for "security"(in
C:\wamp64\www\Project\src\Admin\UserBundle\DependencyInjection/../Resources/
config\security.yml). Looked for namespace "security", found none

I've looked at the Symfony doc but I don't find the issue. I show u my code

app/Resources/config/security.yml

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext
    access_control:
        - { path: ^/admin, roles: ROLE_ADMIN }
    providers:
        in_memory:
            memory: ~
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

Admin/UserBundle/Resources/config/security.yml

security:
    encoders:
        Admin\UserBundle\Entity\User: sha512
    role_hierarchy:
        ROLE_COLLABORATEUR:       [ROLE_LECTEUR]
        ROLE_CHEF:       [ROLE_COLLABORATEUR]
        ROLE_ADMIN:       [ROLE_CHEF, ROLE_ALLOWED_TO_SWITCH]
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
    providers:
        main:
            id: fos_user.user_provider.username
        firewalls:
            main_login:
                pattern:   ^/login$
                anonymous: true
            main_register:
                pattern:   ^/register
                anonymous: true
            main_resetting:
                pattern:   ^/resetting
                anonymous: true
            main:
                anonymous: false
                pattern: ^/
                provider:  main
                form_login:
                    login_path: fos_user_security_login
                    check_path: fos_user_security_check
                logout:
                    path:       fos_user_security_logout
                target:     ^/
                remember_me:
                    secret: %secret%

Admin/UserBundle/DependencyInjection/AdminUserExtension.php

class AdminUserExtension extends Extension
{
    /**
    * {@inheritdoc}
    */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));

        foreach ( array('services', 'parameters', 'security') as $basename )
        {
           $loader->load(sprintf('%s.yml', $basename));
        }
    }
}

The SecurityBundle is here :(

AppKernel

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
        ];

        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function getRootDir()
    {
        return __DIR__;
    }

    public function getCacheDir()
    {
        return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
    }

    public function getLogDir()
    {
        return dirname(__DIR__).'/var/logs';
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
    }
 }

The other file seems to work because when I merge security.yml between them, the application works.

You need to add SecurityBundle to your AppKernel.

    public function registerBundles()
{
    $bundles = [
        ...
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        ...
    ];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM