You are here

TagProcessorBase.php in Extensible BBCode 4.0.x

Same filename and directory in other branches
  1. 8.3 src/Parser/Processor/TagProcessorBase.php

File

src/Parser/Processor/TagProcessorBase.php
View source
<?php

namespace Drupal\xbbcode\Parser\Processor;

use Drupal\xbbcode\Parser\Tree\OutputElement;
use Drupal\xbbcode\Parser\Tree\OutputElementInterface;
use Drupal\xbbcode\Parser\Tree\TagElementInterface;

/**
 * Base tag processor for wrapping the output.
 *
 * @package Drupal\xbbcode\Parser
 */
abstract class TagProcessorBase implements TagProcessorInterface {

  /**
   * {@inheritdoc}
   */
  public function process(TagElementInterface $tag) : OutputElementInterface {
    $output = $this
      ->doProcess($tag);
    if (!$output instanceof OutputElementInterface) {
      $output = new OutputElement((string) $output);
    }
    return $output;
  }

  /**
   * Override this function to return any printable value.
   *
   * @param \Drupal\xbbcode\Parser\Tree\TagElementInterface $tag
   *   Tag element in the parse tree.
   *
   * @return mixed
   *   Any value that can be cast to string.
   */
  public abstract function doProcess(TagElementInterface $tag);

}

Classes

Namesort descending Description
TagProcessorBase Base tag processor for wrapping the output.