From 0fcbd87083686ede024bc3a022201511f29fd4b4 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 18 May 2025 23:52:22 +0200 Subject: [PATCH] Rewrite config to be seperate from path --- php/bin/snips | 2 +- php/config.php | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/php/bin/snips b/php/bin/snips index 30ab5bf..4cae2d0 100755 --- a/php/bin/snips +++ b/php/bin/snips @@ -6,7 +6,7 @@ require_once __DIR__ . '/../functions.php'; require_once __DIR__ . '/../snips.php'; require_once __DIR__ . '/../config.php'; -$config = new config('snips'); +$config = new homeConfig('snips'); $argvParser = new argvParser(['f' => 'File', 'a' => 'Api key', 's' => 'Shortcut'], ['c' => 'Command', 'id' => 'Snip id']); $parsed = $argvParser->parseArgv($argv); if ($parsed === false) { diff --git a/php/config.php b/php/config.php index 7833e91..815fb3b 100644 --- a/php/config.php +++ b/php/config.php @@ -2,12 +2,27 @@ require_once __DIR__ . '/functions.php'; -readonly class config +readonly class homeConfig extends configReader { private const CONFIG_BASE_PATH = '.config'; public function __construct( - private string $name + string $name + ) + { + parent::__construct(path( + getenv('HOME'), + self::CONFIG_BASE_PATH, + $name + )); + } +} + +readonly class configReader +{ + public function __construct( + private string $path, + private string $fileName = 'config.php', ) { $this->init(); @@ -30,17 +45,13 @@ readonly class config { return path( $this->getConfigPath(), - 'config.php' + $this->fileName ); } private function getConfigPath(): string { - return path( - getenv('HOME'), - self::CONFIG_BASE_PATH, - $this->name - ); + return $this->path; } private function init(): void