Skip to content

Commit 3bd96f5

Browse files
committed
Updated to 1.1.2 version
1 parent caecc16 commit 3bd96f5

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

CHANGELOG.md

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

3+
## 1.1.2 - 2017-05-31
4+
5+
* The file exception not found in the `fileToArray()` method was deleted. Now if it does not exist the file will create it with an empty array.
6+
7+
* `JSON_PRETTY_PRINT` was added at time to create the json file.
8+
39
## 1.1.1 - 2017-03-18
410
* Some files were excluded from download and comments and readme files were updated.
511

README-ES.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Esta ĺibrería es soportada por versiones de PHP 5.6 o superiores y es compatib
4444

4545
### Cómo empezar y ejemplos
4646

47-
Para utilizar esta librería, simplemente:
47+
Para utilizar esta biblioteca, simplemente:
4848

4949
```php
5050
require __DIR__ . '/vendor/autoload.php';
@@ -53,7 +53,7 @@ use Josantonius\Json\Json;
5353
```
5454
### Métodos disponibles
5555

56-
Métodos disponibles en esta librería:
56+
Métodos disponibles en esta biblioteca:
5757

5858
```php
5959
Json::arrayToFile();
@@ -62,7 +62,7 @@ Json::jsonLastError();
6262
```
6363
### Uso
6464

65-
Ejemplo de uso para esta librería:
65+
Ejemplo de uso para esta biblioteca:
6666

6767
```php
6868
<?php
@@ -95,7 +95,7 @@ $loader->addPsr4('Josantonius\\Json\\Tests\\', __DIR__ . '/vendor/josantonius/js
9595

9696
use Josantonius\Json\Tests\JsonTest;
9797
```
98-
Métodos de prueba disponibles en esta librería:
98+
Métodos de prueba disponibles en esta biblioteca:
9999

100100
```php
101101
JsonTest::testArrayToFile();
@@ -106,7 +106,7 @@ JsonTest::testFileToArrayError();
106106

107107
### Manejador de excepciones
108108

109-
Esta librería utiliza [control de excepciones](src/Exception) que puedes personalizar a tu gusto.
109+
Esta biblioteca utiliza [control de excepciones](src/Exception) que puedes personalizar a tu gusto.
110110
### Contribuir
111111
1. Comprobar si hay incidencias abiertas o abrir una nueva para iniciar una discusión en torno a un fallo o función.
112112
1. Bifurca la rama del repositorio en GitHub para iniciar la operación de ajuste.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "josantonius/json",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"type": "library",
55
"description": "PHP simple library for managing Json files.",
66
"keywords": [

src/Json.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ public static function arrayToFile($array, $pathfile) {
4040
mkdir($path, 0755, true);
4141
}
4242

43-
$json = json_encode($array);
43+
$json = json_encode($array, JSON_PRETTY_PRINT);
4444

4545
self::jsonLastError();
4646

47-
if (!$file = fopen($pathfile, 'w+')) {
47+
if (!$file = fopen($pathfile, 'w+')) {
48+
49+
$message = 'Could not create file in';
4850

49-
throw new JsonException('Could not create file in ' . $pathfile, 300);
51+
throw new JsonException($message . ' ' . $pathfile, 605);
5052
}
5153

5254
fwrite($file, $json);
@@ -61,23 +63,22 @@ public static function arrayToFile($array, $pathfile) {
6163
*
6264
* @param string $pathfile → path to JSON file
6365
*
64-
* @throws JsonException → there is no file
65-
* @return array → JSON format
66+
* @return array
6667
*/
6768
public static function fileToArray($pathfile) {
6869

69-
if (is_file($pathfile)) {
70+
if (!is_file($pathfile)) {
7071

71-
$jsonString = file_get_contents($pathfile);
72-
73-
$jsonArray = json_decode($jsonString, true);
72+
self::arrayToFile([], $pathFile);
73+
}
7474

75-
self::jsonLastError();
75+
$jsonString = file_get_contents($pathfile);
76+
77+
$jsonArray = json_decode($jsonString, true);
7678

77-
return $jsonArray;
78-
}
79+
self::jsonLastError();
7980

80-
throw new JsonException('File not found in ' . $pathfile, 605);
81+
return $jsonArray;
8182
}
8283

8384
/**
@@ -108,4 +109,4 @@ public static function jsonLastError() {
108109
throw new JsonException('Unknown error', 995);
109110
}
110111
}
111-
}
112+
}

0 commit comments

Comments
 (0)