|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Interface ParserMiddlewareInterface |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource ParserMiddlewareInterface.php |
|
6
|
|
|
* @created 26.04.2018 |
|
7
|
|
|
* @package chillerlan\BBCode |
|
8
|
|
|
* @author smiley <[email protected]> |
|
9
|
|
|
* @copyright 2018 smiley |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace chillerlan\BBCode; |
|
14
|
|
|
|
|
15
|
|
|
use chillerlan\Settings\SettingsContainerInterface; |
|
16
|
|
|
use Psr\Log\LoggerInterface; |
|
17
|
|
|
use Psr\SimpleCache\CacheInterface; |
|
18
|
|
|
|
|
19
|
|
|
interface ParserMiddlewareInterface{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* ParserMiddlewareInterface constructor. |
|
23
|
|
|
* |
|
24
|
|
|
* @param \chillerlan\Settings\SettingsContainerInterface $options |
|
25
|
|
|
* @param \Psr\SimpleCache\CacheInterface $cache |
|
26
|
|
|
* @param \Psr\Log\LoggerInterface $logger |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(SettingsContainerInterface $options, CacheInterface $cache, LoggerInterface $logger); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Pre-parser |
|
32
|
|
|
* |
|
33
|
|
|
* The bbcode you receive is already sanitized, which means: a |
|
34
|
|
|
* ny replacements you do here won't be sanitized any further. Take care! |
|
35
|
|
|
* Do anything here to the unparsed bbcode, just don't touch newlines |
|
36
|
|
|
* - these will be replaced with a placeholder after this step. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $bbcode bbcode |
|
39
|
|
|
* |
|
40
|
|
|
* @return string preparsed bbcode |
|
41
|
|
|
*/ |
|
42
|
|
|
public function pre(string $bbcode):string; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Post-parser |
|
46
|
|
|
* |
|
47
|
|
|
* Use this method in case you want to alter the parsed bbcode. |
|
48
|
|
|
* The newline placeholders are still available and any remaining will |
|
49
|
|
|
* be removed in the last step before output |
|
50
|
|
|
* |
|
51
|
|
|
* Example: you want the "img" bbcode to use database images instead of user URLs. |
|
52
|
|
|
* You'd replace any occurence with a unique placeholder like {__IMG#ID__}. |
|
53
|
|
|
* Now the post-parser gets into play: you preg_match_all() out all your placeholders, |
|
54
|
|
|
* grab the images in a single query from the database and replace them with their respective <img> tag |
|
55
|
|
|
* or whatever replacement and any corrupt id with a placeholder image. Profit! |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $bbcode bbcode |
|
58
|
|
|
* |
|
59
|
|
|
* @return string postparsed bbcode |
|
60
|
|
|
*/ |
|
61
|
|
|
public function post(string $bbcode):string; |
|
62
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@returndoc comment to communicate to implementors of these methods what they are expected to return.