Skip to content

Commit

Permalink
Added exception for invalid json file
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardosahon committed Oct 30, 2024
1 parent 3e3feda commit 13cc51f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
56 changes: 30 additions & 26 deletions src/BobDBuilder/Cmd/Traits/Make/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,35 +190,41 @@ public function update_general_domain_entry(string $domain, string $domain_id, s
);
DEF;

// Current Domain being created
preg_match(
'/Domain::new\(\)->create\([^)]*'. $domain_id .'[^)]*\);/s',
$index_page, $data
);
$current_domain = "";

// Create the new domain patterns as specified from the terminal
$pattern = "";
foreach (explode(",", $patterns) as $p) {
$pattern .= '"' . strtolower(trim($p)) . '",';
}
if($domain_id != 'default') {
// Current Domain being created
preg_match(
'/Domain::new\(\)->create\([^)]*' . $domain_id . '[^)]*\);/s',
$index_page, $data
);

$pattern = rtrim($pattern, ",");
$old_pattern = null;
// Create the new domain patterns as specified from the terminal
$pattern = "";
foreach (explode(",", $patterns) as $p) {
$pattern .= '"' . strtolower(trim($p)) . '",';
}

if(!empty($data)) {
preg_match('/"([^"]+)"/', $data[0], $old_pattern);
$old_pattern = $old_pattern[0] ?? null;
}
$pattern = rtrim($pattern, ",");
$old_pattern = null;

$pattern = $old_pattern == $pattern ? $old_pattern : $pattern;
if (!empty($data)) {
preg_match('/"([^"]+)"/', $data[0], $old_pattern);
$old_pattern = $old_pattern[0] ?? null;
}

$current_domain = <<<CUR
Domain::new()->create(
id: "$domain_id",
builder: \Web\\$domain\\Plaster::class,
patterns: [$pattern],
);
CUR;
$pattern = $old_pattern == $pattern ? $old_pattern : $pattern;

$current_domain = <<<CUR
Domain::new()->create(
id: "$domain_id",
builder: \Web\\$domain\\Plaster::class,
patterns: [$pattern],
);
CUR;
}

// Remove any duplicate from the domain entry
$index_page = trim(preg_replace(
Expand All @@ -233,9 +239,7 @@ public function update_general_domain_entry(string $domain, string $domain_id, s
$main_file,
<<<INDEX
$index_page
$current_domain
$default_domain
INDEX
);
Expand Down
3 changes: 3 additions & 0 deletions src/Libs/Symlink/LaySymlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public function refresh_link(bool $recursive = false) : void

$links = json_decode(file_get_contents($db_file), true);

if($links === null)
Exception::throw_exception("There was an error reading file: $db_file. Please open it and confirm if it's a valid JSON");

foreach ($links as $link) {
if(empty($link['src'])) {
new BobExec("link:{$link['type']} {$link['dest']} --force --silent");
Expand Down

0 comments on commit 13cc51f

Please sign in to comment.