1<?php 2 3/** 4 * Class ConfigManagerAbstractCascadeConfig 5 */ 6abstract class ConfigManagerAbstractCascadeConfig implements ConfigManagerConfigType { 7 private $name; 8 protected $internalName; 9 private $description; 10 private $path; 11 12 /** 13 * @var helper_plugin_confmanager 14 */ 15 protected $helper; 16 17 /** 18 * Load file 19 * 20 * @param string $fileName 21 * @return mixed 22 */ 23 abstract protected function loadFile($fileName); 24 25 /** 26 * @param string $name 27 */ 28 public function __construct($name) { 29 $this->internalName = $name; 30 $this->path = getConfigFiles($name); 31 $this->helper = plugin_load('helper', 'confmanager'); 32 } 33 34 /** 35 * Load configs files for all types 36 * 37 * @return array[] 38 */ 39 protected function readConfig() { 40 global $config_cascade; 41 $config = []; 42 43 foreach (['default', 'local', 'protected'] as $type) { 44 $config[$type] = []; 45 46 if (!isset($config_cascade[$this->internalName][$type])) { 47 continue; 48 } 49 50 foreach ($config_cascade[$this->internalName][$type] as $file) { 51 $config[$type] = array_merge($config[$type], $this->loadFile($file)); 52 } 53 } 54 55 return $config; 56 } 57 58 /** 59 * Prepare entity for saving 60 * 61 * @param string $str 62 * @return string 63 */ 64 protected function prepareEntity($str) { 65 return $this->helper->prepareEntity($str); 66 } 67 68 /** 69 * Get localized name 70 * @return string 71 */ 72 public function getName() { 73 return $this->name; 74 } 75 76 /** 77 * Set localized name 78 * 79 * @param string $name 80 */ 81 public function setName($name) { 82 $this->name = $name; 83 } 84 85 /** 86 * Get localized description 87 * 88 * @return string localized wikitext 89 */ 90 public function getDescription() { 91 return $this->description; 92 } 93 94 /** 95 * Set localized description 96 * 97 * @param string $description localized wikitext 98 */ 99 public function setDescription($description) { 100 $this->description = $description; 101 } 102 103 /** 104 * get all paths to config file (local or protected). 105 * this is used to generate the config id and warnings if the files are not writeable. 106 * 107 * @return array 108 */ 109 public function getPaths() { 110 return $this->path; 111 } 112} 113