-
-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't load entities from bundles using PSR-4 #282
Comments
This is happening when I run This is not the only problem with using |
is the problem happening when loading entities or when generating them ? |
The problem is happening when generating them, because it fails when it tries to load the metadata. Do you want me to create a simple bundle that highlight the problem? |
Having the same problem. If entity class doesn't exist, it creates the PSR-0 directory structure and generates it into there. If the entity does exist in the PSR-4 location, generator fails with this error:
Note, |
Looks like the origin of the issue is in Doctrine itself, which has the PSR-0 naming structure ingrained into the writeEntityClass method: https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/EntityGenerator.php#L341 May be difficult to change this without breaking BC |
PSR-4 is not supported in Doctrine. |
This last comment sounds slightly strange. Please clarify what do you mean. Why it is not supported? I think I can work on adding PSR-4 support to Doctrine. But first of all I should know if this is really needed. Or may be someone is already working on it. Do you think if this is possible? Thank you for your help! |
As said earlier, it looks like doctrine directly relates class namespaces to filesystem paths (converting from \ to / for example) and psr-4 allows for autoloading of classes whose namespaces don't directly map to their paths. E.g., I too wish I knew the plans for this for doctrine. I have to convert some code to psr 0 for some stuff due to this. Not too big of deal but... |
We don't plan to support psr-4.
|
Good to know. Thanks. |
@Ocramius, If someone were to submit a pull request to introduce PSR-4 support in a non intrusive way, what's the likelyhood of it being merged? |
Very unlikely right now.
|
@Ocramius why unlikely ? IMO, we should accept the support of generating classes in codebases using PSR-4 if we get a PR for it. Otherwise, lots of users won't be able to use it properly |
@stof we barely want support for code generation in the ORM right now...
|
@Ocramius I can say that the code gen has been helpful. Perhaps it shouldn't live where it does but I hope it lives on. |
@shideon yes, but we don't see real value in people running the generator over and over again. The generator is meant to be used to import legacy schemas, NOT to generate getters/setters and overwrite existing classes. I realize that this is a crusade against a functionality that is useful to some people, but we really only had a lot of bugs and misuses coming from it, and that for customizations that should be applied post code-generation by the developer that is working on the project. One of these customizations is the location of the generated files. |
Up on this feature, as it would be very useful. Is this planned ? Misread what Ocramius said, ok. That's funny because in Sf doc the doctrine:generate:entities is completly misused. |
@alex-ception Can you open an issue on the Symfony documentation repository if you think that it can be improved? |
Hi, I can't generate crud because of the base path Thx |
I understand why doctrine's team does not wan't psr-4 and generator, but some of us need to regenerate getter often. Especially when our silly brains are not able to anticipate all ideas of our customers and creates the perfect model from scratch. Here is a dirty-hack to enable doctrine:generate:entities with psr-4. In Mapping/DisconnectedMetadataFactory.php, line 144 :
In Doctrine\ORM\Tools\EntityGenerator.php
In Doctrine\ORM\Tools\EntityRepositoryGenerator.php
It works with psr-4 and i can do "app/console doctrine:generate:entities myBundle:myEntity" |
What about customize doctrine:generate:entities ? Instead of rebuild all doctrine with psr-4 support - witch seems complicated -, what about adding an argument to the command in order to activate folders mode :
This way each one can select the way it prefer ? |
Here is a fix for PSR-4 compatibility which acts as an optional lookup before the default PSR-1 path generation. It uses the composer autoloader to check for registered PSR-4 prefix paths. If for some reason no composer autoloader is present it continues to generate base paths the old way. It's therefore fully backwards compatible. https://gist.github.com/janvennemann/46b2626eee2a4808ed75 The entity and crud controller generators work out of the box with this fix. The path passed to the entity repository generator is still wrong and needs to be fixed, but i don't need that at the moment so i haven't done that yet. |
Thanks @Ocramius for the clarity on why this isn't a priority. The entity generation is great, but you need to generate them elsewhere and copy them over either way (even with PSR-4 support) to avoid overwriting existing entity files which may have additional logic in them. Adding PSR-4 support might lead people to use this over and over again to keep their entities up to date, which could be problematic. |
Voting for PSR-4 support. |
STOP_RE_GENERATING_ENTITIES_BASED_ON_DB_CHANGES |
I'm generating entities based on *.orm.yml schema. |
adding repositoryClass for example in yml requires to create that class, generate-task can do it for me, but without PSR-4 support i can't do that |
Same stuff: you write the entity classes. The code generation was never meant to be used as a "refresh" mechanism, and this scenario is actively considered feature abuse by doctrine core, so we don't support it. |
OK, what about creating new entities? Generation command is supported feature, so it should work in common cases. PSR-4 has the same rights to work as PSR-0 |
They'd just be generated in the PSR-0 path, and then you copy them over.
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
…On Fri, Aug 11, 2017 at 12:58 PM, Maksim Borisov ***@***.***> wrote:
OK, what about creating new entities? Generation command is supported
feature, so it should work in common cases. PSR-4 has the same rights to
work as PSR-0
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#282 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJakL6klXjIPWW5o4aNbwEaKuvbucjIks5sXDO8gaJpZM4BsgNw>
.
|
According to PSR-4, the namespace of a class doesn't have to be a direct mapping to the filesystem. See the first example of the specs
This doesn't look to be supported because of:
https://github.com/doctrine/DoctrineBundle/blob/master/Mapping/DisconnectedMetadataFactory.php#L143
This method tries to remove the namespace from the path, and fails because it can't find it.
e.g. of a bundle using PSR-4 and
VendorName\BundleName
as a prefixwill fail because there's no direct mapping
The text was updated successfully, but these errors were encountered: