[ 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\Plugins; 9 use InvalidArgumentException; 10 use RuntimeException; 11 use s9e\TextFormatter\Configurator; 12 use s9e\TextFormatter\Configurator\ConfigProvider; 13 use s9e\TextFormatter\Configurator\Helpers\ConfigHelper; 14 use s9e\TextFormatter\Configurator\JavaScript\Code; 15 use s9e\TextFormatter\Configurator\Validators\AttributeName; 16 use s9e\TextFormatter\Configurator\Validators\TagName; 17 abstract class ConfiguratorBase implements ConfigProvider 18 { 19 protected $configurator; 20 protected $quickMatch = \false; 21 protected $regexpLimit = 50000; 22 final public function __construct(Configurator $configurator, array $overrideProps = []) 23 { 24 $this->configurator = $configurator; 25 foreach ($overrideProps as $k => $v) 26 { 27 $methodName = 'set' . \ucfirst($k); 28 if (\method_exists($this, $methodName)) 29 $this->$methodName($v); 30 elseif (\property_exists($this, $k)) 31 $this->$k = $v; 32 else 33 throw new RuntimeException("Unknown property '" . $k . "'"); 34 } 35 $this->setUp(); 36 } 37 protected function setUp() 38 { 39 } 40 public function finalize() 41 { 42 } 43 public function asConfig() 44 { 45 $properties = \get_object_vars($this); 46 unset($properties['configurator']); 47 return ConfigHelper::toArray($properties); 48 } 49 final public function getBaseProperties() 50 { 51 $config = [ 52 'className' => \preg_replace('/Configurator$/', 'Parser', \get_class($this)), 53 'quickMatch' => $this->quickMatch, 54 'regexpLimit' => $this->regexpLimit 55 ]; 56 $js = $this->getJSParser(); 57 if (isset($js)) 58 $config['js'] = new Code($js); 59 return $config; 60 } 61 public function getJSHints() 62 { 63 return []; 64 } 65 public function getJSParser() 66 { 67 $className = \get_class($this); 68 if (\strpos($className, 's9e\\TextFormatter\\Plugins\\') === 0) 69 { 70 $p = \explode('\\', $className); 71 $pluginName = $p[3]; 72 $filepath = __DIR__ . '/' . $pluginName . '/Parser.js'; 73 if (\file_exists($filepath)) 74 return \file_get_contents($filepath); 75 } 76 return \null; 77 } 78 public function getTag() 79 { 80 if (!isset($this->tagName)) 81 throw new RuntimeException('No tag associated with this plugin'); 82 return $this->configurator->tags[$this->tagName]; 83 } 84 public function disableQuickMatch() 85 { 86 $this->quickMatch = \false; 87 } 88 protected function setAttrName($attrName) 89 { 90 if (!\property_exists($this, 'attrName')) 91 throw new RuntimeException("Unknown property 'attrName'"); 92 $this->attrName = AttributeName::normalize($attrName); 93 } 94 public function setQuickMatch($quickMatch) 95 { 96 if (!\is_string($quickMatch)) 97 throw new InvalidArgumentException('quickMatch must be a string'); 98 $this->quickMatch = $quickMatch; 99 } 100 public function setRegexpLimit($limit) 101 { 102 $limit = (int) $limit; 103 if ($limit < 1) 104 throw new InvalidArgumentException('regexpLimit must be a number greater than 0'); 105 $this->regexpLimit = $limit; 106 } 107 protected function setTagName($tagName) 108 { 109 if (!\property_exists($this, 'tagName')) 110 throw new RuntimeException("Unknown property 'tagName'"); 111 $this->tagName = TagName::normalize($tagName); 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 |