Merge pull request #2674 from Nicofuma/ticket/12784

[ticket/12784] Allow the extensions to add a custom auto loader

* Nicofuma/ticket/12784:
  [ticket/12784] Shearch the "vendor" folders and then the autoload.php files
  [ticket/12784] Allow the extensions to add a custom auto loader
This commit is contained in:
Joas Schilling 2014-07-03 11:58:04 +02:00
commit 380e9c2ef4
3 changed files with 35 additions and 0 deletions

View file

@ -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 = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx);
$phpbb_class_loader_ext->register(); $phpbb_class_loader_ext->register();
phpbb_load_extensions_autoloaders($phpbb_root_path);
// Set up container // Set up container
$phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx); $phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx);

View file

@ -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 = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx);
$phpbb_class_loader_ext->register(); $phpbb_class_loader_ext->register();
phpbb_load_extensions_autoloaders($phpbb_root_path);
// Set up container // Set up container
$phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx); $phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx);

View file

@ -20,6 +20,37 @@ if (!defined('IN_PHPBB'))
} }
// Common global functions // 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(2);
foreach ($iterator as $file_info)
{
if ($file_info->getFilename() === 'vendor' && $iterator->getDepth() === 2)
{
$filename = $file_info->getRealPath() . '/autoload.php';
if (file_exists($filename))
{
require $filename;
}
}
}
}
/** /**
* Casts a variable to the given type. * Casts a variable to the given type.
* *