1 | <?php |
||
5 | class Shortcoder |
||
6 | { |
||
7 | /** |
||
8 | * The shortcodes stack |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $shortcodes = []; |
||
13 | |||
14 | /** |
||
15 | * Create a new Shortcoder instance |
||
16 | * |
||
17 | * @param array|null|string $pattern |
||
18 | * @param null|string $replacement |
||
19 | * @param mixed $regex |
||
20 | */ |
||
21 | 39 | public function __construct($pattern = null, $replacement = null, $regex = null) |
|
25 | |||
26 | /** |
||
27 | * Add shortcodes to the stack |
||
28 | * |
||
29 | * @param array|null|string $pattern |
||
30 | * @param null|string $replacement |
||
31 | * @param mixed $regex |
||
32 | * |
||
33 | * @return \Seiler\Shortcoder\Shortcoder |
||
34 | */ |
||
35 | 39 | public function add($pattern = null, $replacement = null, $regex = null) |
|
73 | |||
74 | /** |
||
75 | * Format the given pattern |
||
76 | * |
||
77 | * @param string $pattern |
||
78 | * @param mixed $regex |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | 33 | protected function formatPattern($pattern, $regex = null) |
|
102 | |||
103 | /** |
||
104 | * Format the given replacement |
||
105 | * |
||
106 | * @param string $replacement |
||
107 | * @param mixed $regex |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | 33 | protected function formatReplacement($replacement = '', $regex = null) |
|
136 | |||
137 | /** |
||
138 | * Parse the given text with stacked shortcodes |
||
139 | * |
||
140 | * @param string $text |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | 6 | public function parse($text = '') |
|
152 | |||
153 | /** |
||
154 | * Replace the stack with new shortcodes |
||
155 | * |
||
156 | * @param array|null|string $pattern |
||
157 | * @param null|string $replacement |
||
158 | * @param mixed $regex |
||
159 | * |
||
160 | * @return \Seiler\Shortcoder\Shortcoder |
||
161 | */ |
||
162 | 39 | public function set($pattern = null, $replacement = null, $regex = null) |
|
166 | |||
167 | /** |
||
168 | * Flush the stack |
||
169 | * |
||
170 | * @return \Seiler\Shortcoder\Shortcoder |
||
171 | */ |
||
172 | 39 | public function flush() |
|
178 | } |
||
179 |