Skip to content

Commit

Permalink
Allow tag instantiation to be overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
qurben committed Mar 24, 2020
1 parent 9b0a1f1 commit 4ce7b21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/BbTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ abstract class BbTag {
*/
protected $content = null;

public function __construct(Parser $parser, $env) {
public function setParser(Parser $parser) {
$this->parser = $parser;
}

public function setEnv($env) {
$this->env = $env;
}

Expand Down
11 changes: 10 additions & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public function parseArray($stoppers = [], $forbidden = []) {
$exists = isset($this->registry[$tag]);

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

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

Expand Down Expand Up @@ -476,4 +476,13 @@ private function getArguments($fullTag) {
return $argument_array;
}

protected function createTagInstance(string $tag, Parser $parser, $env) {
/** @var BbTag $tagInstance */
$tagInstance = new $tag($parser, $env);
$tagInstance->setParser($parser);
$tagInstance->setEnv($env);

return $tagInstance;
}

}

0 comments on commit 4ce7b21

Please sign in to comment.