[ Index ]

PHP Cross Reference of phpBB-3.3.11-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Configurator/RendererGenerators/PHP/XPathConvertor/Convertors/ -> BooleanFunctions.php (source)

   1  <?php
   2  
   3  /**
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2022 The s9e authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Configurator\RendererGenerators\PHP\XPathConvertor\Convertors;
   9  
  10  class BooleanFunctions extends AbstractConvertor
  11  {
  12      /**
  13      * {@inheritdoc}
  14      */
  15  	public function getMatchers(): array
  16      {
  17          $groups = 'Boolean:BooleanFunction:';
  18  
  19          return [
  20              $groups . 'BooleanParam'  => 'boolean \\( ((?&Parameter)) \\)',
  21              $groups . 'False'         => 'false \\( \\)',
  22              $groups . 'HasAttribute'  => 'boolean \\( ((?&Attribute)) \\)',
  23              $groups . 'HasAttributes' => 'boolean \\( @\\* \\)',
  24              $groups . 'Not'           => [
  25                  // Only try matching generic not() invocations after special cases fail
  26                  'order'  => 100,
  27                  'regexp' => 'not \\( ((?&Boolean)|(?&BooleanExpression)) \\)'
  28              ],
  29              $groups . 'NotAttribute'  => 'not \\( ((?&Attribute)) \\)',
  30              $groups . 'NotParam'      => 'not \\( ((?&Parameter)) \\)',
  31              $groups . 'True'          => 'true \\( \\)'
  32          ];
  33      }
  34  
  35      /**
  36      * Convert a call to boolean() with a param
  37      *
  38      * @param  string $expr
  39      * @return string
  40      */
  41  	public function parseBooleanParam($expr)
  42      {
  43          return $this->recurse($expr) . "!==''";
  44      }
  45  
  46      /**
  47      * Convert a call to false()
  48      *
  49      * @return string
  50      */
  51  	public function parseFalse()
  52      {
  53          return 'false';
  54      }
  55  
  56      /**
  57      * Convert a call to boolean() with an attribute
  58      *
  59      * @param  string $expr
  60      * @return string
  61      */
  62  	public function parseHasAttribute($expr)
  63      {
  64          $attrName = $this->getAttributeName($expr);
  65  
  66          return '$node->hasAttribute(' . var_export($attrName, true) . ')';
  67      }
  68  
  69      /**
  70      * Convert a call to boolean(@*)
  71      *
  72      * @return string
  73      */
  74  	public function parseHasAttributes()
  75      {
  76          return '$node->attributes->length';
  77      }
  78  
  79      /**
  80      * Convert a call to not() with a boolean expression
  81      *
  82      * @param  string $expr
  83      * @return string
  84      */
  85  	public function parseNot($expr)
  86      {
  87          return '!(' . $this->recurse($expr) . ')';
  88      }
  89  
  90      /**
  91      * Convert a call to not() with an attribute
  92      *
  93      * @param  string $expr
  94      * @return string
  95      */
  96  	public function parseNotAttribute($expr)
  97      {
  98          $attrName = $this->getAttributeName($expr);
  99  
 100          return '!$node->hasAttribute(' . var_export($attrName, true) . ')';
 101      }
 102  
 103      /**
 104      * Convert a call to not() with a param
 105      *
 106      * @param  string $expr
 107      * @return string
 108      */
 109  	public function parseNotParam($expr)
 110      {
 111          return $this->recurse($expr) . "===''";
 112      }
 113  
 114      /**
 115      * Convert a call to true()
 116      *
 117      * @return string
 118      */
 119  	public function parseTrue()
 120      {
 121          return 'true';
 122      }
 123  }


Generated: Sat Nov 4 14:26:03 2023 Cross-referenced by PHPXref 0.7.1