From fbc15407a215d82263cc37c3a3f897547945e4e5 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 1 Jul 2014 20:53:10 +0200 Subject: [PATCH 1/2] [ticket/12784] Allow the extensions to add a custom auto loader PHPBB3-12784 --- phpBB/common.php | 2 ++ phpBB/download/file.php | 2 ++ phpBB/includes/functions.php | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/phpBB/common.php b/phpBB/common.php index 4b06cd1eda..e96a34938a 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -95,6 +95,8 @@ $phpbb_class_loader->register(); $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); $phpbb_class_loader_ext->register(); +phpbb_load_extensions_autoloaders($phpbb_root_path); + // Set up container $phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index ce2855473b..f7636b0e1a 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -59,6 +59,8 @@ if (isset($_GET['avatar'])) $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); $phpbb_class_loader_ext->register(); + phpbb_load_extensions_autoloaders($phpbb_root_path); + // Set up container $phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 32acb0c9ff..f820679144 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -20,6 +20,33 @@ if (!defined('IN_PHPBB')) } // Common global functions +/** +* Load the autoloaders added by the extensions. +* +* @param string $phpbb_root_path Path to the phpbb root directory. +*/ +function phpbb_load_extensions_autoloaders($phpbb_root_path) +{ + $iterator = new \RecursiveIteratorIterator( + new \phpbb\recursive_dot_prefix_filter_iterator( + new \RecursiveDirectoryIterator( + $phpbb_root_path . 'ext/', + \FilesystemIterator::SKIP_DOTS + ) + ), + \RecursiveIteratorIterator::SELF_FIRST + ); + $iterator->setMaxDepth(3); + + foreach ($iterator as $file_info) + { + if ($file_info->getFilename() === 'autoload.php' && $file_info->getPathInfo()->getFilename() === 'vendor') + { + require $file_info->getRealPath(); + } + } +} + /** * Casts a variable to the given type. * From 520f3b3bd636b52608d134750464daf1b7a27493 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 3 Jul 2014 11:26:07 +0200 Subject: [PATCH 2/2] [ticket/12784] Shearch the "vendor" folders and then the autoload.php files PHPBB3-12784 --- phpBB/includes/functions.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index f820679144..0838f2008e 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -36,13 +36,17 @@ function phpbb_load_extensions_autoloaders($phpbb_root_path) ), \RecursiveIteratorIterator::SELF_FIRST ); - $iterator->setMaxDepth(3); + $iterator->setMaxDepth(2); foreach ($iterator as $file_info) { - if ($file_info->getFilename() === 'autoload.php' && $file_info->getPathInfo()->getFilename() === 'vendor') + if ($file_info->getFilename() === 'vendor' && $iterator->getDepth() === 2) { - require $file_info->getRealPath(); + $filename = $file_info->getRealPath() . '/autoload.php'; + if (file_exists($filename)) + { + require $filename; + } } } }