diff options
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/cache/driver/file.php | 6 | ||||
-rw-r--r-- | phpBB/includes/cache/driver/memory.php | 6 | ||||
-rw-r--r-- | phpBB/includes/cron/task/provider.php | 59 | ||||
-rw-r--r-- | phpBB/includes/di/extension/config.php (renamed from phpBB/includes/di/processor/config.php) | 55 | ||||
-rw-r--r-- | phpBB/includes/di/extension/core.php | 69 | ||||
-rw-r--r-- | phpBB/includes/di/extension/ext.php | 69 | ||||
-rw-r--r-- | phpBB/includes/di/pass/collection_pass.php | 47 | ||||
-rw-r--r-- | phpBB/includes/di/processor/ext.php | 54 | ||||
-rw-r--r-- | phpBB/includes/di/processor/interface.php | 28 | ||||
-rw-r--r-- | phpBB/includes/di/service_collection.php | 49 | ||||
-rw-r--r-- | phpBB/includes/event/dispatcher.php | 4 | ||||
-rw-r--r-- | phpBB/includes/extension/controller.php | 84 | ||||
-rw-r--r-- | phpBB/includes/extension/controller_interface.php | 31 | ||||
-rw-r--r-- | phpBB/includes/extension/manager.php | 10 | ||||
-rw-r--r-- | phpBB/includes/functions_container.php | 140 |
15 files changed, 422 insertions, 289 deletions
diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index f64a9e3ea8..b20c0064ea 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -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; } diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index e0771ab1d3..98ac02b161 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -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; } diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php deleted file mode 100644 index 134723ebd1..0000000000 --- a/phpBB/includes/cron/task/provider.php +++ /dev/null @@ -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); - } -} diff --git a/phpBB/includes/di/processor/config.php b/phpBB/includes/di/extension/config.php index 22b6252a6d..fb5ca90070 100644 --- a/phpBB/includes/di/processor/config.php +++ b/phpBB/includes/di/extension/config.php @@ -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)) diff --git a/phpBB/includes/di/extension/core.php b/phpBB/includes/di/extension/core.php new file mode 100644 index 0000000000..9c36ba2fc4 --- /dev/null +++ b/phpBB/includes/di/extension/core.php @@ -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'; + } +} diff --git a/phpBB/includes/di/extension/ext.php b/phpBB/includes/di/extension/ext.php new file mode 100644 index 0000000000..e76c543ee1 --- /dev/null +++ b/phpBB/includes/di/extension/ext.php @@ -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'; + } +} diff --git a/phpBB/includes/di/pass/collection_pass.php b/phpBB/includes/di/pass/collection_pass.php new file mode 100644 index 0000000000..70a44d1d51 --- /dev/null +++ b/phpBB/includes/di/pass/collection_pass.php @@ -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)); + } + } +} diff --git a/phpBB/includes/di/processor/ext.php b/phpBB/includes/di/processor/ext.php deleted file mode 100644 index e69a3d73b3..0000000000 --- a/phpBB/includes/di/processor/ext.php +++ /dev/null @@ -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'); - } - } - } -} diff --git a/phpBB/includes/di/processor/interface.php b/phpBB/includes/di/processor/interface.php deleted file mode 100644 index b8563791cc..0000000000 --- a/phpBB/includes/di/processor/interface.php +++ /dev/null @@ -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); -} diff --git a/phpBB/includes/di/service_collection.php b/phpBB/includes/di/service_collection.php new file mode 100644 index 0000000000..60323c8dba --- /dev/null +++ b/phpBB/includes/di/service_collection.php @@ -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); + } +} diff --git a/phpBB/includes/event/dispatcher.php b/phpBB/includes/event/dispatcher.php index 2bf46b9b06..4f637ce3bb 100644 --- a/phpBB/includes/event/dispatcher.php +++ b/phpBB/includes/event/dispatcher.php @@ -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()) { diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php deleted file mode 100644 index f97b69c7ed..0000000000 --- a/phpBB/includes/extension/controller.php +++ /dev/null @@ -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; - } -} diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php deleted file mode 100644 index 2b88925388..0000000000 --- a/phpBB/includes/extension/controller_interface.php +++ /dev/null @@ -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(); -} diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index cfa6a0e000..bfd4edde93 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -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; diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php new file mode 100644 index 0000000000..1de1d9f7ea --- /dev/null +++ b/phpBB/includes/functions_container.php @@ -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; +} |