mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[ticket/11152] Move container functions to a separate function file
PHPBB3-11152
This commit is contained in:
parent
3f2cbaac34
commit
897e8f2e83
6 changed files with 127 additions and 109 deletions
|
@ -84,6 +84,7 @@ require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
|
|||
|
||||
require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/functions_container.' . $phpEx);
|
||||
|
||||
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/db/' . ltrim($dbms, 'dbal_') . '.' . $phpEx);
|
||||
|
|
|
@ -48,6 +48,7 @@ if (isset($_GET['avatar']))
|
|||
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/functions_container.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/functions_download' . '.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
|
||||
|
||||
|
|
|
@ -7,13 +7,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
||||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
|
@ -5419,101 +5412,3 @@ function phpbb_to_numeric($input)
|
|||
{
|
||||
return ($input > PHP_INT_MAX) ? (float) $input : (int) $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the ContainerBuilder object
|
||||
*
|
||||
* @param array $extensions Array of Container extension objects
|
||||
* @param string $phpbb_root_path Root path
|
||||
* @param string $php_ext PHP Extension
|
||||
* @return ContainerBuilder object
|
||||
*/
|
||||
function phpbb_create_container(array $extensions, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
foreach ($extensions as $extension)
|
||||
{
|
||||
$container->registerExtension($extension);
|
||||
$container->loadFromExtension($extension->getAlias());
|
||||
}
|
||||
|
||||
$container->setParameter('core.root_path', $phpbb_root_path);
|
||||
$container->setParameter('core.php_ext', $php_ext);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create installer container
|
||||
*
|
||||
* @param string $phpbb_root_path Root path
|
||||
* @param string $php_ext PHP Extension
|
||||
* @return ContainerBuilder object
|
||||
*/
|
||||
function phpbb_create_install_container($phpbb_root_path, $php_ext)
|
||||
{
|
||||
// We have to do it like this instead of with extensions
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
|
||||
$loader->load('services.yml');
|
||||
|
||||
$container->setParameter('core.root_path', $phpbb_root_path);
|
||||
$container->setParameter('core.php_ext', $php_ext);
|
||||
|
||||
$container->setAlias('cache.driver', 'cache.driver.install');
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a compiled ContainerBuilder object
|
||||
*
|
||||
* @param array $extensions Array of Container extension objects
|
||||
* @param array $passes Array of Compiler Pass objects
|
||||
* @param string $phpbb_root_path Root path
|
||||
* @param string $php_ext PHP Extension
|
||||
* @return ContainerBuilder object (compiled)
|
||||
*/
|
||||
function phpbb_create_compiled_container(array $extensions, array $passes, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
// Check for our cached container; if it exists, use it
|
||||
if (file_exists("{$phpbb_root_path}cache/container.$php_ext"))
|
||||
{
|
||||
require("{$phpbb_root_path}cache/container.$php_ext");
|
||||
return new phpbb_cache_container();
|
||||
}
|
||||
|
||||
// We must use an absolute path in the container because we cannot
|
||||
// change the value at runtime when accessing it in different
|
||||
// directory levels.
|
||||
$phpbb_absolute_path = phpbb_realpath($phpbb_root_path) . '/';
|
||||
|
||||
// Create a temporary container for access to the ext.manager service
|
||||
$tmp_container = phpbb_create_container($extensions, $phpbb_absolute_path, $php_ext);
|
||||
$tmp_container->compile();
|
||||
|
||||
// Now pass the enabled extension paths into the ext compiler extension
|
||||
$extensions[] = new phpbb_di_extension_ext($tmp_container->get('ext.manager')->all_enabled());
|
||||
|
||||
// Create the final container to be compiled and cached
|
||||
$container = phpbb_create_container($extensions, $phpbb_absolute_path, $php_ext);
|
||||
|
||||
// Compile the container
|
||||
foreach ($passes as $pass)
|
||||
{
|
||||
$container->addCompilerPass($pass);
|
||||
}
|
||||
$container->compile();
|
||||
|
||||
// Lastly, we create our cached container class
|
||||
$dumper = new PhpDumper($container);
|
||||
$cached_container_dump = $dumper->dump(array(
|
||||
'class' => 'phpbb_cache_container',
|
||||
'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
|
||||
));
|
||||
|
||||
$file = file_put_contents("{$phpbb_absolute_path}cache/container.{$php_ext}", $cached_container_dump);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
|
119
phpBB/includes/functions_container.php
Normal file
119
phpBB/includes/functions_container.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2005 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the ContainerBuilder object
|
||||
*
|
||||
* @param array $extensions Array of Container extension objects
|
||||
* @param string $phpbb_root_path Root path
|
||||
* @param string $php_ext PHP Extension
|
||||
* @return ContainerBuilder object
|
||||
*/
|
||||
function phpbb_create_container(array $extensions, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
foreach ($extensions as $extension)
|
||||
{
|
||||
$container->registerExtension($extension);
|
||||
$container->loadFromExtension($extension->getAlias());
|
||||
}
|
||||
|
||||
$container->setParameter('core.root_path', $phpbb_root_path);
|
||||
$container->setParameter('core.php_ext', $php_ext);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create installer container
|
||||
*
|
||||
* @param string $phpbb_root_path Root path
|
||||
* @param string $php_ext PHP Extension
|
||||
* @return ContainerBuilder object
|
||||
*/
|
||||
function phpbb_create_install_container($phpbb_root_path, $php_ext)
|
||||
{
|
||||
// We have to do it like this instead of with extensions
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
|
||||
$loader->load('services.yml');
|
||||
|
||||
$container->setParameter('core.root_path', $phpbb_root_path);
|
||||
$container->setParameter('core.php_ext', $php_ext);
|
||||
|
||||
$container->setAlias('cache.driver', 'cache.driver.install');
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a compiled ContainerBuilder object
|
||||
*
|
||||
* @param array $extensions Array of Container extension objects
|
||||
* @param array $passes Array of Compiler Pass objects
|
||||
* @param string $phpbb_root_path Root path
|
||||
* @param string $php_ext PHP Extension
|
||||
* @return ContainerBuilder object (compiled)
|
||||
*/
|
||||
function phpbb_create_compiled_container(array $extensions, array $passes, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
// Check for our cached container; if it exists, use it
|
||||
if (file_exists("{$phpbb_root_path}cache/container.$php_ext"))
|
||||
{
|
||||
require("{$phpbb_root_path}cache/container.$php_ext");
|
||||
return new phpbb_cache_container();
|
||||
}
|
||||
|
||||
// We must use an absolute path in the container because we cannot
|
||||
// change the value at runtime when accessing it in different
|
||||
// directory levels.
|
||||
$phpbb_absolute_path = phpbb_realpath($phpbb_root_path) . '/';
|
||||
|
||||
// Create a temporary container for access to the ext.manager service
|
||||
$tmp_container = phpbb_create_container($extensions, $phpbb_absolute_path, $php_ext);
|
||||
$tmp_container->compile();
|
||||
|
||||
// Now pass the enabled extension paths into the ext compiler extension
|
||||
$extensions[] = new phpbb_di_extension_ext($tmp_container->get('ext.manager')->all_enabled());
|
||||
|
||||
// Create the final container to be compiled and cached
|
||||
$container = phpbb_create_container($extensions, $phpbb_absolute_path, $php_ext);
|
||||
|
||||
// Compile the container
|
||||
foreach ($passes as $pass)
|
||||
{
|
||||
$container->addCompilerPass($pass);
|
||||
}
|
||||
$container->compile();
|
||||
|
||||
// Lastly, we create our cached container class
|
||||
$dumper = new PhpDumper($container);
|
||||
$cached_container_dump = $dumper->dump(array(
|
||||
'class' => 'phpbb_cache_container',
|
||||
'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
|
||||
));
|
||||
|
||||
$file = file_put_contents("{$phpbb_absolute_path}cache/container.{$php_ext}", $cached_container_dump);
|
||||
|
||||
return $container;
|
||||
}
|
|
@ -88,6 +88,7 @@ if (!empty($load_extensions) && function_exists('dl'))
|
|||
require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
|
||||
|
||||
require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/functions_container.' . $phpEx);
|
||||
|
||||
phpbb_require_updated('includes/functions_content.' . $phpEx, true);
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ else
|
|||
require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
|
||||
|
||||
require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/functions_container.' . $phpEx);
|
||||
|
||||
phpbb_require_updated('includes/functions_content.' . $phpEx, true);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue