Skip to content

Commit ed86ee1

Browse files
committed
Add setting ['composer_autoload']
Supersedes PR bcit-ci#3132
1 parent 9fa275e commit ed86ee1

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

application/config/config.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
*/
122122
$config['enable_hooks'] = FALSE;
123123

124-
125124
/*
126125
|--------------------------------------------------------------------------
127126
| Class Extension Prefix
@@ -136,6 +135,27 @@
136135
*/
137136
$config['subclass_prefix'] = 'MY_';
138137

138+
/*
139+
|--------------------------------------------------------------------------
140+
| Composer auto-loading
141+
|--------------------------------------------------------------------------
142+
|
143+
| Enabling this setting will tell CodeIgniter to look for a Composer
144+
| package auto-loader script in application/vendor/autoload.php.
145+
|
146+
| $config['composer_autoload'] = TRUE;
147+
|
148+
| Or if you have your vendor/ directory located somewhere else, you
149+
| can opt to set a specific path as well:
150+
|
151+
| $config['composer_autoload'] = '/path/to/vendor/autoload.php';
152+
|
153+
| For more information about Composer, please visit http://getcomposer.org/
154+
|
155+
| Note: This will NOT disable or override the CodeIgniter-specific
156+
| autoloading (application/config/autoload.php)
157+
*/
158+
$config['composer_autoload'] = FALSE;
139159

140160
/*
141161
|--------------------------------------------------------------------------

system/core/CodeIgniter.php

+17
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,23 @@ function &get_instance()
447447
$params = array_slice($URI->rsegments, 2);
448448
}
449449

450+
/*
451+
* ------------------------------------------------------
452+
* Should we use a Composer autoloader?
453+
* ------------------------------------------------------
454+
*/
455+
if (($composer_autoload = config_item('composer_autoload')) !== FALSE)
456+
{
457+
if ($composer_autoload === TRUE && file_exists(APPPATH.'vendor/autoload.php'))
458+
{
459+
require_once(APPPATH.'vendor/autoload.php');
460+
}
461+
elseif (file_exists($composer_autoload))
462+
{
463+
require_once($composer_autoload);
464+
}
465+
}
466+
450467
/*
451468
* ------------------------------------------------------
452469
* Is there a "pre_controller" hook?

user_guide_src/source/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Release Date: Not Released
6161
- Added availability checks where usage of dangerous functions like ``eval()`` and ``exec()`` is required.
6262
- Added support for changing the file extension of log files using ``$config['log_file_extension']``.
6363
- Added support for turning newline standardization on/off via ``$config['standardize_newlines']`` and set it to FALSE by default.
64+
- Added configuration setting ``$config['composer_autoload']`` to enable loading of a `Composer <https://getcomposer.org/>`_ auto-loader.
6465

6566
- Helpers
6667

user_guide_src/source/general/autoloader.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ file and add the item you want loaded to the autoload array. You'll
2020
find instructions in that file corresponding to each type of item.
2121

2222
.. note:: Do not include the file extension (.php) when adding items to
23-
the autoload array.
23+
the autoload array.
24+
25+
Additionally, if you want CodeIgniter to use a `Composer <https://getcomposer.org/>`_
26+
auto-loader, just set ``$config['composer_autoload']`` to ``TRUE`` or
27+
a custom path in **application/config/config.php**.

0 commit comments

Comments
 (0)