From 6b640f81f2ed4ffdbac6036f5fb099a2c7f47e51 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 12 Sep 2016 17:26:31 +1200 Subject: [PATCH] =?UTF-8?q?FIX:=20Don=E2=80=99t=20double-include=20compose?= =?UTF-8?q?r=20autoloader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If another file is include main.php and has included composer already, code might get weird. In particular, if the parent context includes a different vendor/autoload.php than the one main.php expects. --- main.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/main.php b/main.php index b35ab9f44..27c11e6fc 100644 --- a/main.php +++ b/main.php @@ -57,17 +57,19 @@ if (version_compare(phpversion(), '5.5.0', '<')) { * @see Director::direct() */ -// require composers autoloader -if (file_exists($autoloadPath = dirname(__DIR__) . '/vendor/autoload.php')) { - require_once $autoloadPath; -} -else { - if (!headers_sent()) { - header($_SERVER['SERVER_PROTOCOL'] . " 500 Server Error"); - header('Content-Type: text/plain'); +// require composers autoloader, unless it is already installed +if(!class_exists('Composer\\Autoload\\ClassLoader', false)) { + if (file_exists($autoloadPath = dirname(__DIR__) . '/vendor/autoload.php')) { + require_once $autoloadPath; + } + else { + if (!headers_sent()) { + header($_SERVER['SERVER_PROTOCOL'] . " 500 Server Error"); + header('Content-Type: text/plain'); + } + echo "Failed to include composer's autoloader, unable to continue\n"; + exit(1); } - echo "Failed to include composer's autoloader, unable to continue\n"; - exit(1); } // IIS will sometimes generate this.