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

Create autoloader that include all package namespaces #57

Closed
ScreamingDev opened this issue Jan 27, 2021 · 2 comments
Closed

Create autoloader that include all package namespaces #57

ScreamingDev opened this issue Jan 27, 2021 · 2 comments

Comments

@ScreamingDev
Copy link

Right now every package namespace creates its own autoloader:

  • vendor/autoload.php
  • vendor-bin/foo/vendor/autoload.php
  • vendor-bin/bar/vendor/autoload.php
  • vendor-bin/baz/vendor/autoload.php

From my own experience and lately discussed in composer/composer#9636
a custom autoloader could be a thing:

  • The vendor/autoload.php should append all the swapped autoloader too
  • The swapped autoloader should append the application autoloader

Right now developer can do this on their own:

<?php

require_once 'vendor-bin/test/vendor/autoload.php';
require_once 'vendor/autoload.php';

But this needs some hands on when adding another section

composer bin require new-section bar/baz

Having this more dynamically would be a little helper.

Suggestion

The common/central "vendor/autoload.php" should be changed to:

require_once 'vendor/composer/autoload_real.php';

$loader = ComposerAutoloaderInit1234::getLoader();

require_once 'vendor-bin/tools/dev/autoload.php';
require_once 'vendor-bin/tools/tool-a/autoload.php';
require_once 'vendor-bin/tools/tool-b/autoload.php';

return $loader;

In the same order as given in the JSON, to give users control about the autoloading order.
While the single tools put their own autoloader on top ("vendor-bin/tools/dev/autoload.php"):

require_once '/vendor/tools/composer/autoload_real.php';

$loader = ComposerAutoloaderInit6789::getLoader();

require_once 'vendor/autoload.php';

return $loader;

Something like this (just a quick fuzzy example).

Note: Including each another file does not lead to endless recursive includes.
The require_once returns the object on the first include and just TRUE for any further call.

@theofidry
Copy link
Collaborator

theofidry commented Jan 29, 2021

I think combining the autoloaders of multiple vendor-bin is a terrible idea: it completely defeat the purpose of Composer which is to prevent you to autoload incompatible code and will lead to subtle and terribly hard to debug issues that can pop up at any time.

What's the goal here?

@theofidry
Copy link
Collaborator

Closing for the reasons explained in #58

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