From bc7c91a1bf933aa6bbfa46634d7c2d1dd3a9ba6e Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 19 Oct 2010 03:06:40 +0000 Subject: [PATCH] ENHACENEMENT: Change behaviour of the MenufestBuilder to use spl_autoload_register instead of traditional __autoload. (from r111038) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112870 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 ad50ed4ea..00fc5c046 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. *