Skip to content

Commit 2853704

Browse files
authored
Merge pull request #22 from josantonius/release/v2.0.6
Release/v2.0.6
2 parents 867025b + 6678011 commit 2853704

File tree

13 files changed

+449
-191
lines changed

13 files changed

+449
-191
lines changed

.github/lang/es-ES/README.md

Lines changed: 104 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6872
Obtener 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

7988
Establecer 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

9098
Fusionar 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

102109
Incluir 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;
118123
use Josantonius\Json\Exceptions\CreateFileException;
119124
use Josantonius\Json\Exceptions\GetFileException;
120125
use Josantonius\Json\Exceptions\JsonErrorException;
@@ -125,6 +130,30 @@ use Josantonius\Json\Exceptions\UnavailableMethodException;
125130

126131
Ejemplo 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`**

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
# CHANGELOG
22

3+
## [v2.0.6](https://github.com/josantonius/php-json/releases/tag/v2.0.6) (2022-09-05)
4+
5+
### Added
6+
7+
* `Josantonius\Json\Json->getFilepath()` method.
8+
* `Josantonius\Json\Json->exists()` method.
9+
10+
### Changed
11+
12+
* The file is no longer created if it does not exist when the instance is created.
13+
* The `$content` parameter of the `set` method is now optional and contains an empty array by default.
14+
15+
### Deleted
16+
17+
* `Josantonius\Json\Exceptions\CreateDirectoryException` class.
18+
* `Josantonius\Json\Tests\ExistsMethodTest` class.
19+
* `Josantonius\Json\Tests\GetFilepathMethodTest` class.
20+
* `Josantonius\Json\Json->createFileIfNotExists()` method.
21+
22+
### Refactor
23+
24+
* The notation type in the test function names has been changed from camel to snake case for readability.
25+
* Functions were added to document the methods and avoid confusion.
26+
* Disabled the ´CamelCaseMethodName´ rule in ´phpmd.xml´ to avoid warnings about function names in tests.
27+
* The alignment of the asterisks in the comments has been fixed.
28+
29+
### Updated
30+
31+
* Tests.
32+
333
## [v2.0.5](https://github.com/josantonius/php-json/releases/tag/v2.0.5) (2022-08-11)
434

535
* The exceptions directory was renamed from `exception` to `exceptions`.

0 commit comments

Comments
 (0)