CdataStrategy.php
8 years ago
CdataStrategyAlways.php
8 years ago
CdataStrategyFactory.php
9 years ago
CdataStrategyIllegalCharacters.php
8 years ago
CdataStrategyIllegalCharactersHtmlEntities.php
8 years ago
CdataStrategyNever.php
8 years ago
XMLWriter.php
8 years ago
chunk.php
5 years ago
config.php
7 years ago
download.php
6 years ago
handler.php
10 years ago
helper.php
12 years ago
input.php
7 years ago
installer.php
9 years ago
session.php
10 years ago
wpallimport.php
4 years ago
zip.php
10 years ago
config.php
99 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class to load config files |
| 5 | * |
| 6 | * @author Pavel Kulbakin <p.kulbakin@gmail.com> |
| 7 | */ |
| 8 | class PMXE_Config implements IteratorAggregate { |
| 9 | |
| 10 | /** |
| 11 | * Config variables stored |
| 12 | * @var array |
| 13 | */ |
| 14 | protected $config = array(); |
| 15 | |
| 16 | /** |
| 17 | * List of loaded files in order to avoid loading same file several times |
| 18 | * @var array |
| 19 | */ |
| 20 | protected $loaded = array(); |
| 21 | |
| 22 | /** |
| 23 | * Static method to create config instance from file on disc |
| 24 | * @param string $filePath |
| 25 | * @param string[optional] $section |
| 26 | * @return PMXE_Config |
| 27 | */ |
| 28 | public static function createFromFile($filePath, $section = NULL) { |
| 29 | $config = new self(); |
| 30 | return $config->loadFromFile($filePath, $section); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Load config file |
| 35 | * @param string $filePath |
| 36 | * @param string [optional] $section |
| 37 | * @return PMXE_Config |
| 38 | */ |
| 39 | public function loadFromFile($filePath, $section = NULL) |
| 40 | { |
| 41 | if (!is_null($section)) { |
| 42 | $this->config[$section] = self::createFromFile($filePath); |
| 43 | } else { |
| 44 | $filePath = realpath($filePath); |
| 45 | if ($filePath and !in_array($filePath, $this->loaded)) { |
| 46 | |
| 47 | require $filePath; |
| 48 | |
| 49 | if (!isset($config)) { |
| 50 | $config = array(); |
| 51 | } |
| 52 | } |
| 53 | $this->loaded[] = $filePath; |
| 54 | $this->config = array_merge($this->config, $config); |
| 55 | } |
| 56 | return $this; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Return value of setting with specified name |
| 61 | * @param string $field Setting name |
| 62 | * @param string[optional] $section Section name to look setting in |
| 63 | * @return mixed |
| 64 | */ |
| 65 | public function get($field, $section = NULL) { |
| 66 | return ! is_null($section) ? $this->config[$section]->get($field) : $this->config[$field]; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Magic method for checking whether some config option are set |
| 71 | * @param string $field |
| 72 | * @return bool |
| 73 | */ |
| 74 | public function __isset($field) { |
| 75 | return isset($this->config[$field]); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Magic method to implement object-like access to config parameters |
| 80 | * @param string $field |
| 81 | * @return mixed |
| 82 | */ |
| 83 | public function __get($field) { |
| 84 | return $this->config[$field]; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Return all config options as array |
| 89 | * @return array |
| 90 | */ |
| 91 | public function toArray($section = NULL) { |
| 92 | return ! is_null($section) ? $this->config[$section]->toArray() : $this->config; |
| 93 | } |
| 94 | |
| 95 | public function getIterator() { |
| 96 | return new ArrayIterator($this->config); |
| 97 | } |
| 98 | |
| 99 | } |