From d11248dcc89cf972f2479fcd36dc449d1ecbd157 Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Tue, 24 Oct 2017 16:33:22 +0200 Subject: [PATCH] add autoload in config --- config/autoload_lumen.php | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 config/autoload_lumen.php diff --git a/config/autoload_lumen.php b/config/autoload_lumen.php new file mode 100644 index 00000000..596890ca --- /dev/null +++ b/config/autoload_lumen.php @@ -0,0 +1,63 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 6874 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +spl_autoload_register(function($className) { + if (function_exists('smartyAutoload') AND smartyAutoload($className)) + return true; + + if (function_exists('Predis\predisAutoload') AND Predis\predisAutoload($className)) { + return true; + } + + $className = str_replace(chr(0), '', $className); + $classDir = dirname(__FILE__).'/../classes/'; + $overrideDir = dirname(__FILE__).'/../override/classes/'; + $file_in_override = file_exists($overrideDir.$className.'.php'); + $file_in_classes = file_exists($classDir.$className.'.php'); + + // This is a Core class and its name is the same as its declared name + if (substr($className, -4) == 'Core') + require_once($classDir.substr($className, 0, -4).'.php'); + else + { + if ($file_in_override && $file_in_classes) + { + require_once($classDir.str_replace(chr(0), '', $className).'.php'); + require_once($overrideDir.$className.'.php'); + } + elseif (!$file_in_override && $file_in_classes) + { + require_once($classDir.str_replace(chr(0), '', $className).'.php'); + $classInfos = new ReflectionClass($className.((interface_exists($className, false) or class_exists($className, false)) ? '' : 'Core')); + if (!$classInfos->isInterface() && substr($classInfos->name, -4) == 'Core') + eval(($classInfos->isAbstract() ? 'abstract ' : '').'class '.$className.' extends '.$className.'Core {}'); + } + elseif ($file_in_override && !$file_in_classes) + require_once($overrideDir.$className.'.php'); + } +}); +