-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replace "listenere" with "listener" in comments * Replace "listenere" with "listener" in local variable * Replace "listenere" with "listener" in methods Since methods may be exposed to other classes, use an alias for the listenere * Update Lexer.php Co-authored-by: Basil <[email protected]>
- Loading branch information
1 parent
cd105b7
commit 56abc51
Showing
6 changed files
with
52 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
/** | ||
* Block Listener | ||
* | ||
* Block listeneres writes from $line->input into the $line->output. | ||
* Block listener writes from $line->input into the $line->output. | ||
* | ||
* @author Basil Suter <[email protected]> | ||
* @since 1.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ | |
use Exception; | ||
|
||
/** | ||
* Inline Listenere. | ||
* Inline listener. | ||
* | ||
* Inline listeneres changes the $line->input value! | ||
* Inline listeners changes the $line->input value! | ||
* | ||
* @author Basil Suter <[email protected]> | ||
* @since 1.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,36 +24,36 @@ | |
* | ||
* The lexer class represents the main thread in how delta input is processed and rendered. | ||
* | ||
* Basically Listeneres can watch every line of delta and interact with the line, which means | ||
* reading input and writting to output and mark this line as done, so other listeneres won't | ||
* Basically listeners can watch every line of delta and interact with the line, which means | ||
* reading input and writting to output and mark this line as done, so other listeners won't | ||
* take care of this line as well. | ||
* | ||
* ## Basic concept | ||
* | ||
* Listeneres are grouped in 2 types: | ||
* Listeners are grouped in 2 types: | ||
* | ||
* + inline: For elements which are only inline applied, like writing bold or italic | ||
* + block: Used when the line represents a full html element like heading or lists | ||
* | ||
* Inside this group types there are 2 prioirities: | ||
* | ||
* + early bird: This is default value, the early bird catches the worm... | ||
* + garbage collector: This is mainly used for the text listenere which generates the paragraphs and can only be done at the very end of the process. | ||
* + garbage collector: This is mainly used for the text listener which generates the paragraphs and can only be done at the very end of the process. | ||
* | ||
* Every listenere has two methods a process() and render(): | ||
* Every listener has two methods a process() and render(): | ||
* | ||
* + process: is triggered by every line, so the listenere can choose whether he wants to pick this line, interact or not. | ||
* + render: after all lines are processed, every listenered triggers the render() method once, so the picked line from process can be "further" processed and rendered. | ||
* + process: is triggered by every line, so the listener can choose whether he wants to pick this line, interact or not. | ||
* + render: after all lines are processed, every listener triggers the render() method once, so the picked line from process can be "further" processed and rendered. | ||
* | ||
* ## Lifecycle | ||
* | ||
* 1. lines will be generated | ||
* 2. lines foreached and inline early bird listeners run process() method. | ||
* 3. lines foreached and inline garbage collector listeneres run process() method. | ||
* 4. lines foreached and block early bird listeneres run process() method. | ||
* 5. lines foreached and block garbage collector listenere run process() method. | ||
* 6. inline listeneres foreach and run render() method. | ||
* 7. block listeneres foreach and run render() method. | ||
* 3. lines foreached and inline garbage collector listeners run process() method. | ||
* 4. lines foreached and block early bird listeners run process() method. | ||
* 5. lines foreached and block garbage collector listener run process() method. | ||
* 6. inline listeners foreach and run render() method. | ||
* 7. block listeners foreach and run render() method. | ||
* | ||
* @author Basil Suter <[email protected]> | ||
* @since 1.0.0 | ||
|
@@ -104,7 +104,7 @@ class Lexer | |
protected $json; | ||
|
||
/** | ||
* @var array The listeneres grouped by type and priority. | ||
* @var array The listeners grouped by type and priority. | ||
*/ | ||
protected $listeners = [ | ||
Listener::TYPE_INLINE => [ | ||
|
@@ -121,21 +121,21 @@ class Lexer | |
* Initializer | ||
* | ||
* @param string|array $json The delta ops json as string or as already parsed array. | ||
* @param boolean $loadBuiltinListeneres Whether the built in listeneres should be loaded or not. | ||
* @param boolean $loadBuiltinlisteners Whether the built in listeners should be loaded or not. | ||
*/ | ||
public function __construct($json, $loadBuiltinListeneres = true) | ||
public function __construct($json, $loadBuiltinListeners = true) | ||
{ | ||
$this->json = $json; | ||
|
||
if ($loadBuiltinListeneres) { | ||
$this->loadBuiltinListeneres(); | ||
if ($loadBuiltinListeners) { | ||
$this->loadBuiltinListeners(); | ||
} | ||
} | ||
|
||
/** | ||
* Loads the library built in listeneres. | ||
* Loads the library built in listeners. | ||
*/ | ||
public function loadBuiltinListeneres() | ||
public function loadBuiltinListeners() | ||
{ | ||
$this->registerListener(new Image); | ||
$this->registerListener(new Bold); | ||
|
@@ -156,7 +156,16 @@ public function loadBuiltinListeneres() | |
} | ||
|
||
/** | ||
* Register a new listenere. | ||
* Alias for loadBuiltinListeners() for compatibility | ||
* @deprecated will be removed in 3.0 | ||
*/ | ||
public function loadBuiltinListeneres() | ||
{ | ||
return $this->loadBuiltinListeners(); | ||
} | ||
|
||
/** | ||
* Register a new listener. | ||
* | ||
* @param Listener $listener | ||
*/ | ||
|
@@ -169,15 +178,15 @@ public function registerListener(Listener $listener) | |
* Overrite an existing listener with a new object | ||
* | ||
* An example could when you like to provide more options or access other elements which are not covered by the base class | ||
* so you can extend from the built in listeneres and overrite them. This keeps also the hyrarchical level of the elements. | ||
* so you can extend from the built in listeners and overrite them. This keeps also the hyrarchical level of the elements. | ||
* | ||
* ```php | ||
* $lexer->overwriteListener(new Image, new MyOwnImage); | ||
* ``` | ||
* | ||
* As the `new Image` listener is already registered, it will just replace the object with `new MyOwnImage`. | ||
* | ||
* @param Listener $listener The already registered listenere object | ||
* @param Listener $listener The already registered listener object | ||
* @param Listener $new The new listener object | ||
* @see https://github.com/nadar/quill-delta-parser/issues/55 | ||
* @since 2.8.0 | ||
|
@@ -353,7 +362,7 @@ protected function processListeners(Line $line, $type) | |
* @param [type] $type | ||
* @return void | ||
*/ | ||
protected function renderListeneres($type) | ||
protected function renderListeners($type) | ||
{ | ||
foreach ($this->listeners[$type] as $prios) { | ||
foreach ($prios as $listener) { | ||
|
@@ -362,6 +371,15 @@ protected function renderListeneres($type) | |
} | ||
} | ||
|
||
/** | ||
* Alias for renderListeners() for compatibility | ||
* @deprecated will be removed in 3.0 | ||
*/ | ||
protected function renderListeneres($type) | ||
{ | ||
return $this->renderListeners($type); | ||
} | ||
|
||
/** | ||
* Renders the current delta into a html string. | ||
* | ||
|
@@ -376,8 +394,8 @@ public function render() | |
$this->processListeners($line, Listener::TYPE_BLOCK); | ||
} | ||
|
||
$this->renderListeneres(Listener::TYPE_INLINE); | ||
$this->renderListeneres(Listener::TYPE_BLOCK); | ||
$this->renderListeners(Listener::TYPE_INLINE); | ||
$this->renderListeners(Listener::TYPE_BLOCK); | ||
|
||
$buff = null; | ||
foreach ($this->_lines as $line) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
/** | ||
* Listener Object. | ||
* | ||
* Every type of element is a listenere. Listeneres are "listening" to every line of delta code and can | ||
* Every type of element is a listener. Listeners are "listening" to every line of delta code and can | ||
* pick and process this line. | ||
* | ||
* @author Basil Suter <[email protected]> | ||
|
@@ -30,7 +30,7 @@ abstract class Listener | |
|
||
/** | ||
* @var integer Second priority listener within the given type. This is currently only used | ||
* for TEXT listeneres - as they need to be the very last entry. | ||
* for TEXT listeners - as they need to be the very last entry. | ||
*/ | ||
const PRIORITY_GARBAGE_COLLECTOR = 2; | ||
|
||
|