Skip to content

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

@ssaki

Description

@ssaki

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions