From e5dde38f79cad1738d4a2e8bead67516db562705 Mon Sep 17 00:00:00 2001 From: AmitxD <81667979+Amitminer@users.noreply.github.com> Date: Tue, 27 Jun 2023 00:24:18 +0530 Subject: [PATCH] update LibConfig.php --- lib/LibConfig.php | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/LibConfig.php b/lib/LibConfig.php index 9c3c079..00a377c 100644 --- a/lib/LibConfig.php +++ b/lib/LibConfig.php @@ -7,27 +7,63 @@ use Symfony\Component\Yaml\Yaml; class LibConfig { - + /** + * The path to the configuration file. + * + * @var string + */ protected $file; + + /** + * The configuration data. + * + * @var array + */ protected $data; + /** + * LibConfig constructor. + * + * @param string $file The path to the configuration file. + */ public function __construct($file) { $this->file = $file; $this->data = $this->read(); } + /** + * Get a value from the configuration data. + * + * @param string $key The key to retrieve. + * @param mixed $default The default value to return if the key does not exist. + * + * @return mixed The value associated with the key, or the default value if the key does not exist. + */ public function get($key, $default = null) { return $this->data[$key] ?? $default; } + /** + * Set a value in the configuration data. + * + * @param string $key The key to set. + * @param mixed $value The value to set. + * + * @return void + */ public function set($key, $value) { $this->data[$key] = $value; $this->save(); } + /** + * Read the configuration file. + * + * @return array The parsed configuration data. + */ protected function read() { if (file_exists($this->file)) { @@ -36,6 +72,11 @@ protected function read() return []; } + /** + * Save the configuration data to the file. + * + * @return void + */ public function save() { $content = Yaml::dump($this->data);