From 711f482cb62070ab2340aa27c736a85cc6e8c518 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sat, 6 Jun 2009 23:20:10 +0000 Subject: [PATCH] - Class loaders for both frameworks: eZComponents through a loader object Zend Framework with an autoload function Example usage: require("{$phpbb_root_path}includes/ezcomponents/loader.$phpEx"); require("{$phpbb_root_path}includes/Zend/loader.$phpEx"); $loader = new phpbb_ezcomponents_loader(); $loader->load_component('search'); $handler = new ezcSearchZendLuceneHandler( '/tmp/lucene' ); git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9552 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/Zend/loader.php | 58 ++++++++++++++++++++ phpBB/includes/ezcomponents/loader.php | 73 ++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 phpBB/includes/Zend/loader.php create mode 100644 phpBB/includes/ezcomponents/loader.php diff --git a/phpBB/includes/Zend/loader.php b/phpBB/includes/Zend/loader.php new file mode 100644 index 0000000000..99a5543901 --- /dev/null +++ b/phpBB/includes/Zend/loader.php @@ -0,0 +1,58 @@ += 5.2.4 and spl_autoload_register() required', E_USER_ERROR); +} + +/** +* Autoload function for Zend framework classes +*/ +function phpbb_zend_autoload($class_name) +{ + global $phpbb_root_path; + + if (strpos($class_name, '_') !== false) + { + $path = str_replace('_', '/', $class_name) . '.php'; + require("{$phpbb_root_path}includes/" . $path); + return true; + } +} + +/** +* @ignore +*/ +// make sure Zend is in the include path +ini_set( 'include_path', ini_get( 'include_path' ) . PATH_SEPARATOR . $phpbb_root_path . 'includes' ); + +// check whether a regular autoload function already exists, so we can load it into the spl stack afterwards +$register_autoload = false; +if (function_exists('__autoload')) +{ + $register_autoload = true; +} + +spl_autoload_register('phpbb_zend_autoload'); + +// load the old autoload function into the spl stack if necessary +if ($register_autoload) +{ + spl_autoload_register('__autoload'); +} \ No newline at end of file diff --git a/phpBB/includes/ezcomponents/loader.php b/phpBB/includes/ezcomponents/loader.php new file mode 100644 index 0000000000..62aaa7667d --- /dev/null +++ b/phpBB/includes/ezcomponents/loader.php @@ -0,0 +1,73 @@ +loaded = array(); + if (version_compare(PHP_VERSION, '5.2.1', '<')) + { + trigger_error('PHP >= 5.2.1 required', E_USER_ERROR); + } + } + + /** + * Loads all classes of a particular component. + * The base component is always loaded first. + * + * @param $component string Lower case component name + */ + function load_component($component) + { + global $phpbb_root_path; + + // don't allow loading the same component twice + if (isset($this->loaded[$component]) && $this->loaded[$component]) + { + return; + } + + // make sure base is always loaded first + if ($component != 'base' && !isset($this->loaded['base'])) + { + $this->load_component('base'); + } + + $ezc_path = $phpbb_root_path . 'includes/ezcomponents/'; + + // retrieve the autoload list + $classes = include($ezc_path . ucfirst($component) . '/' . $component . '_autoload.php'); + + // include all files related to this component + foreach ($classes as $class => $path) + { + include($ezc_path . $path); + } + } +} \ No newline at end of file