[ Index ]

PHP Cross Reference of phpBB-3.3.3-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Plugins/BBCodes/Configurator/ -> BBCode.php (source)

   1  <?php
   2  
   3  /**
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2020 The s9e authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Plugins\BBCodes\Configurator;
   9  
  10  use InvalidArgumentException;
  11  use s9e\TextFormatter\Configurator\Collections\AttributeList;
  12  use s9e\TextFormatter\Configurator\ConfigProvider;
  13  use s9e\TextFormatter\Configurator\Helpers\ConfigHelper;
  14  use s9e\TextFormatter\Configurator\JavaScript\Dictionary;
  15  use s9e\TextFormatter\Configurator\Traits\Configurable;
  16  use s9e\TextFormatter\Configurator\Validators\AttributeName;
  17  use s9e\TextFormatter\Configurator\Validators\TagName;
  18  
  19  /**
  20  * @property AttributeList $contentAttributes List of attributes whose value is to be made the content between the BBCode's tags if it's not explicitly given
  21  * @property string $defaultAttribute Name of the default attribute
  22  * @property bool $forceLookahead Whether the parser should look ahead in the text for an end tag before adding a start tag
  23  * @property string $tagName Name of the tag used to represent this BBCode in the intermediate representation
  24  */
  25  class BBCode implements ConfigProvider
  26  {
  27      use Configurable;
  28  
  29      /**
  30      * @var AttributeList List of attributes whose value is to be made the content between the
  31      *                    BBCode's tags if it's not explicitly given
  32      */
  33      protected $contentAttributes;
  34  
  35      /**
  36      * @var string Name of the default attribute
  37      */
  38      protected $defaultAttribute;
  39  
  40      /**
  41      * @var bool Whether the parser should look ahead in the text for an end tag before adding a
  42      *           start tag
  43      */
  44      protected $forceLookahead = false;
  45  
  46      /**
  47      * @var string Name of the tag used to represent this BBCode in the intermediate representation
  48      */
  49      protected $tagName;
  50  
  51      /**
  52      * @param array $options This BBCode's options
  53      */
  54  	public function __construct(array $options = null)
  55      {
  56          $this->contentAttributes = new AttributeList;
  57          if (isset($options))
  58          {
  59              foreach ($options as $optionName => $optionValue)
  60              {
  61                  $this->__set($optionName, $optionValue);
  62              }
  63          }
  64      }
  65  
  66      /**
  67      * {@inheritdoc}
  68      */
  69  	public function asConfig()
  70      {
  71          $config = ConfigHelper::toArray(get_object_vars($this));
  72          if (!$this->forceLookahead)
  73          {
  74              unset($config['forceLookahead']);
  75          }
  76  
  77          return $config;
  78      }
  79  
  80      /**
  81      * Normalize the name of a BBCode
  82      *
  83      * Follows the same rules as tag names with one exception: "*" is kept for compatibility with
  84      * other BBCode engines
  85      *
  86      * @param  string $bbcodeName Original name
  87      * @return string             Normalized name
  88      */
  89  	public static function normalizeName($bbcodeName)
  90      {
  91          if ($bbcodeName === '*')
  92          {
  93              return '*';
  94          }
  95  
  96          if (strpos($bbcodeName, ':') !== false || !TagName::isValid($bbcodeName))
  97          {
  98              throw new InvalidArgumentException("Invalid BBCode name '" . $bbcodeName . "'");
  99          }
 100  
 101          return TagName::normalize($bbcodeName);
 102      }
 103  
 104      /**
 105      * Set the default attribute name for this BBCode
 106      *
 107      * @param string $attrName
 108      */
 109  	public function setDefaultAttribute($attrName)
 110      {
 111          $this->defaultAttribute = AttributeName::normalize($attrName);
 112      }
 113  
 114      /**
 115      * Set the tag name that represents this BBCode in the intermediate representation
 116      *
 117      * @param string $tagName
 118      */
 119  	public function setTagName($tagName)
 120      {
 121          $this->tagName = TagName::normalize($tagName);
 122      }
 123  }


Generated: Sun Feb 14 20:08:31 2021 Cross-referenced by PHPXref 0.7.1