[ 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\MediaEmbed\Configurator\Collections; 9 use InvalidArgumentException; 10 use RuntimeException; 11 use s9e\TextFormatter\Configurator\Collections\NormalizedCollection; 12 class SiteDefinitionCollection extends NormalizedCollection 13 { 14 protected $onDuplicateAction = 'replace'; 15 protected function getAlreadyExistsException($key) 16 { 17 return new RuntimeException("Media site '" . $key . "' already exists"); 18 } 19 protected function getNotExistException($key) 20 { 21 return new RuntimeException("Media site '" . $key . "' does not exist"); 22 } 23 public function normalizeKey($siteId) 24 { 25 $siteId = \strtolower($siteId); 26 if (!\preg_match('(^[a-z0-9]+$)', $siteId)) 27 throw new InvalidArgumentException('Invalid site ID'); 28 return $siteId; 29 } 30 public function normalizeValue($siteConfig) 31 { 32 if (!\is_array($siteConfig)) 33 throw new InvalidArgumentException('Invalid site definition type'); 34 if (!isset($siteConfig['host'])) 35 throw new InvalidArgumentException('Missing host from site definition'); 36 $siteConfig += ['attributes' => [], 'extract' => [], 'scrape' => []]; 37 $siteConfig['extract'] = $this->normalizeRegexp($siteConfig['extract']); 38 $siteConfig['host'] = \array_map('strtolower', (array) $siteConfig['host']); 39 $siteConfig['scrape'] = $this->normalizeScrape($siteConfig['scrape']); 40 foreach ($siteConfig['attributes'] as &$attrConfig) 41 if (isset($attrConfig['filterChain'])) 42 $attrConfig['filterChain'] = (array) $attrConfig['filterChain']; 43 unset($attrConfig); 44 return $siteConfig; 45 } 46 protected function normalizeRegexp($value) 47 { 48 return (array) $value; 49 } 50 protected function normalizeScrape($value) 51 { 52 if (!empty($value) && !isset($value[0])) 53 $value = [$value]; 54 foreach ($value as &$scrape) 55 { 56 $scrape += ['extract' => [], 'match' => '//']; 57 $scrape['extract'] = $this->normalizeRegexp($scrape['extract']); 58 $scrape['match'] = $this->normalizeRegexp($scrape['match']); 59 } 60 unset($scrape); 61 return $value; 62 } 63 }
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 |