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

vendor/bin/doctrine won't work, reporting missing 'doctrine.php' #8563

Closed
cybercitizen7 opened this issue Mar 26, 2021 · 7 comments · Fixed by #8564
Closed

vendor/bin/doctrine won't work, reporting missing 'doctrine.php' #8563

cybercitizen7 opened this issue Mar 26, 2021 · 7 comments · Fixed by #8564

Comments

@cybercitizen7
Copy link

cybercitizen7 commented Mar 26, 2021

I was following the doctrine2-ORM Getting Started Guide (just learning about Doctrine) where I encountered a following issue.

ERROR MESSAGE:

PHP Warning:  include(doctrine.php): Failed to open stream: No such file or directory in D:\*mypathtoproject*\DoctrineORM\doctrine2-tutorial\vendor\bin\doctrine(25) : eval()'d code on line 2
PHP Warning:  include(): Failed opening 'doctrine.php' for inclusion (include_path='.;C:\php\pear') in D:\*mypathtoproject*\DoctrineORM\doctrine2-tutorial\vendor\bin\doctrine(25) : eval()'d code on line 2

DOCTRINE CODE:

#!/usr/bin/env php
<?php

/**
 * Proxy PHP file generated by Composer
 *
 * This file includes the referenced bin path (../doctrine/orm/bin/doctrine) using eval to remove the shebang if present
 *
 * @generated
 */

$binPath = realpath(__DIR__ . "/" . '../doctrine/orm/bin/doctrine');
$contents = file_get_contents($binPath);
$contents = preg_replace('{^#!/.+\r?\n<\?(php)?}', '', $contents, 1, $replaced);

if ($replaced) {
    $contents = strtr($contents, array(
        '__FILE__' => var_export($binPath, true),
        '__DIR__' => var_export(dirname($binPath), true),
    ));
    eval($contents);
    exit(0);
}
include $binPath;

This code returns include(doctrine.php), however, this will of course not work, because doctrine.php is NOT present in the current directory where we are executing the vendor/bin/doctrine.

However, when I commented out the if block, the code executed as expected. I assume this works because the $binPath correctly holds the absolute path to where doctrine.php is present.

This raises the question, why do we even do eval() in this script block? including the absolute path to doctrine.php seems to work just nice.

@cybercitizen7 cybercitizen7 changed the title doctrine strips away the binPath and vendor/bin/doctrine won't work vendor/bin/doctrine won't work, reporting missing 'doctrine.php' Mar 26, 2021
@greg0ire
Copy link
Member

Thanks for reporting this, but bear in mind that this script is generated by Composer so even if we (Doctrine) don't need the eval, the fix for that will not happen in doctrine/orm but in composer/composer.

However, when I look at the excerpt of code you are showing, it looks like this could be fixed by using __DIR__. Would you kindly edit vendor/doctrine/orm/doctrine so that it looks like this:

#!/usr/bin/env php
<?php

include(__DIR__ . '/doctrine.php');

And then report back?

@cybercitizen7
Copy link
Author

Thanks for reporting this, but bear in mind that this script is generated by Composer so even if we (Doctrine) don't need the eval, the fix for that will not happen in doctrine/orm but in composer/composer.

However, when I look at the excerpt of code you are showing, it looks like this could be fixed by using __DIR__. Would you kindly edit vendor/doctrine/orm/doctrine so that it looks like this:

#!/usr/bin/env php
<?php

include(__DIR__ . '/doctrine.php');

And then report back?

Hey @greg0ire, thanks for comming back to me on this. First, I apologize for opening this issue in Doctrine Project, rather than Composer - thought it was part of the Doctrine.

And yes, if I do the change like you said, it works.

Do you believe this is worth reporting as a some sort of a Bug in Composer ?

@greg0ire
Copy link
Member

Hey @greg0ire, thanks for comming back to me on this. First, I apologize for opening this issue in Doctrine Project, rather than Composer - thought it was part of the Doctrine.

Oh no you're in the right place actually, because as you just proved to yourself it can be fixed here.

And yes, if I do the change like you said, it works.

Then please send a PR

Do you believe this is worth reporting as a some sort of a Bug in Composer?

I'm not sure. When you remove the if block, you said it worked, but doesn't it also print the shebang to the output? #!/usr/bin/env php <-- that's the shebang

@cybercitizen7
Copy link
Author

When I execute this:
$ vendor/bin/doctrine orm:schema-tool:create

with if-block commented out, it outputs:

[OK] No Metadata Classes to process.

This is (at the moment) expected output. I do not see the shebang part though, at least not in my CMD console. Do you expect the shebang output elsewhere?

potential_bug_investigation_doctrine

@cybercitizen7
Copy link
Author

@greg0ire I believe that the shebang part is only because of fetching the file contents from the /doctrine/orm/bin/doctrine.

But as for the usage of the script, I am not sure if this is necessary at all. We just need the $binPath to the doctrine.php file., as we want to include it in our project. Maybe this feature is needed for some other OS?

If not, I believe better fix is actually removing all of the REGEX and IF and just send the $binPath to the include statement, which will eventually include the doctrine.php file.

@greg0ire
Copy link
Member

I was expecting the shebang to be wrongly output, but it looks like it isn't. So maybe you can try reporting that to Composer.

@greg0ire greg0ire linked a pull request Mar 26, 2021 that will close this issue
@cybercitizen7
Copy link
Author

Will try reaching out. Thanks.

With this I believe we can close this issue at Doctrine's site. :)

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 a pull request may close this issue.

2 participants