class TagElement in Extensible BBCode 4.0.x
Same name and namespace in other branches
- 8.3 src/Parser/Tree/TagElement.php \Drupal\xbbcode\Parser\Tree\TagElement
A BBCode tag element.
Hierarchy
- class \Drupal\xbbcode\Parser\Tree\NodeElement implements NodeElementInterface
- class \Drupal\xbbcode\Parser\Tree\TagElement implements TagElementInterface
Expanded class hierarchy of TagElement
2 files declare their use of TagElement
- TreeEncodeTrait.php in standard/
src/ TreeEncodeTrait.php - XBBCodeParser.php in src/
Parser/ XBBCodeParser.php
File
- src/
Parser/ Tree/ TagElement.php, line 11
Namespace
Drupal\xbbcode\Parser\TreeView source
class TagElement extends NodeElement implements TagElementInterface {
/**
* The processor handling this element.
*
* @var \Drupal\xbbcode\Parser\Processor\TagProcessorInterface
*/
private $processor;
/**
* The tag argument.
*
* @var string
*/
private $argument;
/**
* The tag content source.
*
* @var string
*/
private $source;
/**
* The tag name.
*
* @var string
*/
private $name;
/**
* The tag attributes.
*
* @var string[]
*/
private $attributes = [];
/**
* The tag option.
*
* @var string
*/
private $option;
/**
* The tag's parent element.
*
* @var \Drupal\xbbcode\Parser\Tree\NodeElementInterface
*/
private $parent;
/**
* Opening tag name.
*
* @var string
*/
private $openingName;
/**
* Closing tag name.
*
* @var string
*/
private $closingName;
/**
* TagElement constructor.
*
* @param string $opening
* The opening tag name.
* @param string $argument
* The argument (everything past the tag name)
* @param string $source
* The source of the content.
*/
public function __construct(string $opening, string $argument, string $source) {
$this->name = mb_strtolower($opening);
$this->openingName = $opening;
$this->argument = $argument;
$this->source = $source;
if ($argument && $argument[0] === '=') {
$this->option = XBBCodeParser::parseOption($argument);
}
else {
$this->attributes = XBBCodeParser::parseAttributes($argument);
}
}
/**
* {@inheritdoc}
*/
public function getName() : string {
return $this->name;
}
/**
* {@inheritdoc}
*/
public function getOpeningName() : string {
return $this->openingName;
}
/**
* {@inheritdoc}
*/
public function getClosingName() : string {
return $this->closingName;
}
/**
* {@inheritdoc}
*/
public function setClosingName(string $closing) : TagElementInterface {
$this->closingName = $closing;
return $this;
}
/**
* {@inheritdoc}
*/
public function getArgument() : string {
return $this->argument;
}
/**
* {@inheritdoc}
*/
public function getAttribute(string $name) : ?string {
return $this->attributes[$name] ?? NULL;
}
/**
* {@inheritdoc}
*/
public function setAttribute(string $name, string $value = NULL) : void {
$this->attributes[$name] = $value;
if ($value === NULL) {
unset($this->attributes[$name]);
}
}
/**
* {@inheritdoc}
*/
public function getAttributes() : array {
return $this->attributes;
}
/**
* {@inheritdoc}
*/
public function setAttributes(array $attributes) : void {
$this->attributes = $attributes;
}
/**
* {@inheritdoc}
*/
public function getOption() : string {
return $this->option ?? '';
}
/**
* {@inheritdoc}
*/
public function setOption(string $value) : void {
$this->option = $value;
}
/**
* {@inheritdoc}
*/
public function getSource() : string {
return $this->source;
}
/**
* {@inheritdoc}
*/
public function setSource(string $source) : void {
$this->source = $source;
}
/**
* {@inheritdoc}
*/
public function getOuterSource() : string {
// Reconstruct the opening and closing tags, but render the content.
if (!isset($this->outerSource)) {
$content = $this
->getContent();
$this->outerSource = "[{$this->openingName}{$this->argument}]{$content}[/{$this->closingName}]";
}
return $this->outerSource;
}
/**
* {@inheritdoc}
*/
public function getParent() : NodeElementInterface {
return $this->parent;
}
/**
* {@inheritdoc}
*/
public function setParent(NodeElementInterface $parent) : void {
$this->parent = $parent;
}
/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException
* If the tag does not have an assigned processor.
*/
public function render() : OutputElementInterface {
if (!$this
->getProcessor()) {
throw new \InvalidArgumentException("Missing processor for tag [{$this->name}]");
}
return $this
->getProcessor()
->process($this);
}
/**
* {@inheritdoc}
*/
public function getProcessor() : TagProcessorInterface {
return $this->processor;
}
/**
* {@inheritdoc}
*/
public function setProcessor(TagProcessorInterface $processor) : void {
$this->processor = $processor;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NodeElement:: |
protected | property | The children of this node. | |
NodeElement:: |
protected | property | The rendered children of this node. | |
NodeElement:: |
public | function |
Append an element to the children of this element. Overrides NodeElementInterface:: |
|
NodeElement:: |
public | function |
Get all children of the element. Overrides NodeElementInterface:: |
|
NodeElement:: |
public | function |
Retrieve the rendered content of the element. Overrides NodeElementInterface:: |
|
NodeElement:: |
public | function |
Retrieve the descendants of the node. Overrides NodeElementInterface:: |
|
NodeElement:: |
public | function |
Retrieve the rendered output of each child. Overrides NodeElementInterface:: |
|
TagElement:: |
private | property | The tag argument. | |
TagElement:: |
private | property | The tag attributes. | |
TagElement:: |
private | property | Closing tag name. | |
TagElement:: |
private | property | The tag name. | |
TagElement:: |
private | property | Opening tag name. | |
TagElement:: |
private | property | The tag option. | |
TagElement:: |
private | property | The tag's parent element. | |
TagElement:: |
private | property | The processor handling this element. | |
TagElement:: |
private | property | The tag content source. | |
TagElement:: |
public | function |
Retrieve the unparsed argument string. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Retrieve a particular attribute of the element. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Return all attribute values. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Get the original closing tag name. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Get the canonical (lower-case) tag name of this element. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Get the original opening tag name. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Retrieve the option-type attribute of the element. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Retrieve the content including the opening and closing tags. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Retrieve the parent of the current tag. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Get the assigned processor. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Retrieve the content source of the tag. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Overrides ElementInterface:: |
|
TagElement:: |
public | function |
Set an attribute of the element. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Set all attribute values. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Get the original closing tag name. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Set the option-style attribute of the element. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Set the parent of the current tag. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Assign a processor to this tag element. Overrides TagElementInterface:: |
|
TagElement:: |
public | function |
Set the content source of the tag. Overrides TagElementInterface:: |
|
TagElement:: |
public | function | TagElement constructor. |