maker-bundle: 'Make:entity' failed when don't use the default namespace 'App'.

src/Doctrine/DoctrineEntityHelper.php line 45 $entityClassDetails = new ClassNameDetails($metadata->name, 'App\\Entity');

src/Maker/MakeCommand.php line 91 $generator = new Generator($this->fileManager, 'App\\');

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (9 by maintainers)

Commits related to this issue

Most upvoted comments

For People looking for answer:

It works! To clarify use config similar to this:

config/packages/doctrine.yaml

doctrine:
    orm:
        mappings:
            YourAcme:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'YourAcme\Entity'
                alias: YourAcme

config/packages/dev/maker.yaml

maker:
    root_namespace: YourAcme

@upyx it was just a suggestion. 😄 Obviously configuration file would be the best option. To be honest I would be happy if we could even pass it in like other options --namespace=\\MyAwesomeApp\\src ( or something similar )

Hmm, the command should work if you pass a fully-qualified class name to the first step - e.g. Acme\Foo\Bar, but it looks like we missed at least one thing:

Here’s the error I’m currently getting:

./bin/console make:entity

 Class name of the entity to create or update (e.g. GentleGnome):
 > \App\Foo\Bar\Entity\Baz

 created: src/Foo/Bar/Entity/Baz.php
 created: src/Repository/Foo/Bar/Entity/BazRepository.php

 [ERROR] Only annotation mapping is supported by make:entity, but the                            
         <info>App\Foo\Bar\Entity\Baz</info> class uses a different format. If you would like    
         this command to generate the properties & getter/setter methods, add your mapping       
         configuration, and then re-run this command with the <info>--regenerate</info> flag.    

I’m getting the same error, having configured the default namespace. I’m using my own namespace under src/.

ubuntu@aerobill:/var/www/aerobill$ ./bin/console make:entity

 Class name of the entity to create or update (e.g. BraveElephant):
 > Tenant

 created: src/Entity/Tenant.php
 created: src/Repository/TenantRepository.php


 [ERROR] Only annotation mapping is supported by make:entity, but the <info>XXX\Entity\Tenant</info> class uses
         a different format. If you would like this command to generate the properties & getter/setter methods, add your
         mapping configuration, and then re-run this command with the <info>--regenerate</info> flag.
ubuntu@aerobill:/var/www/aerobill$ cat config/packages/dev/maker.yaml
maker:
    root_namespace: 'XXX'

@helariL Hello! In my opinion we should use configuration file. There is part of composer.json from symfony project:

"psr-4": {
    "Symfony\\Bridge\\Doctrine\\": "src/Symfony/Bridge/Doctrine/",
    "Symfony\\Bridge\\Monolog\\": "src/Symfony/Bridge/Monolog/",
    "Symfony\\Bridge\\ProxyManager\\": "src/Symfony/Bridge/ProxyManager/",
    "Symfony\\Bridge\\Twig\\": "src/Symfony/Bridge/Twig/",
    "Symfony\\Bundle\\": "src/Symfony/Bundle/",
    "Symfony\\Component\\": "src/Symfony/Component/"
}

What is it the namespace to use as root? 😄

Hmm, this does help! What you’re describing is the expected behavior: we assume App unless you pass a full class name (including the beginning slash iirc). But, I think if we guess App, but we can’t determine where to generate the file (which means that you have no App namespace in your autoloading), we could THEN ask you to clarify by entering the full class name. Then you could easily know how to use the command in these cases 😃.