Skip to content
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

Console command d:g:entities cannot find base path #723

Closed
silverbackdan opened this issue Oct 23, 2017 · 14 comments
Closed

Console command d:g:entities cannot find base path #723

silverbackdan opened this issue Oct 23, 2017 · 14 comments

Comments

@silverbackdan
Copy link

With the new directory structure for Symfony 3.4+ getBasePathForClass returns a runtime exception:
https://github.com/doctrine/DoctrineBundle/blob/master/Mapping/DisconnectedMetadataFactory.php#L151

It looks like the function attempts to find the namespace in the path. Because 'AppBundle' is not longer in the file path and it is just within the 'src' directory I get the error:
Can't find base path for "App\Entity\XXX"

@silverbackdan
Copy link
Author

The possible solution I've got would require a PR on 2 bundles, although I'm not sure where to raise this.
Change 1:
https://github.com/doctrine/DoctrineBundle/blob/master/Mapping/DisconnectedMetadataFactory.php#L151

private function getBasePathForClass($name, $namespace, $path)
    {
        $namespace = str_replace('\\', '/', $namespace);
        $search = str_replace('\\', '/', $path);
        if ($namespace === 'App/Entity') {
            $destination = str_replace('/Entity', '', $search, $c);
        } else {
            $destination = str_replace('/'.$namespace, '', $search, $c);
        }

        if ($c != 1) {
            throw new \RuntimeException(sprintf('Can\'t find base path for "%s" (path: "%s", destination: "%s").', $name, $path, $destination));
        }

        return $destination;
    }

Change 2:
doctrine/orm/lib/Doctrine/ORM/Tools/EntityGenerator.php Line 361 writeEntityClass

public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory)
    {
        $metaNamePath = substr($metadata->name, 0, 4) === 'App\\' ? substr($metadata->name, 4) : $metadata->name;
        $path = $outputDirectory . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $metaNamePath) . $this->extension;

Not sure if this is ideal though or if the bundle should perhaps alter the name in the metadata instead. Thoughts?

@gaelb80
Copy link

gaelb80 commented Nov 8, 2017

Your proposal only work when entities are in Entity folder and don't manage subfolder
You should update according this one

private function getBasePathForClass($name, $namespace, $path)
    {
        $namespace = str_replace('\\', '/', $namespace);
        $search = str_replace('\\', '/', $path);
        $namepath = substr($namespace, 0, 4) != 'App/' ? : substr($namespace, 4);
        $destination = str_replace('/'.$namepath, '', $search, $c);

        if ($c != 1) {
            throw new \RuntimeException(sprintf('Can\'t find base path for "%s" (path: "%s", destination: "%s").', $name, $path, $destination));
        }

        return $destination;
    }

See #729 for more informations

@silverbackdan
Copy link
Author

Thanks for the link to the other issue, in fact that means I can close this as I hadn't seen it. The comments in there are very useful to know the direction that this bundle is taking.

@kporras07
Copy link

hi there,
I know this one is closed; however I'm still getting this issue with Symfony 4 recently launched.
Any idea? (I'm sorry for cross-posting in the other issue)

@chiqui3d
Copy link

It does not generate the setters and getters.

php bin/console doctrine:generate:entities App:Cars

error:

Can't find base path for "App\Entity\Cars" (path: "/www/crm/src/Entity", destination: "/www/crm/src/Entity").

@pierre-H
Copy link

Same error like @kporras07 and @chiqui3d

@Kuro-dake
Copy link

Same error as @pierre-H @kporras07 @chiqui3d

@featuriz
Copy link

featuriz commented Feb 3, 2018

Same error for me to , I'm using symfony 4.0.4.
The error is :

Generating entities for namespace "App"

In DisconnectedMetadataFactory.php line 158:

Can't find base path for "App\Entity\Contact" (path: "/home/sudhakar/Sudhak
arK/NB/2018/FZCMS/src/Entity", destination: "/home/sudhakar/SudhakarK/NB/20
18/FZCMS/src/Entity").

@stefanides
Copy link

Hi,
while facing the same issue as above (and while reading #729 "the feature is gone"), I was just trying to get it working - and got the entities with getters&setters successfully! This is a great feature I have used several times and it should not be removed :-(

symfony/framework-bundle                 v4.0.4 
doctrine/orm                             v2.6.0 

Maybe the steps below are not 100% accurate as I have tried a lot of different attempts..

  • read mapping as XML php ./bin/console doctrine:mapping:convert xml --from-database src/Entity/
  • create "virtual" bundle - src/AppBundle/AppBundle.php:
<?php
namespace App\AppBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AppBundle extends Bundle {
}

  • copy XML mappings into src/AppBundle/Resources/config/doctrine (where they are expected from symfony 3.x)
  • and update entity name in XML to full path <entity name="App\AppBundle\Entity\XXX"
  • then run php ./bin/console doctrine:generate:entities "App\AppBundle\Entity" --path=src

And voila - in little strange path src/App/AppBundle/Entity there is the expected result :-)
(note that you cannot call it twice, then autoloader reports error in namespaces - just remove src/App and try again). Probably there might be also other ways/paths how to do the same..
Enjoy :-)

@atakansavas
Copy link

i am getting this error too @Kuro-dake @pierre-H @kporras07 @chiqui3d

@artandor
Copy link

artandor commented Mar 6, 2018

I'm still having this error aswell, with the exact same message, pleae reopen the issue.

@alcaeus
Copy link
Member

alcaeus commented Mar 6, 2018

pleae reopen the issue

Please look at #729.

@silverbackdan
Copy link
Author

I don't think that's a good idea. Read the conversation and you'll see it is not going to be a feature anymore or Doctrine. If you're going to pester the collaborators about it then you can open a new PR, I'm not willing to do this. I'd expect new PRs to be closed quickly referencing #729 conversation anyway.

@silverbackdan
Copy link
Author

@Ocramius - I'd appreciate if this conversation was locked as well to prevent conversations spilling over to here. Some will find it hard to say goodbye to this feature it seems.

@doctrine doctrine locked as resolved and limited conversation to collaborators Mar 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests