[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
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\Plugins\MediaEmbed\Configurator\Collections; 9 10 use InvalidArgumentException; 11 use RuntimeException; 12 use s9e\TextFormatter\Configurator\Collections\NormalizedCollection; 13 14 class SiteDefinitionCollection extends NormalizedCollection 15 { 16 /** 17 * {@inheritdoc} 18 */ 19 protected $onDuplicateAction = 'replace'; 20 21 /** 22 * {@inheritdoc} 23 */ 24 protected function getAlreadyExistsException($key) 25 { 26 return new RuntimeException("Media site '" . $key . "' already exists"); 27 } 28 29 /** 30 * {@inheritdoc} 31 */ 32 protected function getNotExistException($key) 33 { 34 return new RuntimeException("Media site '" . $key . "' does not exist"); 35 } 36 37 /** 38 * Validate and normalize a site ID 39 * 40 * @param string $siteId 41 * @return string 42 */ 43 public function normalizeKey($siteId) 44 { 45 $siteId = strtolower($siteId); 46 if (!preg_match('(^[a-z0-9]+$)', $siteId)) 47 { 48 throw new InvalidArgumentException('Invalid site ID'); 49 } 50 51 return $siteId; 52 } 53 54 /** 55 * {@inheritdoc} 56 */ 57 public function normalizeValue($siteConfig) 58 { 59 if (!is_array($siteConfig)) 60 { 61 throw new InvalidArgumentException('Invalid site definition type'); 62 } 63 if (!isset($siteConfig['host'])) 64 { 65 throw new InvalidArgumentException('Missing host from site definition'); 66 } 67 68 $siteConfig += ['attributes' => [], 'extract' => [], 'scrape' => []]; 69 $siteConfig['extract'] = $this->normalizeRegexp($siteConfig['extract']); 70 $siteConfig['host'] = array_map('strtolower', (array) $siteConfig['host']); 71 $siteConfig['scrape'] = $this->normalizeScrape($siteConfig['scrape']); 72 73 foreach ($siteConfig['attributes'] as &$attrConfig) 74 { 75 if (isset($attrConfig['filterChain'])) 76 { 77 $attrConfig['filterChain'] = (array) $attrConfig['filterChain']; 78 } 79 } 80 unset($attrConfig); 81 82 return $siteConfig; 83 } 84 85 /** 86 * Normalize a regexp / indexed array of regexps 87 * 88 * @param array|string $value 89 * @return array 90 */ 91 protected function normalizeRegexp($value) 92 { 93 return (array) $value; 94 } 95 96 /** 97 * Normalize the "scrape" value 98 * 99 * @param array $value 100 * @return array 101 */ 102 protected function normalizeScrape($value) 103 { 104 if (!empty($value) && !isset($value[0])) 105 { 106 $value = [$value]; 107 } 108 foreach ($value as &$scrape) 109 { 110 $scrape += ['extract' => [], 'match' => '//']; 111 $scrape['extract'] = $this->normalizeRegexp($scrape['extract']); 112 $scrape['match'] = $this->normalizeRegexp($scrape['match']); 113 } 114 unset($scrape); 115 116 return $value; 117 } 118 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |