From 94f03523b59a404f2452c8da55dc43f1f0857b48 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 21 Sep 2010 20:29:04 +0000 Subject: [PATCH] ENHACENEMENT: Change behaviour of the MenufestBuilder to use spl_autoload_register instead of traditional __autoload. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@111038 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/Core.php | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/core/Core.php b/core/Core.php index 92fdaacc1..e6db74c2f 100755 --- a/core/Core.php +++ b/core/Core.php @@ -189,6 +189,28 @@ set_include_path(str_replace('.' . PATH_SEPARATOR, '.' . PATH_SEPARATOR . BASE_PATH . '/sapphire/thirdparty' . PATH_SEPARATOR , get_include_path())); +/** + * Sapphire class autoloader. Requires the ManifestBuilder to work. + * $_CLASS_MANIFEST must have been loaded up by ManifestBuilder for this to successfully load + * classes. Classes will be loaded from any PHP file within the application. + * If your class contains an underscore, for example, Page_Controller, then the filename is + * expected to be the stuff before the underscore. In this case, Page.php. + * + * Class names are converted to lowercase for lookup to adhere to PHP's case-insensitive + * way of dealing with them. + */ +function sapphire_autoload($className) +{ + global $_CLASS_MANIFEST; + $lClassName = strtolower($className); + if(isset($_CLASS_MANIFEST[$lClassName])) include_once($_CLASS_MANIFEST[$lClassName]); + else if(isset($_CLASS_MANIFEST[$className])) include_once($_CLASS_MANIFEST[$className]); + +} + +spl_autoload_register('sapphire_autoload'); + + require_once("core/ManifestBuilder.php"); require_once("core/ClassInfo.php"); require_once('core/Object.php'); @@ -284,23 +306,6 @@ function getTempFolder($base = null) { return $ssTmp; } -/** - * Sapphire class autoloader. Requires the ManifestBuilder to work. - * $_CLASS_MANIFEST must have been loaded up by ManifestBuilder for this to successfully load - * classes. Classes will be loaded from any PHP file within the application. - * If your class contains an underscore, for example, Page_Controller, then the filename is - * expected to be the stuff before the underscore. In this case, Page.php. - * - * Class names are converted to lowercase for lookup to adhere to PHP's case-insensitive - * way of dealing with them. - */ -function __autoload($className) { - global $_CLASS_MANIFEST; - $lClassName = strtolower($className); - if(isset($_CLASS_MANIFEST[$lClassName])) include_once($_CLASS_MANIFEST[$lClassName]); - else if(isset($_CLASS_MANIFEST[$className])) include_once($_CLASS_MANIFEST[$className]); -} - /** * Return the file where that class is stored. *