Config.php
37 lines
| 1 | <?php |
| 2 | namespace NitroPack\WordPress; |
| 3 | |
| 4 | class Config { |
| 5 | private $config; |
| 6 | |
| 7 | public function __construct() { |
| 8 | $this->config = NULL; |
| 9 | } |
| 10 | |
| 11 | public function get() { |
| 12 | if ($this->config) { |
| 13 | return $this->config; |
| 14 | } |
| 15 | |
| 16 | $config = array(); |
| 17 | |
| 18 | if ($this->exists()) { |
| 19 | $config = json_decode(file_get_contents(NITROPACK_CONFIG_FILE), true); // TODO: Convert this to use the Filesystem abstraction for better Redis support |
| 20 | } |
| 21 | |
| 22 | $this->config = $config; |
| 23 | return $config; |
| 24 | } |
| 25 | |
| 26 | public function set($config) { |
| 27 | $np = NitroPack::getInstance(); |
| 28 | if (!$np->dataDirExists() && !$np->initDataDir()) return false; |
| 29 | $this->config = $config; |
| 30 | return WP_DEBUG ? file_put_contents(NITROPACK_CONFIG_FILE, json_encode($config, JSON_PRETTY_PRINT)) : @file_put_contents(NITROPACK_CONFIG_FILE, json_encode($config, JSON_PRETTY_PRINT)); // TODO: Convert this to use the Filesystem abstraction for better Redis support |
| 31 | } |
| 32 | |
| 33 | public function exists() { |
| 34 | return defined("NITROPACK_CONFIG_FILE") && file_exists(NITROPACK_CONFIG_FILE); // TODO: Convert this to use the Filesystem abstraction for better Redis support |
| 35 | } |
| 36 | } |
| 37 |