1 | <?php |
||
28 | class JsonFile extends JsonArray |
||
29 | { |
||
30 | /** |
||
31 | * The filename. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | private $filename; |
||
36 | |||
37 | /** |
||
38 | * The name of the backup file to create when saving. |
||
39 | * |
||
40 | * @var null|string |
||
41 | */ |
||
42 | private $backupFile; |
||
43 | |||
44 | /** |
||
45 | * Create a new instance. |
||
46 | * |
||
47 | * @param string $filename The filename. |
||
48 | * |
||
49 | * @param null|string $backupFile The name of a backup file to create (if none shall be created, pass null). |
||
50 | * The default name of the backup file is the filename with a tilde (~) appended. |
||
51 | * |
||
52 | * @throws \RuntimeException When the file contents are invalid. |
||
53 | */ |
||
54 | public function __construct($filename, $backupFile = '') |
||
76 | |||
77 | /** |
||
78 | * Set a value. |
||
79 | * |
||
80 | * @param string $path The path of the value. |
||
81 | * |
||
82 | * @param mixed $value The value to set. |
||
83 | * |
||
84 | * @return JsonFile |
||
85 | */ |
||
86 | public function set($path, $value) |
||
94 | |||
95 | /** |
||
96 | * Retrieve the file name. |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | public function getFilename() |
||
104 | |||
105 | /** |
||
106 | * Copy the file contents over to the backup. |
||
107 | * |
||
108 | * @return void |
||
109 | */ |
||
110 | private function makeBackup() |
||
122 | |||
123 | /** |
||
124 | * Save the file data. |
||
125 | * |
||
126 | * @return JsonFile |
||
127 | */ |
||
128 | public function save() |
||
140 | } |
||
141 |