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:
Nils Adermann 2012-11-11 09:05:15 -08:00
commit 69845585a2
27 changed files with 1463 additions and 450 deletions

View file

@ -69,11 +69,10 @@ if (!defined('PHPBB_INSTALLED'))
// Include files // Include files
require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx);
require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx);
require($phpbb_root_path . 'includes/functions_content.' . $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/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . ltrim($dbms, 'dbal_') . '.' . $phpEx); require($phpbb_root_path . 'includes/db/' . ltrim($dbms, 'dbal_') . '.' . $phpEx);
@ -82,16 +81,27 @@ require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
// Set PHP error handler to ours // Set PHP error handler to ours
set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');
$phpbb_container = new ContainerBuilder();
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/config'));
$loader->load('services.yml');
$processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx);
$processor->process($phpbb_container);
// Setup class loader first // Setup class loader first
$phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", ".$phpEx");
$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); $phpbb_class_loader->register();
$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_path}ext/", ".$phpEx");
$phpbb_class_loader_ext->register();
// Set up container
$phpbb_container = phpbb_create_dumped_container_unless_debug(
array(
new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx),
new phpbb_di_extension_core($phpbb_root_path),
),
array(
new phpbb_di_pass_collection_pass('cron.task_collection', 'cron.task'),
),
$phpbb_root_path,
$phpEx
);
$phpbb_class_loader->set_cache($phpbb_container->get('cache.driver'));
$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver'));
// set up caching // set up caching
$cache = $phpbb_container->get('cache'); $cache = $phpbb_container->get('cache');
@ -118,13 +128,6 @@ $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader');
$template = $phpbb_container->get('template'); $template = $phpbb_container->get('template');
$phpbb_style = $phpbb_container->get('style'); $phpbb_style = $phpbb_container->get('style');
$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor'));
foreach ($ids as $id)
{
$processor = $phpbb_container->get($id);
$processor->process($phpbb_container);
}
// Add own hook handler // Add own hook handler
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('phpbb_template', 'display'))); $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('phpbb_template', 'display')));

View file

