Notifications
2 months ago
Settings
2 months ago
Admin.php
2 months ago
CLI.php
6 months ago
Config.php
1 year ago
ConflictingPlugins.php
10 months ago
Cron.php
1 year ago
Invalidations.php
2 months ago
NitroPack.php
4 months ago
Settings.php
4 months ago
Config.php
48 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 = []; |
| 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 | if (!empty($config['config_path']) && $config['config_path'] != md5(NITROPACK_PLUGIN_DATA_DIR)) { |
| 21 | $config = []; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | $this->config = $config; |
| 26 | return $config; |
| 27 | } |
| 28 | |
| 29 | public function set($config) { |
| 30 | $np = NitroPack::getInstance(); |
| 31 | if (!$np->pluginDataDirExists() && !$np->initPluginDataDir()) return false; |
| 32 | $config['config_path'] = md5(NITROPACK_PLUGIN_DATA_DIR); |
| 33 | $this->config = $config; |
| 34 | 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 |
| 35 | } |
| 36 | |
| 37 | // Used when changing the location of the data dir |
| 38 | public function updateConfigPath() { |
| 39 | $config = json_decode(file_get_contents(NITROPACK_CONFIG_FILE), true); // TODO: Convert this to use the Filesystem abstraction for better Redis support |
| 40 | $config['config_path'] = md5(NITROPACK_PLUGIN_DATA_DIR); |
| 41 | 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 |
| 42 | } |
| 43 | |
| 44 | public function exists() { |
| 45 | return defined("NITROPACK_CONFIG_FILE") && file_exists(NITROPACK_CONFIG_FILE); // TODO: Convert this to use the Filesystem abstraction for better Redis support |
| 46 | } |
| 47 | } |
| 48 |