Skip to content

"make:entity" root directory location improvment #265

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

Closed
wants to merge 1 commit into from

Conversation

bastos71
Copy link

As a developer using Symfony 3.x, I got issues using make:entity

I made this pull request to allow users to override the hardcoded src/Entity/ as the root directory for entities.
Now there are two ways to override it :

  • define the new available configuration in your config.yml
maker:
    root_namespace: Acme\AwesomeBundle
    root_entity_directory: src/Acme/AwesomeBundle/Entity/
  • use the new option of the make:entity command :
php bin/console make:entity --rootdir=src/Acme/AwesomeBundle/Entity/

Anyway the file will be created to the correct location (corresponding to the class namespace), that was already the case before my pull request.

@bastos71
Copy link
Author

The error returned by the AppVeyor build seems not to be dued to my development :

Error: "PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "Kernel" from namespace "Custom"

@weaverryan
Copy link
Member

Hey @bastos71!

Ah, I think I understand the issue: it's just that the auto-complete questions don't fill from the correct entity directory - that part IS indeed hardcoded. But, I think there's a better solution - and I think you already saw the PR I'm talking about :) #185 (comment)

As I mentioned there, there's no reason to force the user to think/configure an option at all. We can ask Doctrine for the list of mapped entity and create an auto-complete list from that. In fact, I think we may already have the hard part done :) - see:

public function getEntitiesForAutocomplete(): array
{
$entities = [];
if ($this->isDoctrineInstalled()) {
$allMetadata = $this->getMetadata();
/* @var ClassMetadata $metadata */
foreach (array_keys($allMetadata) as $classname) {
$entityClassDetails = new ClassNameDetails($classname, $this->entityNamespace);
$entities[] = $entityClassDetails->getRelativeName();
}
}
return $entities;
}

This code was created after MakeEntity I believe, so we may just be able to point to that and fix it. Would you be willing to try it?

@bastos71
Copy link
Author

Thanks for your reply @weaverryan
Ok I will try to implement this, parsing the list of mapped entities to get a list of namespaces.

But what if the user tries to create its very First Entity ? That means there would not have any mapped entities, so no namespace to list :/

@weaverryan
Copy link
Member

Closing in favor of #310 or #311

@weaverryan weaverryan closed this Nov 2, 2018
weaverryan added a commit that referenced this pull request Dec 20, 2018
This PR was squashed before being merged into the 1.0-dev branch (closes #311).

Discussion
----------

Fix Entity directory does not exist

Closes #299 according to #185 (comment)

Also alternative for #185, #265 and #310

Commits
-------

5f37c5d Remove invalid field mapping
06f5399 Invalidating cached AnnotationDriver::$classNames to find new entities
8b7c291 Fix 'src/Entity' directory does not exist
saylor-mik87786 added a commit to saylor-mik87786/maker-bundle that referenced this pull request Jun 3, 2025
This PR was squashed before being merged into the 1.0-dev branch (closes #311).

Discussion
----------

Fix Entity directory does not exist

Closes #299 according to symfony/maker-bundle#185 (comment)

Also alternative for symfony/maker-bundle#185, symfony/maker-bundle#265 and symfony/maker-bundle#310

Commits
-------

5f37c5d Remove invalid field mapping
06f5399 Invalidating cached AnnotationDriver::$classNames to find new entities
8b7c291 Fix 'src/Entity' directory does not exist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants