mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
Merge pull request #1056 from igorw/feature/compiled-dic
[feature/compiled-dic] Compile the DI Container into a cached class
This commit is contained in:
6
phpBB/includes/cache/driver/file.php
vendored
6
phpBB/includes/cache/driver/file.php
vendored
@@ -214,7 +214,11 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
|
||||
|
||||
while (($entry = readdir($dir)) !== false)
|
||||
{
|
||||
if (strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0)
|
||||
if (strpos($entry, 'container') !== 0 &&
|
||||
strpos($entry, 'sql_') !== 0 &&
|
||||
strpos($entry, 'data_') !== 0 &&
|
||||
strpos($entry, 'ctpl_') !== 0 &&
|
||||
strpos($entry, 'tpl_') !== 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
6
phpBB/includes/cache/driver/memory.php
vendored
6
phpBB/includes/cache/driver/memory.php
vendored
@@ -162,7 +162,11 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base
|
||||
|
||||
while (($entry = readdir($dir)) !== false)
|
||||
{
|
||||
if (strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0)
|
||||
if (strpos($entry, 'container') !== 0 &&
|
||||
strpos($entry, 'sql_') !== 0 &&
|
||||
strpos($entry, 'data_') !== 0 &&
|
||||
strpos($entry, 'ctpl_') !== 0 &&
|
||||
strpos($entry, 'tpl_') !== 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides cron manager with tasks
|
||||
*
|
||||
* Finds installed cron tasks and makes them available to the cron manager.
|
||||
*
|
||||
* @package phpBB3
|
||||
*/
|
||||
class phpbb_cron_task_provider implements IteratorAggregate
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(TaggedContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an iterator over all items
|
||||
*
|
||||
* @return ArrayIterator An iterator for the array of cron tasks
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
$definitions = $this->container->findTaggedServiceIds('cron.task');
|
||||
|
||||
$tasks = array();
|
||||
foreach ($definitions as $name => $definition)
|
||||
{
|
||||
$task = $this->container->get($name);
|
||||
if ($task instanceof phpbb_cron_task_base)
|
||||
{
|
||||
$task->set_name($name);
|
||||
}
|
||||
|
||||
$tasks[] = $task;
|
||||
}
|
||||
|
||||
return new ArrayIterator($tasks);
|
||||
}
|
||||
}
|
@@ -16,40 +16,31 @@ if (!defined('IN_PHPBB'))
|
||||
}
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
/**
|
||||
* Configure the container for phpBB's services though
|
||||
* user-defined parameters defined in the config.php file.
|
||||
* Container config extension
|
||||
*/
|
||||
class phpbb_di_processor_config implements phpbb_di_processor_interface
|
||||
class phpbb_di_extension_config extends Extension
|
||||
{
|
||||
private $config_file;
|
||||
private $phpbb_root_path;
|
||||
private $php_ext;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $config_file The config file
|
||||
* @param string $phpbb_root_path The root path
|
||||
* @param string $php_ext The PHP extension
|
||||
*/
|
||||
public function __construct($config_file, $phpbb_root_path, $php_ext)
|
||||
public function __construct($config_file)
|
||||
{
|
||||
$this->config_file = $config_file;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* Loads a specific configuration.
|
||||
*
|
||||
* @param array $config An array of configuration values
|
||||
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||
*
|
||||
* @throws InvalidArgumentException When provided tag is not defined in this extension
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
require $this->config_file;
|
||||
|
||||
$container->setParameter('core.root_path', $this->phpbb_root_path);
|
||||
$container->setParameter('core.php_ext', $this->php_ext);
|
||||
require($this->config_file);
|
||||
|
||||
$container->setParameter('core.table_prefix', $table_prefix);
|
||||
$container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type));
|
||||
@@ -60,10 +51,26 @@ class phpbb_di_processor_config implements phpbb_di_processor_interface
|
||||
$container->setParameter('dbal.dbname', $dbname);
|
||||
$container->setParameter('dbal.dbport', $dbport);
|
||||
$container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK);
|
||||
|
||||
$container->set('container', $container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the recommended alias to use in XML.
|
||||
*
|
||||
* This alias is also the mandatory prefix to use when using YAML.
|
||||
*
|
||||
* @return string The alias
|
||||
*/
|
||||
public function getAlias()
|
||||
{
|
||||
return 'config';
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert old (3.0) values to 3.1 class names
|
||||
*
|
||||
* @param style $acm_type ACM type
|
||||
* @return ACM type class
|
||||
*/
|
||||
protected function fix_acm_type($acm_type)
|
||||
{
|
||||
if (preg_match('#^[a-z]+$#', $acm_type))
|
69
phpBB/includes/di/extension/core.php
Normal file
69
phpBB/includes/di/extension/core.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
/**
|
||||
* Container core extension
|
||||
*/
|
||||
class phpbb_di_extension_core extends Extension
|
||||
{
|
||||
/**
|
||||
* phpBB Root path
|
||||
* @var string
|
||||
*/
|
||||
protected $root_path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $root_path Root path
|
||||
*/
|
||||
public function __construct($root_path)
|
||||
{
|
||||
$this->root_path = $root_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific configuration.
|
||||
*
|
||||
* @param array $config An array of configuration values
|
||||
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||
*
|
||||
* @throws InvalidArgumentException When provided tag is not defined in this extension
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->root_path . 'config')));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the recommended alias to use in XML.
|
||||
*
|
||||
* This alias is also the mandatory prefix to use when using YAML.
|
||||
*
|
||||
* @return string The alias
|
||||
*/
|
||||
public function getAlias()
|
||||
{
|
||||
return 'core';
|
||||
}
|
||||
}
|
69
phpBB/includes/di/extension/ext.php
Normal file
69
phpBB/includes/di/extension/ext.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
/**
|
||||
* Container ext extension
|
||||
*/
|
||||
class phpbb_di_extension_ext extends Extension
|
||||
{
|
||||
protected $paths = array();
|
||||
|
||||
public function __construct($enabled_extensions)
|
||||
{
|
||||
foreach ($enabled_extensions as $ext => $path)
|
||||
{
|
||||
$this->paths[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific configuration.
|
||||
*
|
||||
* @param array $config An array of configuration values
|
||||
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||
*
|
||||
* @throws InvalidArgumentException When provided tag is not defined in this extension
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
foreach ($this->paths as $path)
|
||||
{
|
||||
if (file_exists($path . '/config/services.yml'))
|
||||
{
|
||||
$loader = new YamlFileLoader($container, new FileLocator(phpbb_real_path($path . '/config')));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the recommended alias to use in XML.
|
||||
*
|
||||
* This alias is also the mandatory prefix to use when using YAML.
|
||||
*
|
||||
* @return string The alias
|
||||
*/
|
||||
public function getAlias()
|
||||
{
|
||||
return 'ext';
|
||||
}
|
||||
}
|
47
phpBB/includes/di/pass/collection_pass.php
Normal file
47
phpBB/includes/di/pass/collection_pass.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
|
||||
class phpbb_di_pass_collection_pass implements CompilerPassInterface
|
||||
{
|
||||
private $collection_service;
|
||||
private $service_tag;
|
||||
|
||||
public function __construct($collection_service, $service_tag)
|
||||
{
|
||||
$this->collection_service = $collection_service;
|
||||
$this->service_tag = $service_tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the container before it is passed to the rest of the code
|
||||
*
|
||||
* @param ContainerBuilder $container ContainerBuilder object
|
||||
* @return null
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$definition = $container->getDefinition($this->collection_service);
|
||||
|
||||
foreach ($container->findTaggedServiceIds($this->service_tag) as $id => $data)
|
||||
{
|
||||
$definition->addMethodCall('add', array($id));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
|
||||
/**
|
||||
* Load the service configurations from all extensions into the container.
|
||||
*/
|
||||
class phpbb_di_processor_ext implements phpbb_di_processor_interface
|
||||
{
|
||||
private $extension_manager;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $extension_manager The extension manager
|
||||
*/
|
||||
public function __construct($extension_manager)
|
||||
{
|
||||
$this->extension_manager = $extension_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$enabled_exts = $this->extension_manager->all_enabled();
|
||||
foreach ($enabled_exts as $name => $path)
|
||||
{
|
||||
if (file_exists($path . '/config/services.yml'))
|
||||
{
|
||||
$loader = new YamlFileLoader($container, new FileLocator($path . '/config'));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
interface phpbb_di_processor_interface
|
||||
{
|
||||
/**
|
||||
* Mutate the container.
|
||||
*
|
||||
* @param ContainerBuilder $container The container
|
||||
*/
|
||||
public function process(ContainerBuilder $container);
|
||||
}
|
49
phpBB/includes/di/service_collection.php
Normal file
49
phpBB/includes/di/service_collection.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Collection of services to be configured at container compile time.
|
||||
*
|
||||
* @package phpBB3
|
||||
*/
|
||||
class phpbb_di_service_collection extends ArrayObject
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ContainerInterface $container Container object
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a service to the collection
|
||||
*
|
||||
* @param string $name The service name
|
||||
* @return null
|
||||
*/
|
||||
public function add($name)
|
||||
{
|
||||
$task = $this->container->get($name);
|
||||
$task->set_name($name);
|
||||
$this->offsetSet($name, $task);
|
||||
}
|
||||
}
|
@@ -15,7 +15,7 @@ if (!defined('IN_PHPBB'))
|
||||
exit;
|
||||
}
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
|
||||
|
||||
/**
|
||||
* Extension of the Symfony2 EventDispatcher
|
||||
@@ -31,7 +31,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
* extract($phpbb_dispatcher->trigger_event('core.index', compact($vars)));
|
||||
*
|
||||
*/
|
||||
class phpbb_event_dispatcher extends EventDispatcher
|
||||
class phpbb_event_dispatcher extends ContainerAwareEventDispatcher
|
||||
{
|
||||
public function trigger_event($eventName, $data = array())
|
||||
{
|
||||
|
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package extension
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract class extended by extension front controller classes
|
||||
*
|
||||
* @package extension
|
||||
*/
|
||||
abstract class phpbb_extension_controller implements phpbb_extension_controller_interface
|
||||
{
|
||||
/**
|
||||
* Request class object
|
||||
* @var phpbb_request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* DBAL class object
|
||||
* @var dbal
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* User class object
|
||||
* @var phpbb_user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Template class object
|
||||
* @var phpbb_template
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* Config object
|
||||
* @var phpbb_config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* PHP Extension
|
||||
* @var string
|
||||
*/
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* Relative path to board root
|
||||
* @var string
|
||||
*/
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/**
|
||||
* Constructor method that provides the common phpBB objects as inherited class
|
||||
* properties for automatic availability in extension controllers
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
global $request, $db, $user, $template, $config;
|
||||
global $phpEx, $phpbb_root_path;
|
||||
|
||||
$this->request = $request;
|
||||
$this->db = $db;
|
||||
$this->user = $user;
|
||||
$this->template = $template;
|
||||
$this->config = $config;
|
||||
$this->php_ext = $phpEx;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
}
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package extension
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface that extension classes have to implement to run front pages
|
||||
*
|
||||
* @package extension
|
||||
*/
|
||||
interface phpbb_extension_controller_interface
|
||||
{
|
||||
/**
|
||||
* Handle the request to display a page from an extension
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function handle();
|
||||
}
|
@@ -195,7 +195,7 @@ class phpbb_extension_manager
|
||||
|
||||
if ($this->cache)
|
||||
{
|
||||
$this->cache->destroy($this->cache_name);
|
||||
$this->cache->purge();
|
||||
}
|
||||
|
||||
return !$active;
|
||||
@@ -252,7 +252,7 @@ class phpbb_extension_manager
|
||||
|
||||
if ($this->cache)
|
||||
{
|
||||
$this->cache->destroy($this->cache_name);
|
||||
$this->cache->purge();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -272,7 +272,7 @@ class phpbb_extension_manager
|
||||
|
||||
if ($this->cache)
|
||||
{
|
||||
$this->cache->destroy($this->cache_name);
|
||||
$this->cache->purge();
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -335,7 +335,7 @@ class phpbb_extension_manager
|
||||
|
||||
if ($this->cache)
|
||||
{
|
||||
$this->cache->destroy($this->cache_name);
|
||||
$this->cache->purge();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -349,7 +349,7 @@ class phpbb_extension_manager
|
||||
|
||||
if ($this->cache)
|
||||
{
|
||||
$this->cache->destroy($this->cache_name);
|
||||
$this->cache->purge();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
140
phpBB/includes/functions_container.php
Normal file
140
phpBB/includes/functions_container.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?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)
|
||||
{
|
||||
$core = new phpbb_di_extension_core($phpbb_root_path);
|
||||
$container = phpbb_create_container(array($core), $phpbb_root_path, $php_ext);
|
||||
|
||||
$container->setParameter('core.root_path', $phpbb_root_path);
|
||||
$container->setParameter('core.php_ext', $php_ext);
|
||||
$container->setParameter('core.table_prefix', '');
|
||||
|
||||
$container->register('dbal.conn')->setSynthetic(true);
|
||||
|
||||
$container->setAlias('cache.driver', 'cache.driver.install');
|
||||
|
||||
$container->compile();
|
||||
|
||||
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)
|
||||
{
|
||||
// Create a temporary container for access to the ext.manager service
|
||||
$tmp_container = phpbb_create_container($extensions, $phpbb_root_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_root_path, $php_ext);
|
||||
|
||||
// Compile the container
|
||||
foreach ($passes as $pass)
|
||||
{
|
||||
$container->addCompilerPass($pass);
|
||||
}
|
||||
$container->compile();
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
function phpbb_create_dumped_container(array $extensions, array $passes, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
// Check for our cached container; if it exists, use it
|
||||
$container_filename = phpbb_container_filename($phpbb_root_path, $php_ext);
|
||||
if (file_exists($container_filename))
|
||||
{
|
||||
require($container_filename);
|
||||
return new phpbb_cache_container();
|
||||
}
|
||||
|
||||
$container = phpbb_create_compiled_container($extensions, $passes, $phpbb_root_path, $php_ext);
|
||||
|
||||
// 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_put_contents($container_filename, $cached_container_dump);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
function phpbb_create_dumped_container_unless_debug(array $extensions, array $passes, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
if (defined('DEBUG')) {
|
||||
return phpbb_create_compiled_container($extensions, $passes, $phpbb_root_path, $php_ext);
|
||||
}
|
||||
|
||||
return phpbb_create_dumped_container($extensions, $passes, $phpbb_root_path, $php_ext);
|
||||
}
|
||||
|
||||
function phpbb_container_filename($phpbb_root_path, $php_ext)
|
||||
{
|
||||
$filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path);
|
||||
return $phpbb_root_path . 'cache/' . $filename . '_container.' . $php_ext;
|
||||
}
|
Reference in New Issue
Block a user