-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e402f99
commit f0e993d
Showing
10 changed files
with
129 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ | |
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"JG\\Config\\": "tests/" | ||
"JG\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace JG\Tests; | ||
|
||
use JG\Config\Parsers\ParserInterface; | ||
use JG\Config\Exceptions\ConfigParseException; | ||
|
||
class CustomParser implements ParserInterface | ||
{ | ||
/** | ||
* Parses a custom configuration file into an associative array. | ||
* | ||
* @param string $filePath Path to the custom configuration file. | ||
* @return array Parsed configuration data as an associative array. | ||
* @throws ConfigParseException If the file cannot be read or parsed. | ||
*/ | ||
public function parse(string $filePath): array | ||
{ | ||
if (!is_file($filePath) || !is_readable($filePath)) { | ||
throw new ConfigParseException("File not found or unreadable: {$filePath}"); | ||
} | ||
|
||
$data = file_get_contents($filePath); | ||
if ($data === false) { | ||
throw new ConfigParseException("Failed to read the custom configuration file: {$filePath}"); | ||
} | ||
|
||
$lines = explode(PHP_EOL, $data); | ||
$output = []; | ||
|
||
foreach ($lines as $line) { | ||
$line = trim($line); | ||
|
||
if (empty($line) || str_starts_with($line, '#')) { | ||
continue; // Skip empty lines or comments | ||
} | ||
|
||
if (!str_contains($line, '->')) { | ||
throw new ConfigParseException("Invalid line format in file {$filePath}: {$line}"); | ||
} | ||
|
||
[$key, $value] = array_map('trim', explode('->', $line, 2)); | ||
$output[$key] = $value; | ||
} | ||
return $output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
key1 -> value1 | ||
key2 -> value2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
��� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"key":"value"} |