diff options
author | vipsoft <vipsoft@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2009-06-15 06:17:33 +0400 |
---|---|---|
committer | vipsoft <vipsoft@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2009-06-15 06:17:33 +0400 |
commit | 9cb4e9d0276da56cc069c6820289b698febbeace (patch) | |
tree | faac5f8d82d0f02ad9997d8c69fe238c149580a3 /piwik.php | |
parent | 60b45d3280f16876bb99145a1b39fe8a0f210f2b (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
Diffstat (limited to 'piwik.php')
-rw-r--r-- | piwik.php | 42 |
1 files changed, 40 insertions, 2 deletions
@@ -18,12 +18,51 @@ error_reporting(E_ALL|E_NOTICE); define('PIWIK_INCLUDE_PATH', dirname(__FILE__)); @ignore_user_abort(true); -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 "Common.php"; require_once "PluginsManager.php"; require_once "Tracker.php"; @@ -53,4 +92,3 @@ $process = new Piwik_Tracker; $process->main(); ob_end_flush(); printDebug($_COOKIE); - |