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

Fixed autoloader patch to work with composer-installed setup #3226

Merged
merged 1 commit into from
May 2, 2023

Conversation

colinmollenhour
Copy link
Member

As per #3216 this adds back the automatic detection of vendor in the parent directory of BP.

@github-actions github-actions bot added the Mage.php Relates to app/Mage.php label May 1, 2023
@fballiano
Copy link
Contributor

isnt't there a way to say "require dirname(DIR) . etc etc OR require DIR . etc etc", to keep it some sort of one liner?

@colinmollenhour
Copy link
Member Author

isnt't there a way to say "require dirname(DIR) . etc etc OR require DIR . etc etc", to keep it some sort of one liner?

Maybe... I try to stick with common stuff that everyone can easily read, though. If it takes more than a few seconds to come up with it will probably be confusing to some readers. :)

@fballiano
Copy link
Contributor

the thing with require that it triggers an error otherwise it would be super easy to read:
require ../vendor/autoload.php || require vendor/autoload.php
but...

Copy link
Contributor

@fballiano fballiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

briefly tested

@fballiano fballiano merged commit d3dcc76 into OpenMage:main May 2, 2023
@fballiano fballiano changed the title Fix autoloader patch to work with composer-installed setup. Fixed autoloader patch to work with composer-installed setup May 2, 2023
@m-overlund
Copy link
Contributor

This patch seems to crash my site (non-composer install)

@elidrissidev
Copy link
Member

This patch seems to crash my site (non-composer install)

Even the non-composer install should normally have the vendor folder. What's the error you're getting?

@m-overlund
Copy link
Contributor

i believe it was a open basedir restriction - trying to load vendor dir outside public_html instead of in public_html.
Will check later on

@m-overlund
Copy link
Contributor

@elidrissidev it was open basedir restriction for is_dir() function - trying to find vendor folder outside public_html.
It gives me a lot of errors every second.

did a dirty fix of the composer patch in get.php and app/Mage.php by including public_html in the path and the errors are gone.

(It however still doesn't seem to load things like redis session module for instance, from the vendor)

$autoloaderPath = getenv('COMPOSER_VENDOR_PATH');
if (!$autoloaderPath) {
    $autoloaderPath = dirname($bp) . $ds . 'public_html' . $ds .  'vendor';

@elidrissidev
Copy link
Member

@m-overlund ahh got it. You could also avoid the issue by setting COMPOSER_VENDOR_PATH env variable in your vhost or htaccess.

@fballiano @colinmollenhour What do you think if the two lines were swapped instead, since most installs will likely have vendor within the same folder?

 $autoloaderPath = getenv('COMPOSER_VENDOR_PATH');
 if (!$autoloaderPath) {
-    $autoloaderPath = dirname(BP) . DS .  'vendor';
+    $autoloaderPath = BP . DS . 'vendor';
     if (!is_dir($autoloaderPath)) {
-        $autoloaderPath = BP . DS . 'vendor';
+        $autoloaderPath = dirname(BP) . DS .  'vendor';
     }
 }

@fballiano
Copy link
Contributor

@elidrissidev I think it was done this way for some reason but I can recall it from top of my head now

@m-overlund
Copy link
Contributor

m-overlund commented Sep 13, 2023

@m-overlund ahh got it. You could also avoid the issue by setting COMPOSER_VENDOR_PATH env variable in your vhost or htaccess.

Thanks - that was a better solution.

Maybe it should be added to htaccess (commented out)
and to Readme, if it is required, and cannot be fixed otherwise

@addison74
Copy link
Contributor

Creating a variable for Nginx webserver must also be provided. You can push a PR that includes the modification in .htaccess and a paragraph in the README file.

@colinmollenhour
Copy link
Member Author

What do you think if the two lines were swapped instead, since most installs will likely have vendor within the same folder?

No objection. I think the motivation was to prevent an attacker from creating a vendor directory in the root which overrides the one in the parent directory, but I think if that prevents people from using open_basedir then it is preferable to have open_basedir supported.

@m-overlund
Copy link
Contributor

Creating a variable for Nginx webserver must also be provided. You can push a PR that includes the modification in .htaccess and a paragraph in the README file.

I don't believe it will be necessary if switching the lines ends up being implemented, like @colinmollenhour suggests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mage.php Relates to app/Mage.php
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants