diff options
author | robocoder <anthon.pang@gmail.com> | 2009-06-15 06:17:33 +0400 |
---|---|---|
committer | robocoder <anthon.pang@gmail.com> | 2009-06-15 06:17:33 +0400 |
commit | 50018b34168c9144eda92f87131220c5c85218ff (patch) | |
tree | faac5f8d82d0f02ad9997d8c69fe238c149580a3 /index.php | |
parent | dd109ef3709e72c38c056c2043ed10ebe2e7864d (diff) |
fixes #801, fixes #620 - implement autoloader; remove require_once
FrontController.php from ./index.php to test autoloader; add "false"
parameter to all class_exists() calls to not trigger autoloader
git-svn-id: http://dev.piwik.org/svn/trunk@1221 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'index.php')
-rwxr-xr-x | index.php | 44 |
1 files changed, 41 insertions, 3 deletions
@@ -19,11 +19,50 @@ if(!defined('PIWIK_INCLUDE_PATH')) define('PIWIK_INCLUDE_PATH', dirname(__FILE__)); } -if((@include "Version.php") === false || !class_exists('Piwik_Version')) { +if((@include "Version.php") === false || !class_exists('Piwik_Version', false)) +{ set_include_path(PIWIK_INCLUDE_PATH . '/core' . PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/libs' . PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/plugins'); } + +function piwikAutoloader($class) +{ + $class = str_replace('_', '/', $class) . '.php'; + if(substr($class, 0, 6) === 'Piwik/') + { + $class = substr($class, 6); + if(file_exists(PIWIK_INCLUDE_PATH . "/core/" . $class)) + { + include_once PIWIK_INCLUDE_PATH . "/core/" . $class; + } + else + { + include_once PIWIK_INCLUDE_PATH . "/plugins/" . $class; + } + } + else + { + include_once PIWIK_INCLUDE_PATH . "/libs/" . $class; + } +} + +// Note: only one __autoload per PHP instance +if(function_exists('spl_autoload_register')) +{ + spl_autoload_register('piwikAutoloader'); // use the SPL autoload stack + if(function_exists('__autoload')) + { + spl_auto_register('__autoload'); + } +} +else +{ + function __autoload($class) + { + piwikAutoloader($class); + } +} require_once "core/testMinimumPhpVersion.php"; @@ -34,6 +73,7 @@ if(!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) { require_once "core/ErrorHandler.php"; require_once "core/ExceptionHandler.php"; + set_error_handler('Piwik_ErrorHandler'); set_exception_handler('Piwik_ExceptionHandler'); } @@ -44,8 +84,6 @@ if(strlen(session_id()) === 0) session_start(); } -require_once "FrontController.php"; - if(!defined('PIWIK_ENABLE_DISPATCH') || PIWIK_ENABLE_DISPATCH) { $controller = Piwik_FrontController::getInstance(); |