[ticket/11768] Updated constructors with explicit dependencies

The trade-off is that an instance of phpbb\textformatter\s9e\factory and
phpbb\textformatter\data_access is created on any page that uses the
parser or the renderer, even when neither need to be regenerated. It has
no measureable impact on performance and costs ~20KB of RAM.

PHPBB3-11768
This commit is contained in:
s9e 2015-02-04 23:07:58 +01:00 committed by JoshyPHP
parent e0bb446c57
commit 72fb380c9f
3 changed files with 11 additions and 11 deletions

View file

@ -41,7 +41,7 @@ services:
- @cache.driver - @cache.driver
- %text_formatter.cache.parser.key% - %text_formatter.cache.parser.key%
- @user - @user
- @service_container - @text_formatter.s9e.factory
text_formatter.s9e.renderer: text_formatter.s9e.renderer:
class: phpbb\textformatter\s9e\renderer class: phpbb\textformatter\s9e\renderer
@ -49,7 +49,7 @@ services:
- @cache.driver - @cache.driver
- %text_formatter.cache.dir% - %text_formatter.cache.dir%
- %text_formatter.cache.renderer.key% - %text_formatter.cache.renderer.key%
- @service_container - @text_formatter.s9e.factory
calls: calls:
- [configure_smilies_path, [@config, @path_helper]] - [configure_smilies_path, [@config, @path_helper]]
- [configure_user, [@user, @config, @auth]] - [configure_user, [@user, @config, @auth]]

View file

@ -39,17 +39,17 @@ class parser extends \phpbb\textformatter\parser
* @param phpbb\cache\driver_interface $cache * @param phpbb\cache\driver_interface $cache
* @param string $key Cache key * @param string $key Cache key
* @param phpbb\user $user * @param phpbb\user $user
* @param ContainerInterface $container * @param factory $factory
* @return null * @return null
*/ */
public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, ContainerInterface $container) public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, factory $factory)
{ {
$this->user = $user; $this->user = $user;
$parser = $cache->get($key); $parser = $cache->get($key);
if (!$parser) if (!$parser)
{ {
list($parser) = $container->get('text_formatter.s9e.factory')->regenerate(); list($parser) = $factory->regenerate();
} }
$this->parser = $parser; $this->parser = $parser;

View file

@ -49,13 +49,13 @@ class renderer extends \phpbb\textformatter\renderer
/** /**
* Constructor * Constructor
* *
* @param phpbb\cache\driver\driver_interface $cache * @param \phpbb\cache\driver\driver_interface $cache
* @param string $cache_dir Path to the cache dir * @param string $cache_dir Path to the cache dir
* @param string $key Cache key * @param string $key Cache key
* @param ContainerInterface $container * @param factory $factory
* @return null * @return null
*/ */
public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, ContainerInterface $container) public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, factory $factory)
{ {
$renderer_data = $cache->get($key); $renderer_data = $cache->get($key);
@ -82,7 +82,7 @@ class renderer extends \phpbb\textformatter\renderer
if (!isset($renderer)) if (!isset($renderer))
{ {
list(, $renderer) = $container->get('text_formatter.s9e.factory')->regenerate(); list(, $renderer) = $factory->regenerate();
} }
$this->renderer = $renderer; $this->renderer = $renderer;