@ -4,6 +4,7 @@
"symfony/config": "2.1.*", "symfony/config": "2.1.*",
"symfony/dependency-injection": "2.1.*", "symfony/dependency-injection": "2.1.*",
"symfony/event-dispatcher": "2.1.*", "symfony/event-dispatcher": "2.1.*",
"symfony/http-kernel": "2.1.*",
"symfony/yaml": "2.1.*" "symfony/yaml": "2.1.*"
}, },
"require-dev": { "require-dev": {

746
phpBB/composer.lock generated
View file

@ -1,67 +1,749 @@
{ {
"hash": "1632798bc1d5298a4f5bd3087c972a9f", "hash": "407cc89f4bb0e409146c863dee51b0ae",
"packages": [ "packages": [
{ {
"package": "symfony/config", "name": "symfony/config",
"version": "v2.1.0-RC1" "version": "v2.1.3",
"target-dir": "Symfony/Component/Config",
"source": {
"type": "git",
"url": "https://github.com/symfony/Config",
"reference": "v2.1.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/Config/zipball/v2.1.3",
"reference": "v2.1.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"time": "2012-10-20 00:10:30",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\Config": ""
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}, },
{ {
"package": "symfony/dependency-injection", "name": "Symfony Community",
"version": "v2.1.0-RC1" "homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony Config Component",
"homepage": "http://symfony.com"
}, },
{ {
"package": "symfony/event-dispatcher", "name": "symfony/dependency-injection",
"version": "v2.1.0-RC1" "version": "v2.1.3",
"target-dir": "Symfony/Component/DependencyInjection",
"source": {
"type": "git",
"url": "https://github.com/symfony/DependencyInjection",
"reference": "v2.1.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/DependencyInjection/zipball/v2.1.3",
"reference": "v2.1.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"symfony/yaml": "2.1.*",
"symfony/config": "2.1.*"
},
"suggest": {
"symfony/yaml": "2.1.*",
"symfony/config": "2.1.*"
},
"time": "2012-10-22 07:37:12",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\DependencyInjection": ""
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}, },
{ {
"package": "symfony/yaml", "name": "Symfony Community",
"version": "v2.1.0-RC1" "homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony DependencyInjection Component",
"homepage": "http://symfony.com"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.1.3",
"target-dir": "Symfony/Component/EventDispatcher",
"source": {
"type": "git",
"url": "https://github.com/symfony/EventDispatcher",
"reference": "v2.1.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/EventDispatcher/zipball/v2.1.3",
"reference": "v2.1.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"symfony/dependency-injection": "2.1.*"
},
"suggest": {
"symfony/dependency-injection": "2.1.*",
"symfony/http-kernel": "2.1.*"
},
"time": "2012-10-04 08:17:57",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\EventDispatcher": ""
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony EventDispatcher Component",
"homepage": "http://symfony.com"
},
{
"name": "symfony/http-foundation",
"version": "v2.1.3",
"target-dir": "Symfony/Component/HttpFoundation",
"source": {
"type": "git",
"url": "https://github.com/symfony/HttpFoundation",
"reference": "v2.1.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/HttpFoundation/zipball/v2.1.3",
"reference": "v2.1.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"time": "2012-10-20 00:10:30",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\HttpFoundation": "",
"SessionHandlerInterface": "Symfony/Component/HttpFoundation/Resources/stubs"
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony HttpFoundation Component",
"homepage": "http://symfony.com"
},
{
"name": "symfony/http-kernel",
"version": "v2.1.3",
"target-dir": "Symfony/Component/HttpKernel",
"source": {
"type": "git",
"url": "https://github.com/symfony/HttpKernel",
"reference": "v2.1.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/HttpKernel/zipball/v2.1.3",
"reference": "v2.1.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"symfony/event-dispatcher": "2.1.*",
"symfony/http-foundation": "2.1.*"
},
"require-dev": {
"symfony/browser-kit": "2.1.*",
"symfony/class-loader": "2.1.*",
"symfony/config": "2.1.*",
"symfony/console": "2.1.*",
"symfony/dependency-injection": "2.1.*",
"symfony/finder": "2.1.*",
"symfony/process": "2.1.*",
"symfony/routing": "2.1.*"
},
"suggest": {
"symfony/browser-kit": "2.1.*",
"symfony/class-loader": "2.1.*",
"symfony/config": "2.1.*",
"symfony/console": "2.1.*",
"symfony/dependency-injection": "2.1.*",
"symfony/finder": "2.1.*"
},
"time": "2012-10-30 01:14:14",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\HttpKernel": ""
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony HttpKernel Component",
"homepage": "http://symfony.com"
},
{
"name": "symfony/yaml",
"version": "v2.1.3",
"target-dir": "Symfony/Component/Yaml",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml",
"reference": "v2.1.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/Yaml/zipball/v2.1.3",
"reference": "v2.1.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"time": "2012-10-29 04:15:41",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\Yaml": ""
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony Yaml Component",
"homepage": "http://symfony.com"
} }
], ],
"packages-dev": [ "packages-dev": [
{ {
"package": "fabpot/goutte", "name": "fabpot/goutte",
"version": "dev-master", "version": "dev-master",
"alias-pretty-version": "1.0.x-dev", "source": {
"alias-version": "1.0.9999999.9999999-dev" "type": "git",
"url": "https://github.com/fabpot/Goutte",
"reference": "f2940f9c7c1f409159f5e9f512e575946c5cff48"
},
"dist": {
"type": "zip",
"url": "https://github.com/fabpot/Goutte/zipball/f2940f9c7c1f409159f5e9f512e575946c5cff48",
"reference": "f2940f9c7c1f409159f5e9f512e575946c5cff48",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"symfony/browser-kit": "2.1.*",
"symfony/css-selector": "2.1.*",
"symfony/dom-crawler": "2.1.*",
"symfony/finder": "2.1.*",
"symfony/process": "2.1.*",
"ext-curl": "*",
"guzzle/http": "2.8.*"
},
"time": "1351086217",
"type": "application",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"installation-source": "source",
"autoload": {
"psr-0": {
"Goutte": "."
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}
],
"description": "A simple PHP Web Scraper",
"homepage": "https://github.com/fabpot/Goutte",
"keywords": [
"scraper"
]
}, },
{ {
"package": "fabpot/goutte", "name": "guzzle/common",
"version": "dev-master", "version": "v2.8.8",
"source-reference": "6d26279344736f6983a969e46afef082ebf30a67", "target-dir": "Guzzle/Common",
"commit-date": "1345141401" "source": {
"type": "git",
"url": "git://github.com/guzzle/common.git",
"reference": "v2.8.8"
},
"dist": {
"type": "zip",
"url": "https://github.com/guzzle/common/zipball/v2.8.8",
"reference": "v2.8.8",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"symfony/event-dispatcher": "2.1.*"
},
"time": "2012-10-15 17:42:47",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"Guzzle\\Common": ""
}
},
"license": [
"MIT"
],
"description": "Common libraries used by Guzzle",
"homepage": "http://guzzlephp.org/",
"keywords": [
"log",
"event",
"cache",
"validation",
"Socket",
"common",
"batch",
"inflection"
]
}, },
{ {
"package": "guzzle/common", "name": "guzzle/http",
"version": "v2.8.4" "version": "v2.8.8",
"target-dir": "Guzzle/Http",
"source": {
"type": "git",
"url": "git://github.com/guzzle/http.git",
"reference": "v2.8.8"
},
"dist": {
"type": "zip",
"url": "https://github.com/guzzle/http/zipball/v2.8.8",
"reference": "v2.8.8",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"guzzle/common": "self.version",
"guzzle/parser": "self.version"
},
"time": "2012-10-15 17:42:47",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"Guzzle\\Http": ""
}
},
"license": [
"MIT"
],
"description": "HTTP libraries used by Guzzle",
"homepage": "http://guzzlephp.org/",
"keywords": [
"curl",
"http",
"http client",
"client",
"Guzzle"
]
}, },
{ {
"package": "guzzle/http", "name": "guzzle/parser",
"version": "v2.8.4" "version": "v2.8.8",
"target-dir": "Guzzle/Parser",
"source": {
"type": "git",
"url": "git://github.com/guzzle/parser.git",
"reference": "v2.8.8"
},
"dist": {
"type": "zip",
"url": "https://github.com/guzzle/parser/zipball/v2.8.8",
"reference": "v2.8.8",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"time": "2012-09-20 13:28:06",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"Guzzle\\Parser": ""
}
},
"license": [
"MIT"
],
"description": "Interchangeable parsers used by Guzzle",
"homepage": "http://guzzlephp.org/",
"keywords": [
"http",
"url",
"message",
"cookie",
"URI Template"
]
}, },
{ {
"package": "guzzle/parser", "name": "symfony/browser-kit",
"version": "v2.8.4" "version": "v2.1.3",
"target-dir": "Symfony/Component/BrowserKit",
"source": {
"type": "git",
"url": "https://github.com/symfony/BrowserKit",
"reference": "v2.1.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/BrowserKit/zipball/v2.1.3",
"reference": "v2.1.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"symfony/dom-crawler": "2.1.*"
},
"require-dev": {
"symfony/process": "2.1.*",
"symfony/css-selector": "2.1.*"
},
"suggest": {
"symfony/process": "2.1.*"
},
"time": "2012-10-25 06:11:50",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\BrowserKit": ""
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}, },
{ {
"package": "symfony/browser-kit", "name": "Symfony Community",
"version": "v2.1.0-RC1" "homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony BrowserKit Component",
"homepage": "http://symfony.com"
}, },
{ {
"package": "symfony/css-selector", "name": "symfony/css-selector",
"version": "v2.1.0-RC1" "version": "v2.1.3",
"target-dir": "Symfony/Component/CssSelector",
"source": {
"type": "git",
"url": "https://github.com/symfony/CssSelector",
"reference": "v2.1.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/CssSelector/zipball/v2.1.3",
"reference": "v2.1.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"time": "2012-10-04 08:17:57",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\CssSelector": ""
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}, },
{ {
"package": "symfony/dom-crawler", "name": "Symfony Community",
"version": "v2.1.0-RC1" "homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony CssSelector Component",
"homepage": "http://symfony.com"
}, },
{ {
"package": "symfony/finder", "name": "symfony/dom-crawler",
"version": "v2.1.0-RC1" "version": "v2.1.3",
"target-dir": "Symfony/Component/DomCrawler",
"source": {
"type": "git",
"url": "https://github.com/symfony/DomCrawler",
"reference": "v2.1.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/DomCrawler/zipball/v2.1.3",
"reference": "v2.1.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"symfony/css-selector": "2.1.*"
},
"suggest": {
"symfony/css-selector": "2.1.*"
},
"time": "2012-10-18 14:16:01",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\DomCrawler": ""
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}, },
{ {
"package": "symfony/process", "name": "Symfony Community",
"version": "v2.1.0-RC1" "homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony DomCrawler Component",
"homepage": "http://symfony.com"
},
{
"name": "symfony/finder",
"version": "v2.1.3",
"target-dir": "Symfony/Component/Finder",
"source": {
"type": "git",
"url": "https://github.com/symfony/Finder",
"reference": "v2.1.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/Finder/zipball/v2.1.3",
"reference": "v2.1.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"time": "2012-10-20 00:10:30",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\Finder": ""
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony Finder Component",
"homepage": "http://symfony.com"
},
{
"name": "symfony/process",
"version": "v2.1.3",
"target-dir": "Symfony/Component/Process",
"source": {
"type": "git",
"url": "https://github.com/symfony/Process",
"reference": "v2.1.3"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/Process/zipball/v2.1.3",
"reference": "v2.1.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"time": "2012-10-20 00:10:30",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\Process": ""
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony Process Component",
"homepage": "http://symfony.com"
} }
], ],
"aliases": [ "aliases": [

View file

@ -44,15 +44,15 @@ services:
- @cache.driver - @cache.driver
- %tables.config% - %tables.config%
cron.task_provider: cron.task_collection:
class: phpbb_cron_task_provider class: phpbb_di_service_collection
arguments: arguments:
- @container - @service_container
cron.manager: cron.manager:
class: phpbb_cron_manager class: phpbb_cron_manager
arguments: arguments:
- @cron.task_provider - @cron.task_collection
- %core.root_path% - %core.root_path%
- %core.php_ext% - %core.php_ext%
@ -65,6 +65,8 @@ services:
dispatcher: dispatcher:
class: phpbb_event_dispatcher class: phpbb_event_dispatcher
arguments:
- @service_container
dbal.conn: dbal.conn:
class: %dbal.driver.class% class: %dbal.driver.class%
@ -89,13 +91,6 @@ services:
- .%core.php_ext% - .%core.php_ext%
- @cache.driver - @cache.driver
processor.ext:
class: phpbb_di_processor_ext
arguments:
- @ext.manager
tags:
- { name: container.processor }
request: request:
class: phpbb_request class: phpbb_request

View file

@ -48,18 +48,31 @@ if (isset($_GET['avatar']))
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $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/functions_download' . '.' . $phpEx);
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
$phpbb_container = new ContainerBuilder(); // Setup class loader first
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", ".$phpEx");
$loader->load('services.yml'); $phpbb_class_loader->register();
$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_path}ext/", ".$phpEx");
$phpbb_class_loader_ext->register();
$processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx); // Set up container
$processor->process($phpbb_container); $phpbb_container = phpbb_create_dumped_container_unless_debug(
array(
new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx),
new phpbb_di_extension_core($phpbb_root_path),
),
array(
new phpbb_di_pass_collection_pass('cron.task_collection', 'cron.task'),
),
$phpbb_root_path,
$phpEx
);
$phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver'));
$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver'));
// set up caching // set up caching
$cache = $phpbb_container->get('cache'); $cache = $phpbb_container->get('cache');
@ -85,13 +98,6 @@ if (isset($_GET['avatar']))
$phpbb_extension_manager = $phpbb_container->get('ext.manager'); $phpbb_extension_manager = $phpbb_container->get('ext.manager');
$phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader');
$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor'));
foreach ($ids as $id)
{
$processor = $phpbb_container->get($id);
$processor->process($phpbb_container);
}
// worst-case default // worst-case default
$browser = strtolower($request->header('User-Agent', 'msie 6.0')); $browser = strtolower($request->header('User-Agent', 'msie 6.0'));

View file

@ -214,7 +214,11 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
while (($entry = readdir($dir)) !== false) 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; continue;
} }

View file

@ -162,7 +162,11 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base
while (($entry = readdir($dir)) !== false) 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; continue;
} }

