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

fix: use classmap instead of files for Composer autoload #965

Merged
merged 2 commits into from
May 21, 2020
Merged

fix: use classmap instead of files for Composer autoload #965

merged 2 commits into from
May 21, 2020

Conversation

kampalex
Copy link
Contributor

Fixes

This PR fixes #963 reported by @SamMousa. It reduces the number of files which are loaded 'always' after including the autoload.php generated by Composer. Missing classes will be loaded 'on demand'.

Result of temporary file '(workdir)\testing.php' containing:

<?php

require_once("vendor/autoload.php");
print_r(get_included_files());

Using files directive:

Array
(
    [0] => (workdir)\testing.php
    [1] => (workdir)\vendor\autoload.php
    [2] => (workdir)\vendor\composer\autoload_real.php
    [3] => (workdir)\vendor\composer\ClassLoader.php
    [4] => (workdir)\vendor\composer\autoload_static.php
    [5] => (workdir)\vendor\symfony\polyfill-ctype\bootstrap.php
    [6] => (workdir)\vendor\myclabs\deep-copy\src\DeepCopy\deep_copy.php
    [7] => (workdir)\lib\BaseInterface.php
    [8] => (workdir)\lib\SendGrid.php
    [9] => (workdir)\lib\TwilioEmail.php
    [10] => (workdir)\test\BaseTestClass.php
    [11] => (workdir)\vendor\phpunit\phpunit\src\Framework\TestCase.php
    [12] => (workdir)\vendor\phpunit\phpunit\src\Framework\Assert.php
    [13] => (workdir)\vendor\phpunit\phpunit\src\Framework\Test.php
    [14] => (workdir)\vendor\phpunit\phpunit\src\Framework\SelfDescribing.php
)

Using classmap directive:

Array
(
    [0] => (workdir)\testing.php
    [1] => (workdir)\vendor\autoload.php
    [2] => (workdir)\vendor\composer\autoload_real.php
    [3] => (workdir)\vendor\composer\ClassLoader.php
    [4] => (workdir)\vendor\composer\autoload_static.php
    [5] => (workdir)\vendor\symfony\polyfill-ctype\bootstrap.php
    [6] => (workdir)\vendor\myclabs\deep-copy\src\DeepCopy\deep_copy.php
)

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the master branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

kampalex added 2 commits May 19, 2020 15:38
Updated code base from upstream repository
…of 'files' (load always)

Signed-off-by: Alexander Kamp <[email protected]>
@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label May 19, 2020
Copy link
Contributor

@childish-sambino childish-sambino left a comment

Choose a reason for hiding this comment

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

LGTM. Nice work.

@childish-sambino childish-sambino changed the title Composer autoload: use classmap instead of files fix: use classmap instead of files for Composer autoload May 21, 2020
@childish-sambino childish-sambino merged commit 7b4457f into sendgrid:master May 21, 2020
@kampalex kampalex deleted the feature-composer-autoload-classmap branch June 8, 2020 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: code review request requesting a community code review or review from Twilio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Composer autoloader unnecessarily includes files
3 participants