@@ -19,7 +19,7 @@ Biblioteca PHP para la gestión de archivos JSON.
1919- [ Instalación] ( #instalación )
2020- [ Clases disponibles] ( #clases-disponibles )
2121 - [ Clase Json] ( #clase-json )
22- - [ Excepciones usadas ] ( #excepciones-usadas )
22+ - [ Excepciones utilizadas ] ( #excepciones-utilizadas )
2323- [ Uso] ( #uso )
2424- [ Tests] ( #tests )
2525- [ Tareas pendientes] ( #tareas-pendientes )
@@ -61,60 +61,65 @@ git clone https://github.com/josantonius/php-json.git
6161
6262### Clase Json
6363
64+ ` Josantonius\Json\Json `
65+
66+ Comprueba si existe un archivo local o remoto.
67+
6468``` php
65- use Josantonius\Json\Json ;
69+ public function exists(): bool ;
6670```
6771
6872Obtener el contenido del archivo JSON:
6973
7074``` php
7175/**
72- * @throws CreateDirectoryException if there is an error when creating a directory.
73- * @throws CreateFileException if there is an error when creating a file.
74- * @throws JsonErrorException if there is an error when parsing a JSON file.
76+ * @throws GetFileException if there is an error when getting a file.
77+ * @throws JsonErrorException if there is an error when parsing a JSON file.
7578 */
76- $json->get(): array
79+ public function get(): array;
80+ ```
81+
82+ Obtiene la ruta o URL del archivo JSON.
83+
84+ ``` php
85+ public function getFilepath(): string;
7786```
7887
7988Establecer el contenido del archivo JSON:
8089
8190``` php
8291/**
8392 * @throws CreateFileException if there is an error when creating a file.
84- * @throws JsonErrorException if there is an error when parsing a JSON file.
8593 * @throws UnavailableMethodException if the method is not available.
8694 */
87- $json-> set(array|object $content): void
95+ public function set(array|object $content = [] ): void;
8896```
8997
9098Fusionar en el archivo JSON:
9199
92100``` php
93101/**
94- * @throws CreateFileException if there is an error when creating a file.
95102 * @throws GetFileException if there is an error when getting a file.
96103 * @throws JsonErrorException if there is an error when parsing a JSON file.
97104 * @throws UnavailableMethodException if the method is not available.
98105 */
99- $json-> merge(array|object $content): array
106+ public function merge(array|object $content): array;
100107```
101108
102109Incluir en el archivo JSON:
103110
104111``` php
105112/**
106- * @throws CreateFileException if there is an error when creating a file.
107113 * @throws GetFileException if there is an error when getting a file.
108114 * @throws JsonErrorException if there is an error when parsing a JSON file.
109115 * @throws UnavailableMethodException if the method is not available.
110116 */
111- $json-> push(array|object $content): array
117+ public function push(array|object $content): array;
112118```
113119
114120## Excepciones utilizadas
115121
116122``` php
117- use Josantonius\Json\Exceptions\CreateDirectoryException;
118123use Josantonius\Json\Exceptions\CreateFileException;
119124use Josantonius\Json\Exceptions\GetFileException;
120125use Josantonius\Json\Exceptions\JsonErrorException;
@@ -125,6 +130,30 @@ use Josantonius\Json\Exceptions\UnavailableMethodException;
125130
126131Ejemplo de uso para esta biblioteca:
127132
133+ ### Comprueba si existe un archivo local
134+
135+ ** ` index.php ` **
136+
137+ ``` php
138+ use Josantonius\Json\Json;
139+
140+ $json = new Json('file.json');
141+
142+ $json->exists(); // bool
143+ ```
144+
145+ ### Comprueba si existe un archivo remoto
146+
147+ ** ` index.php ` **
148+
149+ ``` php
150+ use Josantonius\Json\Json;
151+
152+ $json = new Json('https://example.com/file.json');
153+
154+ $json->exists(); // bool
155+ ```
156+
128157### Obtener el contenido del archivo
129158
130159** ` file.json ` **
@@ -145,6 +174,68 @@ $json = new Json('file.json');
145174$json->get(); // ['foo' => 'bar']
146175```
147176
177+ ### Obtener el contenido del archivo desde una URL
178+
179+ ** ` https://example.com/file.json ` **
180+
181+ ``` json
182+ {
183+ "foo" : " bar"
184+ }
185+ ```
186+
187+ ** ` index.php ` **
188+
189+ ``` php
190+ use Josantonius\Json\Json;
191+
192+ $json = new Json('https://example.com/file.json');
193+
194+ $json->get(); // ['foo' => 'bar']
195+ ```
196+
197+ ### Obtiene la ruta del archivo JSON
198+
199+ ** ` index.php ` **
200+
201+ ``` php
202+ use Josantonius\Json\Json;
203+
204+ $json = new Json('file.json');
205+
206+ $json->getFilepath(); // 'file.json'
207+ ```
208+
209+ ### Obtiene la URL del archivo JSON remoto
210+
211+ ** ` index.php ` **
212+
213+ ``` php
214+ use Josantonius\Json\Json;
215+
216+ $json = new Json('https://example.com/file.json');
217+
218+ $json->getFilepath(); // 'https://example.com/file.json'
219+ ```
220+
221+ ### Establecer una matriz vacía en el contenido del archivo JSON
222+
223+ ** ` index.php ` **
224+
225+ ``` php
226+ use Josantonius\Json\Json;
227+
228+ $json = new Json('file.json');
229+
230+ $json->set();
231+ ```
232+
233+ ** ` file.json ` **
234+
235+ ``` json
236+ []
237+ ```
238+
148239### Establecer el contenido del archivo
149240
150241** ` index.php ` **
0 commit comments