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/modulesfolder. - Go to
/admin/modulesand enable theBackport Composerin theUtilitiessection (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_schemeis set to):public://
- Site specific directory:
sites/example.comorsites/defaultas 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.phpROOT/vendor/autoload.phpROOT/composer/autoload.phpROOT/composer/vendor/autoload.phpROOT/composer_manager/autoload.phpROOT/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.phpfile 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.phpfile to a path where Composer'sautoload.phpfile resides:
$conf['backport_composer_autoload_path'] = DRUPAL_ROOT . '/../../../sites/example.com/files/vendor/autoload.php';
Notes
- The location of the Composer
autoload.phpfile is cached, even if set as a variable in yoursettings.phporsettings.local.phpfile. 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.phpwhich requires anotherautoload.php, you should always explicitly userequireinstead ofrequire_onceas the latter will returnTRUEinstead of the autoloader if it has already been required in PHP (which is a possibility). - If the variable
backport_composer_autoload_pathis 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_databaseis set, it is also highly recommended that you explicitly set thebackport_composer_autoload_pathvariable as not doing so may cause more than one intended file system check to determine the absolute path of theautoload.phpfile as any cached value stored in the database will not be retrievable. - If the variable
page_cache_invoke_hookshas been disabled, Composer'sautoload.phpwill 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) projectsNo further development
No longer developed by its maintainers.- Project categories: Developer tools
- Created by markhalliwell on , updated
Stable releases for this project are covered by the security advisory policy.
There are currently no supported stable releases.
