From 72d89f96f31af5c92f96fa16f0d1adf15c0bf4e8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 7 Jan 2014 19:16:54 +0100 Subject: remove duplicate plugin code for syntax plugins This makes Doku_Parser_Mode inherit from DokuWiki_Plugin which allows for the removal of a bunch of duplicate code form DokuWiki_Syntax_Plugin. This makes the code easier to maintain and makes sure all DokuWiki plugins are actual instances of DokuWiki_Plugin. However this adds a bunch of functions to the "normal" parser modes that don't need them which could have performance/RAM implications. --- inc/parser/parser.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'inc/parser/parser.php') diff --git a/inc/parser/parser.php b/inc/parser/parser.php index 1f14b98a3..43a1c22fa 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -126,16 +126,14 @@ class Doku_Parser { //------------------------------------------------------------------- /** - * This class and all the subclasses below are - * used to reduce the effort required to register - * modes with the Lexer. For performance these - * could all be eliminated later perhaps, or - * the Parser could be serialized to a file once - * all modes are registered + * This class and all the subclasses below are used to reduce the effort required to register + * modes with the Lexer. + * + * Inherits from DokuWiki_Plugin for giving additional functions to syntax plugins * * @author Harry Fuecks */ -class Doku_Parser_Mode { +class Doku_Parser_Mode extends DokuWiki_Plugin { /** * @var Doku_Lexer $Lexer -- cgit v1.2.3 From 5a3e1f53b18728d500b3505f4fbd8c78848120e0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 7 Jan 2014 19:35:57 +0100 Subject: reintroduce a tiny bit of duplication This reads some duplication in the from of haveing a Doku_Parser_Mode and Doku_Parser_Mode_Plugin class which are basically the same but only the latter extends DokuWiki_Plugin. This avoids the performance/RAM problems mentioned in my previous commit. An interface keeps both logically together. With PHP 5.4 further deduplication could be done via Traits. --- inc/parser/parser.php | 74 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 12 deletions(-) (limited to 'inc/parser/parser.php') diff --git a/inc/parser/parser.php b/inc/parser/parser.php index 43a1c22fa..252bd9170 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -125,41 +125,91 @@ class Doku_Parser { } //------------------------------------------------------------------- + +/** + * Class Doku_Parser_Mode_Interface + * + * Defines a mode (syntax component) in the Parser + */ +interface Doku_Parser_Mode_Interface { + /** + * returns a number used to determine in which order modes are added + */ + public function getSort(); + + /** + * Called before any calls to connectTo + */ + function preConnect(); + + /** + * Connects the mode + * + * @param string $mode + */ + function connectTo($mode); + + /** + * Called after all calls to connectTo + */ + function postConnect(); + + /** + * Check if given mode is accepted inside this mode + * + * @param string $mode + * @return bool + */ + function accepts($mode); +} + /** * This class and all the subclasses below are used to reduce the effort required to register * modes with the Lexer. * - * Inherits from DokuWiki_Plugin for giving additional functions to syntax plugins - * * @author Harry Fuecks */ -class Doku_Parser_Mode extends DokuWiki_Plugin { - +class Doku_Parser_Mode implements Doku_Parser_Mode_Interface { /** * @var Doku_Lexer $Lexer */ var $Lexer; - var $allowedModes = array(); - // returns a number used to determine in which order modes are added function getSort() { trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING); } - // Called before any calls to connectTo function preConnect() {} - - // Connects the mode function connectTo($mode) {} - - // Called after all calls to connectTo function postConnect() {} - function accepts($mode) { return in_array($mode, (array) $this->allowedModes ); } +} +/** + * Basically the same as Doku_Parser_Mode but extends from DokuWiki_Plugin + * + * Adds additional functions to syntax plugins + */ +class Doku_Parser_Mode_Plugin extends DokuWiki_Plugin implements Doku_Parser_Mode_Interface { + /** + * @var Doku_Lexer $Lexer + */ + var $Lexer; + var $allowedModes = array(); + + function getSort() { + trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING); + } + + function preConnect() {} + function connectTo($mode) {} + function postConnect() {} + function accepts($mode) { + return in_array($mode, (array) $this->allowedModes ); + } } //------------------------------------------------------------------- -- cgit v1.2.3 From 7ac0b9fe750a5713353e6edce51493a8a75c4f6f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 25 May 2014 12:24:14 +0200 Subject: just some more doc blocks --- inc/parser/parser.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'inc/parser/parser.php') diff --git a/inc/parser/parser.php b/inc/parser/parser.php index 252bd9170..df01f3302 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -200,6 +200,11 @@ class Doku_Parser_Mode_Plugin extends DokuWiki_Plugin implements Doku_Parser_Mod var $Lexer; var $allowedModes = array(); + /** + * Sort for applying this mode + * + * @return int + */ function getSort() { trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING); } -- cgit v1.2.3 From 276820f70d7e96ee375735c1a15bdc0a8331a5a7 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Sat, 10 Jan 2015 14:47:51 +0000 Subject: Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- inc/parser/parser.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'inc/parser/parser.php') diff --git a/inc/parser/parser.php b/inc/parser/parser.php index df01f3302..5f86cf5c4 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -61,6 +61,9 @@ class Doku_Parser { var $connected = false; + /** + * @param Doku_Parser_Mode_base $BaseMode + */ function addBaseMode(& $BaseMode) { $this->modes['base'] =& $BaseMode; if ( !$this->Lexer ) { @@ -139,6 +142,7 @@ interface Doku_Parser_Mode_Interface { /** * Called before any calls to connectTo + * @return void */ function preConnect(); @@ -146,11 +150,13 @@ interface Doku_Parser_Mode_Interface { * Connects the mode * * @param string $mode + * @return void */ function connectTo($mode); /** * Called after all calls to connectTo + * @return void */ function postConnect(); @@ -407,6 +413,9 @@ class Doku_Parser_Mode_formatting extends Doku_Parser_Mode { ), ); + /** + * @param string $type + */ function Doku_Parser_Mode_formatting($type) { global $PARSER_MODES; -- cgit v1.2.3