[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * @package s9e\TextFormatter 5 * @copyright Copyright (c) 2010-2019 The s9e Authors 6 * @license http://www.opensource.org/licenses/mit-license.php The MIT License 7 */ 8 namespace s9e\TextFormatter\Parser; 9 use s9e\TextFormatter\Parser; 10 use s9e\TextFormatter\Parser\Logger; 11 use s9e\TextFormatter\Parser\Tag; 12 class FilterProcessing 13 { 14 public static function executeAttributePreprocessors(Tag $tag, array $tagConfig) 15 { 16 if (empty($tagConfig['attributePreprocessors'])) 17 return; 18 foreach ($tagConfig['attributePreprocessors'] as $_c5fdeb05) 19 { 20 list($attrName, $regexp, $map) = $_c5fdeb05; 21 if ($tag->hasAttribute($attrName)) 22 self::executeAttributePreprocessor($tag, $attrName, $regexp, $map); 23 } 24 } 25 public static function filterAttributes(Tag $tag, array $tagConfig, array $registeredVars, Logger $logger) 26 { 27 $attributes = []; 28 foreach ($tagConfig['attributes'] as $attrName => $attrConfig) 29 { 30 $attrValue = \false; 31 if ($tag->hasAttribute($attrName)) 32 { 33 $vars = [ 34 'attrName' => $attrName, 35 'attrValue' => $tag->getAttribute($attrName), 36 'logger' => $logger, 37 'registeredVars' => $registeredVars 38 ]; 39 $attrValue = self::executeAttributeFilterChain($attrConfig['filterChain'], $vars); 40 } 41 if ($attrValue !== \false) 42 $attributes[$attrName] = $attrValue; 43 elseif (isset($attrConfig['defaultValue'])) 44 $attributes[$attrName] = $attrConfig['defaultValue']; 45 elseif (!empty($attrConfig['required'])) 46 $tag->invalidate(); 47 } 48 $tag->setAttributes($attributes); 49 } 50 public static function filterTag(Tag $tag, Parser $parser, array $tagsConfig, array $openTags) 51 { 52 $tagName = $tag->getName(); 53 $tagConfig = $tagsConfig[$tagName]; 54 $logger = $parser->getLogger(); 55 $logger->setTag($tag); 56 $vars = [ 57 'logger' => $logger, 58 'openTags' => $openTags, 59 'parser' => $parser, 60 'registeredVars' => $parser->registeredVars, 61 'tag' => $tag, 62 'tagConfig' => $tagConfig, 63 'text' => $parser->getText() 64 ]; 65 foreach ($tagConfig['filterChain'] as $filter) 66 { 67 if ($tag->isInvalid()) 68 break; 69 self::executeFilter($filter, $vars); 70 } 71 $logger->unsetTag(); 72 } 73 protected static function executeAttributeFilterChain(array $filterChain, array $vars) 74 { 75 $vars['logger']->setAttribute($vars['attrName']); 76 foreach ($filterChain as $filter) 77 { 78 $vars['attrValue'] = self::executeFilter($filter, $vars); 79 if ($vars['attrValue'] === \false) 80 break; 81 } 82 $vars['logger']->unsetAttribute(); 83 return $vars['attrValue']; 84 } 85 protected static function executeAttributePreprocessor(Tag $tag, $attrName, $regexp, $map) 86 { 87 $attrValue = $tag->getAttribute($attrName); 88 $captures = self::getNamedCaptures($attrValue, $regexp, $map); 89 foreach ($captures as $k => $v) 90 if ($k === $attrName || !$tag->hasAttribute($k)) 91 $tag->setAttribute($k, $v); 92 } 93 protected static function executeFilter(array $filter, array $vars) 94 { 95 $vars += ['registeredVars' => []]; 96 $vars += $vars['registeredVars']; 97 $args = []; 98 if (isset($filter['params'])) 99 foreach ($filter['params'] as $k => $v) 100 $args[] = (isset($vars[$k])) ? $vars[$k] : $v; 101 return \call_user_func_array($filter['callback'], $args); 102 } 103 protected static function getNamedCaptures($str, $regexp, $map) 104 { 105 if (!\preg_match($regexp, $str, $m)) 106 return []; 107 $values = []; 108 foreach ($map as $i => $k) 109 if (isset($m[$i]) && $m[$i] !== '') 110 $values[$k] = $m[$i]; 111 return $values; 112 } 113 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |