diff options
author | Andreas Gohr <andi@splitbrain.org> | 2014-01-07 19:35:57 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2014-01-07 19:35:57 +0100 |
commit | 5a3e1f53b18728d500b3505f4fbd8c78848120e0 (patch) | |
tree | 5bd3c765891973fe1d65f86e67c557cd8cf20b11 /inc/parser | |
parent | 72d89f96f31af5c92f96fa16f0d1adf15c0bf4e8 (diff) | |
download | rpg-5a3e1f53b18728d500b3505f4fbd8c78848120e0.tar.gz rpg-5a3e1f53b18728d500b3505f4fbd8c78848120e0.tar.bz2 |
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.
Diffstat (limited to 'inc/parser')
-rw-r--r-- | inc/parser/parser.php | 74 |
1 files changed, 62 insertions, 12 deletions
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 <hfuecks@gmail.com> */ -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 ); + } } //------------------------------------------------------------------- |