diff --git a/config/services.yml b/config/services.yml index c185a43..6225ec6 100644 --- a/config/services.yml +++ b/config/services.yml @@ -14,7 +14,7 @@ services: alias: text_formatter.s9e.renderer phpbb\textformatter\cache_interface: - alias: text_formatter.s9e.factory + alias: text_formatter.cache phpbb\textformatter\parser_interface: alias: text_formatter.s9e.parser @@ -76,6 +76,13 @@ services: - '@service_container' - '@config' + phpbb.pages.text_formatter.cache: + class: phpbb\pages\textformatter\cache + decorates: text_formatter.cache + arguments: + - '@phpbb.pages.text_formatter.cache.inner' + - '@phpbb.pages.text_formatter.factory' + phpbb.pages.text_formatter.factory: class: phpbb\pages\textformatter\factory arguments: diff --git a/entity/page_interface.php b/entity/page_interface.php index ee3dcd8..9907637 100644 --- a/entity/page_interface.php +++ b/entity/page_interface.php @@ -227,7 +227,7 @@ public function set_content($content); /** * Check if bbcode is enabled on the content * - * @return bool + * @return int * @access public */ public function content_bbcode_enabled(); @@ -253,7 +253,7 @@ public function content_disable_bbcode(); /** * Check if magic_url is enabled on the content * - * @return bool + * @return int * @access public */ public function content_magic_url_enabled(); @@ -279,7 +279,7 @@ public function content_disable_magic_url(); /** * Check if smilies are enabled on the content * - * @return bool + * @return int * @access public */ public function content_smilies_enabled(); diff --git a/tests/textformatter/cache_test.php b/tests/textformatter/cache_test.php new file mode 100644 index 0000000..902b8e2 --- /dev/null +++ b/tests/textformatter/cache_test.php @@ -0,0 +1,36 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + */ + +namespace phpbb\pages\tests\textformatter; + +class cache_test extends \phpbb_test_case +{ + public function test_invalidate_invalidates_core_and_pages_caches() + { + $core_cache = $this->createMock(\phpbb\textformatter\cache_interface::class); + $pages_cache = $this->createMock(\phpbb\textformatter\cache_interface::class); + $core_cache->expects(self::once())->method('invalidate'); + $pages_cache->expects(self::once())->method('invalidate'); + + $cache = new \phpbb\pages\textformatter\cache($core_cache, $pages_cache); + $cache->invalidate(); + } + + public function test_tidy_tidies_core_and_regenerates_pages_cache() + { + $core_cache = $this->createMock(\phpbb\textformatter\cache_interface::class); + $pages_cache = $this->createMock(\phpbb\textformatter\cache_interface::class); + $core_cache->expects(self::once())->method('tidy'); + $pages_cache->expects(self::once())->method('invalidate'); + + $cache = new \phpbb\pages\textformatter\cache($core_cache, $pages_cache); + $cache->tidy(); + } +} diff --git a/textformatter/cache.php b/textformatter/cache.php new file mode 100644 index 0000000..848d492 --- /dev/null +++ b/textformatter/cache.php @@ -0,0 +1,56 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + */ + +namespace phpbb\pages\textformatter; + +/** + * Keeps the core and Pages text formatter caches synchronized + */ +class cache implements \phpbb\textformatter\cache_interface +{ + /** @var \phpbb\textformatter\cache_interface */ + protected $core_cache; + + /** @var \phpbb\textformatter\cache_interface */ + protected $pages_cache; + + /** + * Constructor + * + * @param \phpbb\textformatter\cache_interface $core_cache Core text formatter cache + * @param \phpbb\textformatter\cache_interface $pages_cache Pages text formatter cache + */ + public function __construct(\phpbb\textformatter\cache_interface $core_cache, \phpbb\textformatter\cache_interface $pages_cache) + { + $this->core_cache = $core_cache; + $this->pages_cache = $pages_cache; + } + + /** + * {@inheritdoc} + */ + public function invalidate() + { + $this->core_cache->invalidate(); + $this->pages_cache->invalidate(); + } + + /** + * {@inheritdoc} + */ + public function tidy() + { + $this->core_cache->tidy(); + + // Core and Pages renderers share a directory. Core tidy removes the + // Pages renderer, so regenerate both Pages cache entries together. + $this->pages_cache->invalidate(); + } +}