A very lightweight module that registers Composer's Autoloader in Drupal 7.
This module is primarily to support the Backport module as the preferred or "native" Composer solution in Drupal 7, similar to what is now done in Drupal 8.
This is a standalone implementation and not a comprehensive solution like Composer Manager.
Installation
- Copy the module into your
sites/all/modules
folder. - Go to
/admin/modules
and enable theBackport Composer
in theUtilities
section (or if you use Drush:drush en backport_composer
).
Setup
By default, this module should immediately work "out-of-the-box" as it attempts to automatically locate the first viable autoload.php
file it can find.
The locations in which it searches depends greatly on how the site is configured and which modules are used.
There are five "root" paths this module checks:
- Drupal Root (indicates project level management):
DRUPAL_ROOT
- One level above Drupal Root (indicates project level management):
DRUPAL_ROOT/..
- Site specific files (whatever the variable
file_default_scheme
is set to):public://
- Site specific directory:
sites/example.com
orsites/default
as a fallback
- All sites directory:
sites/all
Finally, for each of the above ROOT
paths, this module will check if autoload.php
exists at one of the following locations:
ROOT/autoload.php
ROOT/vendor/autoload.php
ROOT/composer/autoload.php
ROOT/composer/vendor/autoload.php
ROOT/composer_manager/autoload.php
ROOT/composer_manager/vendor/autoload.php
This module only supports Composer Manager locations solely for the express purpose of easier transitioning or migration to a more "native" Composer workflow. This module should not be used if Composer Manager is installed.
Configuration
If you have Composer installed at a different location there are a couple ways you can customize which autoloader is used:
- Create a custom file in the root of your site (e.g.
./DOCROOT/autoload.php
) and then return the require of the Composer'sautoload.php
file from whichever location you need (similar to what Drupal 8 does):
return require '../../../sites/example.com/files/vendor/autoload.php';
- Set the following variable in your site's
settings.php
file to a path where Composer'sautoload.php
file resides:
$conf['backport_composer_autoload_path'] = DRUPAL_ROOT . '/../../../sites/example.com/files/vendor/autoload.php';
Notes
- The location of the Composer
autoload.php
file is cached, even if set as a variable in yoursettings.php
orsettings.local.php
file. This is to ensure that an absolute path is always ascertained in the event the variable uses relative positioning or contains any symbolic links. If its location changes, you will need to clear the database cache for it to be rediscovered. This is primarily to reduce unnecessary file system checks on each bootstrap. - If you create a custom
autoload.php
which requires anotherautoload.php
, you should always explicitly userequire
instead ofrequire_once
as the latter will returnTRUE
instead of the autoloader if it has already been required in PHP (which is a possibility). - If the variable
backport_composer_autoload_path
is set, it will always take precedence over any automated discovery if it is a valid path. If it isn't, it will fallback to automated discovery. - If the variable
page_cache_without_database
is set, it is also highly recommended that you explicitly set thebackport_composer_autoload_path
variable as not doing so may cause more than one intended file system check to determine the absolute path of theautoload.php
file as any cached value stored in the database will not be retrievable. - If the variable
page_cache_invoke_hooks
has been disabled, Composer'sautoload.php
will not be invoked or registered. This is a limitation of how page caching works and you will need to figure out a way to circumvent this and manually invokebackport_composer_autoloader()
if its functionality is desired at this step of the bootstrap phase.
Project information
- Unsupported
Not supported (i.e. abandoned), and no longer being developed. Learn more about dealing with unsupported (abandoned) projects - No further development
No longer developed by its maintainers. - Module categories: Developer Tools
- 1 site reports using this module
- Created by markhalliwell on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Development version: 7.x-1.x-dev updated 10 Mar 2018 at 19:28 UTC