Code Monkey home page Code Monkey logo

Comments (22)

piotrkardasz avatar piotrkardasz commented on June 22, 2024 19

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

from maker-bundle.

weaverryan avatar weaverryan commented on June 22, 2024 2

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.    

from maker-bundle.

helariL avatar helariL commented on June 22, 2024 2

@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 )

from maker-bundle.

weaverryan avatar weaverryan commented on June 22, 2024 1

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 :).

from maker-bundle.

upyx avatar upyx commented on June 22, 2024 1

@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? ๐Ÿ˜„

from maker-bundle.

kategray avatar kategray commented on June 22, 2024 1

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'

from maker-bundle.

kilianklein avatar kilianklein commented on June 22, 2024

Hi guys, first of all thanks for this amazing and promising bundle!

I am testing the bundle with symfony3.4 (as the documentation mentioned it should work with it) and indeed I had to go mess directly with the 2 lignes @yuhuaian mentioned to change "App" to "AppBundle" (unless I am wrong this is the convention for the bundle name for 3.4?). Otherwise, I would not get prompted for the entity's fully qualified name and would get this error instead:

bin/console make:entity Test
Could not determine where to locate the new class "App\Entity\Test".

Hope this helps.

from maker-bundle.

kilianklein avatar kilianklein commented on June 22, 2024

Thanks for your answer, the solution sounds good to me! :)

from maker-bundle.

helariL avatar helariL commented on June 22, 2024

Wouldn't it be possible to reference namespace directly from composer.json ? If we anyway have to define it for autoload.

from maker-bundle.

upyx avatar upyx commented on June 22, 2024

Hello!

I have the similar issue. We don't use App as root namespace of our project so all make:* commands doesn't work. Few examples:

Command Error
make:auth Could not determine where to locate the new class "App\Security\SuperAuth".
make:command Could not determine where to locate the new class "App\Command\ProjHelloCommand".
make:controller Could not determine where to locate the new class "App\Controller\VictoriousGnomeController".
make:entity Could not determine where to locate the new class "App\Entity\TinyKangaroo".
make:form Could not determine where to locate the new class "App\Form\TinyPizzaType".
make:functional-test Could not determine where to locate the new class "App\Tests\DefaultControllerTest".
make:unit-test Could not determine where to locate the new class "App\Tests\UtilTest".

As we can see all errors are identical. It is because App is hardcoded and there is no way to change it without interfering to code. I'm not sure that simple determining root namespace is possible. But we can do it configurable.

I've found 8 places where App was hardcoded. So refactoring won't be very difficult.

What do you think about?

P.S.
What do you say about changing title to "All 'make:*' failed..."?

from maker-bundle.

weaverryan avatar weaverryan commented on June 22, 2024

@upyx Actually, your description isn't quite right, but clearly the bundle isn't doing a very helpful job :). You can use a non-App namespace on any command, but you must type the full class name. For example, you should be able to

php bin/console make:controller

Then, when it asks you for the controller name, use:

\MyNamespace\Controller\FooController

By starting your namespace with \, we know that you are giving us a full namespace.

We need to:

A) Give a better error message in all commands. Instead of Could not determine where to locate the new class "App\Security\SuperAuth"., we need to suggest that the user type in the full namespace, because obviously, App\ is not used by them.

B) We probably need to make the App\ root prefix configurable.

from maker-bundle.

LeJeanbono avatar LeJeanbono commented on June 22, 2024

Should we do a configuration file ?

from maker-bundle.

upyx avatar upyx commented on June 22, 2024

@weaverryan Oh, I didn't know that. Thank you for advice.
However not all commands ask class name. For example, make:command asks command name and doesn't ask class.
I think it would be better if a user does not need to type the full class name.

@LeJeanbono I think so. Would you like to do that?

from maker-bundle.

helariL avatar helariL commented on June 22, 2024

This is not correct @weaverryan

Sure you can use full class name when generating controllers etc. but when generating Entities it doesn't work. You can pass full class name for the Entity but when script reaches the point to start generating the Repository for the Entity it fails and there is no option to pass in the full namespace for that.

Option B sounds reasonable and as i pointed out before, it actually should get the namespace from composer.json and default App namespace should be a fallback when everything else fails.

But otherwise keep up the awesome work!

from maker-bundle.

eugenekurasov avatar eugenekurasov commented on June 22, 2024

Is any news about repository in Make:entity?

I can do PR if needed.

from maker-bundle.

eugenekurasov avatar eugenekurasov commented on June 22, 2024

@helariL You can use absolute path (https://github.com/symfony/maker-bundle/blob/master/src/Generator.php#L107)
make:controller \\Controller\\CustomController

from maker-bundle.

helariL avatar helariL commented on June 22, 2024

@eugenekurasov yes that works really well when generating controllers etc. but try the same thing with make:entity ๐Ÿ˜‰

from maker-bundle.

eugenekurasov avatar eugenekurasov commented on June 22, 2024

@helariL make:entity has problem with absolute path.
I created issue for make:entity, but then closed.

from maker-bundle.

javiereguiluz avatar javiereguiluz commented on June 22, 2024

Closing as fixed by #173.

from maker-bundle.

jonmnoj avatar jonmnoj commented on June 22, 2024

If you are using 3.4 you need to place the maker config in

app/config/config_dev.yml

from maker-bundle.

weilin-ong avatar weilin-ong commented on June 22, 2024

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

Hi, but it only works for 1 specific custom folder, in this case, YourAcme.
What if I want to have multiple custom folders? (e.g YourAcme2, YourAcme3 etc)
I will then have to change the root_namespace manually every time I want to create entity/repository for that specific folder. Is that right?

from maker-bundle.

upyx avatar upyx commented on June 22, 2024

What if I want to have multiple custom folders? (e.g YourAcme2, YourAcme3 etc) I will then have to change the root_namespace manually every time I want to create entity/repository for that specific folder. Is that right?

No. See #133 (comment)

You can set the full class name like:

bin/console make:entity '\YourAcme2\Entity\SomeEntity'

from maker-bundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.