Skip to content

Commit 4ce7b21

Browse files
committed
Allow tag instantiation to be overridden
1 parent 9b0a1f1 commit 4ce7b21

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/BbTag.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ abstract class BbTag {
2121
*/
2222
protected $content = null;
2323

24-
public function __construct(Parser $parser, $env) {
24+
public function setParser(Parser $parser) {
2525
$this->parser = $parser;
26+
}
27+
28+
public function setEnv($env) {
2629
$this->env = $env;
2730
}
2831

src/Parser.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public function parseArray($stoppers = [], $forbidden = []) {
309309
$exists = isset($this->registry[$tag]);
310310

311311
if ($this->bb_mode && $isOpenTag && $exists && $isAllowed) {
312-
$tagInstance = new $this->registry[$tag]($this, $this->env);
312+
$tagInstance = $this->createTagInstance($this->registry[$tag], $this, $this->env);
313313

314314
$arguments = $this->getArguments($entry);
315315

@@ -476,4 +476,13 @@ private function getArguments($fullTag) {
476476
return $argument_array;
477477
}
478478

479+
protected function createTagInstance(string $tag, Parser $parser, $env) {
480+
/** @var BbTag $tagInstance */
481+
$tagInstance = new $tag($parser, $env);
482+
$tagInstance->setParser($parser);
483+
$tagInstance->setEnv($env);
484+
485+
return $tagInstance;
486+
}
487+
479488
}

0 commit comments

Comments
 (0)