View file

@ -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);
}
}

View file

@ -16,40 +16,31 @@ if (!defined('IN_PHPBB'))
} }
use Symfony\Component\DependencyInjection\ContainerBuilder; 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 * Container config extension
* user-defined parameters defined in the config.php file.
*/ */
class phpbb_di_processor_config implements phpbb_di_processor_interface class phpbb_di_extension_config extends Extension
{ {
private $config_file; public function __construct($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)
{ {
$this->config_file = $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; require($this->config_file);
$container->setParameter('core.root_path', $this->phpbb_root_path);
$container->setParameter('core.php_ext', $this->php_ext);
$container->setParameter('core.table_prefix', $table_prefix); $container->setParameter('core.table_prefix', $table_prefix);
$container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); $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.dbname', $dbname);
$container->setParameter('dbal.dbport', $dbport); $container->setParameter('dbal.dbport', $dbport);
$container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); $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) protected function fix_acm_type($acm_type)
{ {
if (preg_match('#^[a-z]+$#', $acm_type)) if (preg_match('#^[a-z]+$#', $acm_type))

View 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';
}
}

View 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';
}
}

View 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));
}
}
}

View file

@ -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');
}
}
}
}

View file

@ -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);
}

View 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);
}
}

View file

@ -15,7 +15,7 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
/** /**
* Extension of the Symfony2 EventDispatcher * Extension of the Symfony2 EventDispatcher
@ -31,7 +31,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
* extract($phpbb_dispatcher->trigger_event('core.index', compact($vars))); * 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()) public function trigger_event($eventName, $data = array())
{ {

View file

@ -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;
}
}

View file

@ -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();
}

View file

@ -195,7 +195,7 @@ class phpbb_extension_manager
if ($this->cache) if ($this->cache)
{ {
$this->cache->destroy($this->cache_name); $this->cache->purge();
} }
return !$active; return !$active;
@ -252,7 +252,7 @@ class phpbb_extension_manager
if ($this->cache) if ($this->cache)
{ {
$this->cache->destroy($this->cache_name); $this->cache->purge();
} }
return true; return true;
@ -272,7 +272,7 @@ class phpbb_extension_manager
if ($this->cache) if ($this->cache)
{ {
$this->cache->destroy($this->cache_name); $this->cache->purge();
} }
return false; return false;
@ -335,7 +335,7 @@ class phpbb_extension_manager
if ($this->cache) if ($this->cache)
{ {
$this->cache->destroy($this->cache_name); $this->cache->purge();
} }
return true; return true;
@ -349,7 +349,7 @@ class phpbb_extension_manager
if ($this->cache) if ($this->cache)
{ {
$this->cache->destroy($this->cache_name); $this->cache->purge();
} }
return false; return false;

View 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;
}

View file

@ -77,6 +77,7 @@ if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx);
require($phpbb_root_path . 'includes/functions_container.' . $phpEx);
phpbb_require_updated('includes/functions_content.' . $phpEx, true); phpbb_require_updated('includes/functions_content.' . $phpEx, true);
@ -98,20 +99,27 @@ if (!defined('EXT_TABLE'))
define('EXT_TABLE', $table_prefix . 'ext'); define('EXT_TABLE', $table_prefix . 'ext');
} }
$phpbb_container = new ContainerBuilder();
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config'));
$loader->load('services.yml');
// We must include the DI processor class files because the class loader
// is not yet set up
require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx);
require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx);
$processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx);
$processor->process($phpbb_container);
// Setup class loader first // Setup class loader first
$phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", ".$phpEx");
$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); $phpbb_class_loader->register();
$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_path}ext/", ".$phpEx");
$phpbb_class_loader_ext->register();
// Set up container
$phpbb_container = phpbb_create_dumped_container_unless_debug(
array(
new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx),
new phpbb_di_extension_core($phpbb_root_path),
),
array(
new phpbb_di_pass_collection_pass('cron.task_collection', 'cron.task'),
),
$phpbb_root_path,
$phpEx
);
$phpbb_class_loader->set_cache($phpbb_container->get('cache.driver'));
$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver'));
// set up caching // set up caching
$cache = $phpbb_container->get('cache'); $cache = $phpbb_container->get('cache');
@ -123,13 +131,6 @@ $user = $phpbb_container->get('user');
$auth = $phpbb_container->get('auth'); $auth = $phpbb_container->get('auth');
$db = $phpbb_container->get('dbal.conn'); $db = $phpbb_container->get('dbal.conn');
$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor'));
foreach ($ids as $id)
{
$processor = $phpbb_container->get($id);
$processor->process($phpbb_container);
}
// make sure request_var uses this request instance // make sure request_var uses this request instance
request_var('', 0, false, false, $request); // "dependency injection" for a function request_var('', 0, false, false, $request); // "dependency injection" for a function

View file

@ -75,10 +75,9 @@ else
// Include essential scripts // Include essential scripts
require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx);
require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx);
require($phpbb_root_path . 'includes/functions_container.' . $phpEx);
phpbb_require_updated('includes/functions_content.' . $phpEx, true); phpbb_require_updated('includes/functions_content.' . $phpEx, true);
@ -86,17 +85,17 @@ include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
require($phpbb_root_path . 'includes/functions_install.' . $phpEx); require($phpbb_root_path . 'includes/functions_install.' . $phpEx);
$phpbb_container = new ContainerBuilder(); // Setup class loader first
$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", ".$phpEx");
$loader->load('services.yml'); $phpbb_class_loader->register();
$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_path}ext/", ".$phpEx");
$phpbb_class_loader_ext->register();
$phpbb_container->setParameter('core.root_path', $phpbb_root_path); // Set up container
$phpbb_container->setParameter('core.php_ext', $phpEx); $phpbb_container = phpbb_create_install_container($phpbb_root_path, $phpEx);
$phpbb_container->setAlias('cache.driver', 'cache.driver.install'); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver'));
$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver'));
$phpbb_class_loader = $phpbb_container->get('class_loader');
$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext');
// set up caching // set up caching
$cache = $phpbb_container->get('cache'); $cache = $phpbb_container->get('cache');

View file

@ -1,50 +0,0 @@
<?php
/**
*
* @package testing
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->tasks = array(
'phpbb_cron_task_core_dummy_task',
'phpbb_cron_task_core_second_dummy_task',
'phpbb_ext_testext_cron_dummy_task',
);
$container = $this->getMock('Symfony\Component\DependencyInjection\TaggedContainerInterface');
$container
->expects($this->once())
->method('findTaggedServiceIds')
->will($this->returnValue(array_flip($this->tasks)));
$container
->expects($this->any())
->method('get')
->will($this->returnCallback(function ($name) {
return new $name;
}));
$this->provider = new phpbb_cron_task_provider($container);
}
public function test_manager_finds_shipped_tasks()
{
$task_names = array();
foreach ($this->provider as $task)
{
$task_names[] = $task->get_name();
}
sort($task_names);
$this->assertEquals(array(
'phpbb_cron_task_core_dummy_task',
'phpbb_cron_task_core_second_dummy_task',
'phpbb_ext_testext_cron_dummy_task',
), $task_names);
}
}

View file

@ -0,0 +1,72 @@
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/dbal.php';
class phpbb_di_container_test extends phpbb_test_case
{
public function test_phpbb_create_container()
{
$phpbb_root_path = __DIR__ . '/../../phpBB/';
$extensions = array(
new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'),
new phpbb_di_extension_core($phpbb_root_path),
);
$container = phpbb_create_container($extensions, $phpbb_root_path, 'php');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
}
public function test_phpbb_create_install_container()
{
$phpbb_root_path = __DIR__ . '/../../phpBB/';
$extensions = array(
new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'),
new phpbb_di_extension_core($phpbb_root_path),
);
$container = phpbb_create_install_container($phpbb_root_path, 'php');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
$this->assertTrue($container->isFrozen());
}
public function test_phpbb_create_compiled_container()
{
$phpbb_root_path = __DIR__ . '/../../phpBB/';
$extensions = array(
new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'),
new phpbb_di_extension_core($phpbb_root_path),
);
$container = phpbb_create_compiled_container($extensions, array(), $phpbb_root_path, 'php');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
$this->assertTrue($container->isFrozen());
}
}
class dbal_container_mock extends dbal
{
public function sql_connect()
{
}
public function sql_query()
{
}
public function sql_fetchrow()
{
}
public function sql_freeresult()
{
}
}

View file

@ -0,0 +1,11 @@
<?php
// phpBB 3.1.x auto-generated configuration file
// Do not change anything in this file!
$dbms = 'container_mock';
$dbhost = '127.0.0.1';
$dbport = '';
$dbname = 'phpbb';
$dbuser = 'root';
$dbpasswd = '';
$table_prefix = 'phpbb_';
$acm_type = 'phpbb_cache_driver_null';

View file

@ -11,7 +11,7 @@ class phpbb_event_dispatcher_test extends phpbb_test_case
{ {
public function test_trigger_event() public function test_trigger_event()
{ {
$dispatcher = new phpbb_event_dispatcher(); $dispatcher = new phpbb_event_dispatcher(new phpbb_mock_container_builder());
$dispatcher->addListener('core.test_event', function (phpbb_event_data $event) { $dispatcher->addListener('core.test_event', function (phpbb_event_data $event) {
$event['foo'] = $event['foo'] . '2'; $event['foo'] = $event['foo'] . '2';

View file

@ -0,0 +1,160 @@
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ScopeInterface;
class phpbb_mock_container_builder implements ContainerInterface
{
/**
* Sets a service.
*
* @param string $id The service identifier
* @param object $service The service instance
* @param string $scope The scope of the service
*
* @api
*/
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
{
}
/**
* Gets a service.
*
* @param string $id The service identifier
* @param int $invalidBehavior The behavior when the service does not exist
*
* @return object The associated service
*
* @throws InvalidArgumentException if the service is not defined
* @throws ServiceCircularReferenceException When a circular reference is detected
* @throws ServiceNotFoundException When the service is not defined
*
* @see Reference
*
* @api
*/
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
{
}
/**
* Returns true if the given service is defined.
*
* @param string $id The service identifier
*
* @return Boolean true if the service is defined, false otherwise
*
* @api
*/
public function has($id)
{
}
/**
* Gets a parameter.
*
* @param string $name The parameter name
*
* @return mixed The parameter value
*
* @throws InvalidArgumentException if the parameter is not defined
*
* @api
*/
public function getParameter($name)
{
}
/**
* Checks if a parameter exists.
*
* @param string $name The parameter name
*
* @return Boolean The presence of parameter in container
*
* @api
*/
public function hasParameter($name)
{
}
/**
* Sets a parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
*
* @api
*/
public function setParameter($name, $value)
{
}
/**
* Enters the given scope
*
* @param string $name
*
* @api
*/
public function enterScope($name)
{
}
/**
* Leaves the current scope, and re-enters the parent scope
*
* @param string $name
*
* @api
*/
public function leaveScope($name)
{
}
/**
* Adds a scope to the container
*
* @param ScopeInterface $scope
*
* @api
*/
public function addScope(ScopeInterface $scope)
{
}
/**
* Whether this container has the given scope
*
* @param string $name
*
* @return Boolean
*
* @api
*/
public function hasScope($name)
{
}
/**
* Determines whether the given scope is currently active.
*
* It does however not check if the scope actually exists.
*
* @param string $name
*
* @return Boolean
*
* @api
*/
public function isScopeActive($name)
{
}
}