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

Classnames that violate the PSR-0 convention are not covered by composer's autoloader #7

Closed
ssaki opened this issue Jul 8, 2015 · 1 comment

Comments

@ssaki
Copy link

ssaki commented Jul 8, 2015

Since PSR-0 explicitly mandates that underscores in file names must be translated into directory separators to locate the file the following files will throw an exception:

  • src/MaxCDN/OAuth/OAuthSignatureMethod_PLAINTEXT.php
  • src/MaxCDN/OAuth/OAuthSignatureMethod_HMAC_SHA1.php
  • src/MaxCDN/OAuth/OAuthSignatureMethod_RSA_SHA1.php

unless the "composer dumpautoload --optimize" was executed either directly or via the install/update commands (with the "--optimize-autoloader" option).

[Wed Jul 08 15:12:34.182097 2015] [:error] [pid 1324] [client 192.168.122.1:41655] PHP Fatal error: Class 'MaxCDN\OAuth\OAuthSignatureMethod_HMAC_SHA1' not found in /var/www/site/releases/20150708154715/vendor/maxcdn/php-maxcdn/src/MaxCDN.php on line 44, referer: https://site.localhost/.....
[Wed Jul 08 15:12:34.182146 2015] [:error] [pid 1324] [client 192.168.122.1:41655] PHP Stack trace:, referer: https://site.localhost/.....
...........
[Wed Jul 08 15:12:34.182268 2015] [:error] [pid 1324] [client 192.168.122.1:41655] PHP 11. MaxCDN->delete(....)
[Wed Jul 08 15:12:34.182279 2015] [:error] [pid 1324] [client 192.168.122.1:41655] PHP 12. MaxCDN->execute(...)

There are two possible solutions:

  1. move the files in subdirectories according to PSR-0, e.g. src/MaxCDN/OAuth/OAuthSignatureMethod_HMAC_SHA1.php shold be moved to src/MaxCDN/OAuth/OAuthSignatureMethod/HMAC/SHA1.php
  2. update the composer to use classmap to include those files

The project's readme currently states that

It is advised that you understand how to optimze Composer's usage in Production environments.

But this could prove to be ill advice as what the --optimize-autoloader option actually does is to scan all included files and dump a classmap for you. This could be an optimization if the project has a sane amount of dependencies/classes, but on legacy projects with tons of seldom used files this has the potential to produce monstrous classmap file (in my case ~600kB :) ) and become anti-optimisation.

@ssaki
Copy link
Author

ssaki commented Jul 8, 2015

FTR: the pull request will also fix #3

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

No branches or pull requests

2 participants