I'm trying to use SonataAdminBundle and SonataUserBundle on my symfony4 project. When I try to extend SonataUserBundle, I got an error states that my new class is already in use:
Fatal error: Cannot declare class Application\Sonata\UserBundle\ApplicationSonat
aUserBundle, because the name is already in use in C:\wamp64\www\staff-test\src\
Application\Sonata\UserBundle\ApplicationSonataUserBundle.php on line 24
I enable the bundle on bundles.php file On composer.json file, I added my new bundle on psr4 attribute. I mapped my new bundle on doctrine My ApplicationSonataUserBundle class is used just in my Bundle. I extended it :
php bin/console sonata:easy-extends:generate SonataUserBundle --dest=src --namespace_prefix=App
My Bundles.php file :
return [
Application\Sonata\UserBundle\ApplicationSonataUserBundle::class => ['all' => true],
];
Composer.json:
"autoload": {
"psr-4": {
"App\\": "src/",
"Application\\":"src/Application/"
}
},
doctrine.yaml
orm:
auto_generate_proxy_classes: true
entity_managers:
default:
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
SonataUserBundle: ~
FOSUserBundle: ~
ApplicationSonataUserBundle: ~
ApplicationSonataUserBundle class:
<?php
namespace Application\Sonata\UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* This file has been generated by the SonataEasyExtendsBundle.
*
* @link https://sonata-project.org/easy-extends
*
* References:
* @link http://symfony.com/doc/current/book/bundles.html
*/
class ApplicationSonataUserBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function getParent()
{
return 'SonataUserBundle';
}
}
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"friendsofsymfony/rest-bundle": "^2.5",
"nelmio/api-doc-bundle": "^3.4",
"sensio/framework-extra-bundle": "^5.1",
"sonata-project/admin-bundle": "^3.48",
"sonata-project/doctrine-orm-admin-bundle": "^3.8",
"sonata-project/user-bundle": "^4.3",
"symfony/acl-bundle": "^1.0",
"symfony/asset": "4.2.*",
"symfony/console": "4.2.*",
"symfony/dotenv": "4.2.*",
"symfony/expression-language": "4.2.*",
"symfony/flex": "^1.1",
"symfony/form": "4.2.*",
"symfony/framework-bundle": "4.2.*",
"symfony/monolog-bundle": "^3.1",
"symfony/orm-pack": "*",
"symfony/process": "4.2.*",
"symfony/security-bundle": "4.2.*",
"symfony/serializer-pack": "*",
"symfony/swiftmailer-bundle": "^3.1",
"symfony/translation": "4.2.*",
"symfony/twig-bundle": "4.2.*",
"symfony/validator": "4.2.*",
"symfony/web-link": "4.2.*",
"symfony/yaml": "4.2.*"
},
I need just to extend SonataUserBundle, but everytime I try to do it, I have the same problem. I'm using Symfony4 in my project. The exception appears after extending the bundle.
Any idea about this problem? I posted the problem before but no answer.
To solve problem. I just added App on my namespace :
namespace App\Application\Sonata\UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* This file has been generated by the SonataEasyExtendsBundle.
*
* @link https://sonata-project.org/easy-extends
*
* References:
* @link http://symfony.com/doc/current/book/bundles.html
*/
class ApplicationSonataUserBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function getParent()
{
return 'SonataUserBundle';
}
}
And in bundles.php too :
return [
App\Application\Sonata\UserBundle\ApplicationSonataUserBundle::class => ['all' => true],
];