Skip to content

Commit

Permalink
Loading and saving JSON replaced by RAW
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Helldar authored Jul 10, 2020
1 parent 4d41e9b commit 55b11d8
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions src/Services/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Helldar\PrettyArray\Exceptions\FileDoesntExistsException;
use Helldar\Support\Facades\File as FileSupport;
use Helldar\Support\Facades\Str;
use Helldar\Support\Tools\Stub;

class File
Expand Down Expand Up @@ -34,43 +33,25 @@ public function load(string $filename)
throw new FileDoesntExistsException($filename);
}

return $this->isJson($filename)
? $this->loadJson($filename)
: require $filename;
return require $filename;
}

public function loadJson(string $filename)
public function loadRaw(string $filename)
{
return json_decode(file_get_contents($filename), true);
return file_get_contents($filename);
}

public function store(string $path): void
{
if ($this->isJson($path)) {
$this->storeAsJson($path);

return;
}

$content = Stub::replace(Stub::CONFIG_FILE, [
'{{slot}}' => $this->content,
]);

FileSupport::store($path, $content);
}

public function storeAsJson(string $path): void
public function storeRaw(string $path): void
{
FileSupport::store(
$path,
json_encode($this->content, JSON_PRETTY_PRINT)
);
}

public function isJson(string $filename): bool
{
$extension = pathinfo($filename, PATHINFO_EXTENSION);

return Str::lower($extension) === 'json';
FileSupport::store($path, $this->content);
}
}

0 comments on commit 55b11d8

Please sign in to comment.