2023-12-31 20:56:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare (strict_types=1);
|
2024-01-02 02:40:38 +00:00
|
|
|
namespace Rector\FileSystem;
|
2023-12-31 20:56:31 +00:00
|
|
|
|
2024-04-01 16:51:34 +00:00
|
|
|
use RectorPrefix202404\Nette\Utils\FileSystem;
|
|
|
|
use RectorPrefix202404\Nette\Utils\Json;
|
2023-12-31 20:56:31 +00:00
|
|
|
final class JsonFileSystem
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public static function readFilePath(string $filePath) : array
|
|
|
|
{
|
|
|
|
$fileContents = FileSystem::read($filePath);
|
2024-04-09 20:37:51 +00:00
|
|
|
return Json::decode($fileContents, \true);
|
2023-12-31 20:56:31 +00:00
|
|
|
}
|
2024-01-25 00:06:40 +00:00
|
|
|
/**
|
|
|
|
* @param array<string, mixed> $data
|
|
|
|
*/
|
|
|
|
public static function writeFile(string $filePath, array $data) : void
|
|
|
|
{
|
2024-04-09 20:37:51 +00:00
|
|
|
$json = Json::encode($data, \true);
|
2024-01-28 22:41:37 +00:00
|
|
|
FileSystem::write($filePath, $json, null);
|
2024-01-25 00:06:40 +00:00
|
|
|
}
|
2023-12-31 20:56:31 +00:00
|
|
|
}
|