Skip to content

Commit 2fd17bb

Browse files
committed
refactor: Removal of JSON_CONFIG_FILE_PATH
1 parent 7f853fd commit 2fd17bb

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

tests/webfiori/framework/test/config/JsonDriverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ public function testAppNames01() {
105105
'AR' => 'تطبيق',
106106
'EN' => 'Cool App'
107107
],$driver->getAppNames());
108-
$this->assertTrue(File::isFileExist(JsonDriver::JSON_CONFIG_FILE_PATH.DS.$driver->getConfigFileName().'.json'));
108+
$this->assertTrue(File::isFileExist(JsonDriver::getConfigPath().DS.$driver->getConfigFileName().'.json'));
109109
$driver->remove();
110-
$this->assertFalse(File::isFileExist(JsonDriver::JSON_CONFIG_FILE_PATH.DS.$driver->getConfigFileName().'.json'));
110+
$this->assertFalse(File::isFileExist(JsonDriver::getConfigPath().DS.$driver->getConfigFileName().'.json'));
111111
}
112112
/**
113113
* @test

webfiori/framework/config/JsonDriver.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
* @author Ibrahim
2020
*/
2121
class JsonDriver implements ConfigurationDriver {
22+
2223
/**
23-
* The location at which the configuration file will be kept at.
24-
*
25-
* @var string The file will be stored at [APP_PATH]/config/';
24+
* Returns the path to JSON configuration files.
2625
*/
27-
const JSON_CONFIG_FILE_PATH = APP_PATH.'config'.DIRECTORY_SEPARATOR;
26+
private static function getConfigPath(): string {
27+
return APP_PATH.'config'.DIRECTORY_SEPARATOR;
28+
}
2829
/**
2930
* The name of JSON configuration file.
3031
*/
@@ -466,7 +467,7 @@ public function getTitleSeparator(): string {
466467
* file with same name, it will be overriden.
467468
*/
468469
public function initialize(bool $reCreate = false) {
469-
$path = self::JSON_CONFIG_FILE_PATH.self::getConfigFileName().'.json';
470+
$path = self::getConfigPath().self::getConfigFileName().'.json';
470471

471472
if (!file_exists($path) || $reCreate) {
472473
$this->writeJson();
@@ -480,7 +481,7 @@ public function initialize(bool $reCreate = false) {
480481
* be set using the method JsonDriver::setConfigFileName()
481482
*/
482483
public function remove() {
483-
$f = new File(self::JSON_CONFIG_FILE_PATH.DIRECTORY_SEPARATOR.self::getConfigFileName().'.json');
484+
$f = new File(self::getConfigPath().self::getConfigFileName().'.json');
484485
$f->remove();
485486
}
486487
public function removeAllDBConnections() {
@@ -746,7 +747,7 @@ private function isValidLangCode($langCode) {
746747
return $code;
747748
}
748749
private function writeJson() {
749-
$file = new File(self::JSON_CONFIG_FILE_PATH.self::getConfigFileName().'.json');
750+
$file = new File(self::getConfigPath().self::getConfigFileName().'.json');
750751
$file->remove();
751752
$json = $this->toJSON();
752753
$json->setIsFormatted(true);

0 commit comments

Comments
 (0)