mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/11768] Added configurator events
PHPBB3-11768
This commit is contained in:
parent
f4f5bdbaee
commit
49b9e8e4ea
4 changed files with 84 additions and 4 deletions
|
@ -31,6 +31,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- @text_formatter.data_access
|
- @text_formatter.data_access
|
||||||
- @cache.driver
|
- @cache.driver
|
||||||
|
- @dispatcher
|
||||||
- %text_formatter.cache.dir%
|
- %text_formatter.cache.dir%
|
||||||
- %text_formatter.cache.parser.key%
|
- %text_formatter.cache.parser.key%
|
||||||
- %text_formatter.cache.renderer.key%
|
- %text_formatter.cache.renderer.key%
|
||||||
|
|
|
@ -100,23 +100,29 @@ class factory implements \phpbb\textformatter\cache_interface
|
||||||
'email' => '<a href="mailto:{EMAIL}"><xsl:apply-templates/></a>',
|
'email' => '<a href="mailto:{EMAIL}"><xsl:apply-templates/></a>',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \phpbb\event\dispatcher_interface
|
||||||
|
*/
|
||||||
|
protected $dispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param \phpbb\textformatter\data_access $data_access
|
* @param \phpbb\textformatter\data_access $data_access
|
||||||
* @param \phpbb\cache\driver\driver_interface $cache
|
* @param \phpbb\cache\driver\driver_interface $cache
|
||||||
|
* @param \phpbb\event\dispatcher_interface $dispatcher
|
||||||
* @param string $cache_dir Path to the cache dir
|
* @param string $cache_dir Path to the cache dir
|
||||||
* @param string $cache_key_parser Cache key used for the parser
|
* @param string $cache_key_parser Cache key used for the parser
|
||||||
* @param string $cache_key_renderer Cache key used for the renderer
|
* @param string $cache_key_renderer Cache key used for the renderer
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\textformatter\data_access $data_access, \phpbb\cache\driver\driver_interface $cache, $cache_dir, $cache_key_parser, $cache_key_renderer)
|
public function __construct(\phpbb\textformatter\data_access $data_access, \phpbb\cache\driver\driver_interface $cache, \phpbb\event\dispatcher_interface $dispatcher, $cache_dir, $cache_key_parser, $cache_key_renderer)
|
||||||
{
|
{
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
$this->cache_dir = $cache_dir;
|
$this->cache_dir = $cache_dir;
|
||||||
$this->cache_key_parser = $cache_key_parser;
|
$this->cache_key_parser = $cache_key_parser;
|
||||||
$this->cache_key_renderer = $cache_key_renderer;
|
$this->cache_key_renderer = $cache_key_renderer;
|
||||||
|
|
||||||
$this->data_access = $data_access;
|
$this->data_access = $data_access;
|
||||||
|
$this->dispatcher = $dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,6 +164,16 @@ class factory implements \phpbb\textformatter\cache_interface
|
||||||
// Create a new Configurator
|
// Create a new Configurator
|
||||||
$configurator = new Configurator;
|
$configurator = new Configurator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify the s9e\TextFormatter configurator before the default settings are set
|
||||||
|
*
|
||||||
|
* @event core.text_formatter_s9e_configure_before
|
||||||
|
* @var \s9e\TextFormatter\Configurator configurator Configurator instance
|
||||||
|
* @since 3.2.0-a1
|
||||||
|
*/
|
||||||
|
$vars = array('configurator');
|
||||||
|
extract($this->dispatcher->trigger_event('core.text_formatter_s9e_configure_before', compact($vars)));
|
||||||
|
|
||||||
// Convert newlines to br elements by default
|
// Convert newlines to br elements by default
|
||||||
$configurator->rootRules->enableAutoLineBreaks();
|
$configurator->rootRules->enableAutoLineBreaks();
|
||||||
|
|
||||||
|
@ -288,6 +304,16 @@ class factory implements \phpbb\textformatter\cache_interface
|
||||||
$configurator->registeredVars['max_img_height'] = 0;
|
$configurator->registeredVars['max_img_height'] = 0;
|
||||||
$configurator->registeredVars['max_img_width'] = 0;
|
$configurator->registeredVars['max_img_width'] = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify the s9e\TextFormatter configurator after the default settings are set
|
||||||
|
*
|
||||||
|
* @event core.text_formatter_s9e_configure_after
|
||||||
|
* @var \s9e\TextFormatter\Configurator configurator Configurator instance
|
||||||
|
* @since 3.2.0-a1
|
||||||
|
*/
|
||||||
|
$vars = array('configurator');
|
||||||
|
extract($this->dispatcher->trigger_event('core.text_formatter_s9e_configure_after', compact($vars)));
|
||||||
|
|
||||||
return $configurator;
|
return $configurator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -315,7 +315,7 @@ class phpbb_test_case_helpers
|
||||||
public function set_s9e_services(ContainerInterface $container = null, $fixture = null, $styles_path = null)
|
public function set_s9e_services(ContainerInterface $container = null, $fixture = null, $styles_path = null)
|
||||||
{
|
{
|
||||||
static $first_run;
|
static $first_run;
|
||||||
global $phpbb_container, $phpbb_root_path, $phpEx;
|
global $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
$cache_dir = __DIR__ . '/../tmp/';
|
$cache_dir = __DIR__ . '/../tmp/';
|
||||||
|
|
||||||
|
@ -443,8 +443,22 @@ class phpbb_test_case_helpers
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create an event dispatcher
|
||||||
|
if ($container->has('dispatcher'))
|
||||||
|
{
|
||||||
|
$dispatcher = $container->get('dispatcher');
|
||||||
|
}
|
||||||
|
else if (isset($phpbb_dispatcher))
|
||||||
|
{
|
||||||
|
$dispatcher = $phpbb_dispatcher;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$dispatcher = new phpbb_mock_event_dispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
// Create and register the text_formatter.s9e.factory service
|
// Create and register the text_formatter.s9e.factory service
|
||||||
$factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $cache_dir, $cache_key_parser, $cache_key_renderer);
|
$factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $dispatcher, $cache_dir, $cache_key_parser, $cache_key_renderer);
|
||||||
$container->set('text_formatter.s9e.factory', $factory);
|
$container->set('text_formatter.s9e.factory', $factory);
|
||||||
|
|
||||||
// Create a user if none was provided, and add the common lang strings
|
// Create a user if none was provided, and add the common lang strings
|
||||||
|
|
|
@ -16,6 +16,13 @@ require_once __DIR__ . '/../../test_framework/phpbb_database_test_case.php';
|
||||||
|
|
||||||
class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case
|
class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case
|
||||||
{
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->cache = new phpbb_mock_cache;
|
||||||
|
$this->dispatcher = new phpbb_mock_event_dispatcher;
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
public function getDataSet()
|
public function getDataSet()
|
||||||
{
|
{
|
||||||
return $this->createXMLDataSet(__DIR__ . '/fixtures/factory.xml');
|
return $this->createXMLDataSet(__DIR__ . '/fixtures/factory.xml');
|
||||||
|
@ -41,6 +48,7 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case
|
||||||
$factory = new \phpbb\textformatter\s9e\factory(
|
$factory = new \phpbb\textformatter\s9e\factory(
|
||||||
$dal,
|
$dal,
|
||||||
$this->cache,
|
$this->cache,
|
||||||
|
$this->dispatcher,
|
||||||
$this->get_cache_dir(),
|
$this->get_cache_dir(),
|
||||||
'_foo_parser',
|
'_foo_parser',
|
||||||
'_foo_renderer'
|
'_foo_renderer'
|
||||||
|
@ -184,4 +192,35 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case
|
||||||
$expected = '<a href="javascript:alert(1)">text</a>';
|
$expected = '<a href="javascript:alert(1)">text</a>';
|
||||||
$this->assertSame($expected, $renderer->render($parser->parse($original)));
|
$this->assertSame($expected, $renderer->render($parser->parse($original)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @testdox get_configurator() triggers events before and after configuration
|
||||||
|
*/
|
||||||
|
public function test_configure_events()
|
||||||
|
{
|
||||||
|
$this->dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface');
|
||||||
|
$this->dispatcher
|
||||||
|
->expects($this->at(0))
|
||||||
|
->method('trigger_event')
|
||||||
|
->with(
|
||||||
|
'core.text_formatter_s9e_configure_before',
|
||||||
|
$this->callback(array($this, 'configure_event_callback'))
|
||||||
|
)
|
||||||
|
->will($this->returnArgument(1));
|
||||||
|
$this->dispatcher
|
||||||
|
->expects($this->at(1))
|
||||||
|
->method('trigger_event')
|
||||||
|
->with(
|
||||||
|
'core.text_formatter_s9e_configure_after',
|
||||||
|
$this->callback(array($this, 'configure_event_callback'))
|
||||||
|
)
|
||||||
|
->will($this->returnArgument(1));
|
||||||
|
|
||||||
|
$this->get_factory()->get_configurator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configure_event_callback($vars)
|
||||||
|
{
|
||||||
|
return isset($vars['configurator']) && $vars['configurator'] instanceof \s9e\TextFormatter\Configurator;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue