[wp-trac] [WordPress Trac] #36335: Next generation: core autoloader proposal

WordPress Trac noreply at wordpress.org
Sun Sep 4 16:35:55 UTC 2016


#36335: Next generation: core autoloader proposal
-----------------------------+------------------
 Reporter:  dnaber-de        |       Owner:
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  4.7
Component:  General          |     Version:
 Severity:  normal           |  Resolution:
 Keywords:  has-patch        |     Focuses:
-----------------------------+------------------

Comment (by TJNowell):

 > And then there is the idea of bundling Composer with WordPress. What
 would
 > be benefit of that? For people who use composer already, or for end-
 users
 > who download and install plugins and themes from WP.org?

 Nobody is suggesting we bundle Composer with WordPress, Composer is a CLI
 tool, and to bundle it with Core would be very unusual. That's not how
 Composer is meant to be installed or used.

 What we're talking about is an autoloader, which is generated as output by
 the Composer tool, not Composer itself. It was mentioned because Composer
 generated autoloaders are widespread, well known, reliable, well tested,
 and have had the attention of some of the biggest companies and most
 experienced PHP developers alive. It's also in use in a great number of
 WordPress agencies, plugins, and themes, so there is existing familiarity
 with how it works, it's not a foreign unknown.

 This gets you these 10 files:

 * '''vendor/autoload.php''' - the bootstrapper
 * '''vendor/composer/ClassLoader.php''' - implements a PSR-0, PSR-4 and
 classmap class loader
 * '''vendor/composer/LICENSE''' - license
 * '''vendor/composer/autoload_classmap.php''' - an array of class names
 and the files they can be found in
 * '''vendor/composer/autoload_files.php''' - an array of files that will
 always be loaded immediatley
 * '''vendor/composer/autoload_namespaces.php''' - an array of folder to
 namespace mappings
 * '''vendor/composer/autoload_psr4.php''' - an array mapping folders to
 PSR4 namespaces
 * '''vendor/composer/autoload_real.php''' - an autogenerated class with a
 build specific hash in the name to create the autoloader and fill it with
 the above files
 * '''vendor/composer/autoload_static.php''' - a map of all
 classes/namespaces, and their files, an amalgam of the other
 autoload_*.php array files
 * '''vendor/composer/installed.json''' - a json file of what is being
 autoloaded

 Composer can also be passed a generator that controls what is generated
 when an autoloader is created. The above list is merely the default.

 I'm also unsure why we're renaming the vendor folder to wp-vendor, it's
 strange and non-standard.

 I'd also advise against including the autoloader in wp-config.php, wp-
 config.php is for setting constants and configuring, including the
 autoloader there will necessitate modifying every config file that exists
 already, as well as handling those scenarios when the file is up one
 directory, etc

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36335#comment:171>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list