Skip to content

Commit 268850b

Browse files
committed
Use external library for JSON
1 parent 1e13de2 commit 268850b

8 files changed

Lines changed: 25 additions & 127 deletions

File tree

app/classes/Transvision/Json.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

app/inc/search_counter.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
<?php
22
namespace Transvision;
33

4+
use Json\Json;
5+
46
// Create a JSON file logging locale/number of requests
5-
$stats = Json::fetch(CACHE_PATH . 'stats_locales.json');
7+
$json_data = new Json;
8+
$local_filename = CACHE_PATH . 'stats_locales.json';
9+
$stats = $json_data
10+
->setURI($local_filename)
11+
->fetchContent();
12+
613
$stats[$locale] = array_key_exists($locale, $stats) ? $stats[$locale] += 1 : 1;
7-
file_put_contents(CACHE_PATH . 'stats_locales.json', json_encode($stats));
14+
$json_data->saveFile($stats, $local_filename);
815

916
// Create a JSON file logging search options to determine if some are unused
10-
$stats = Json::fetch(CACHE_PATH . 'stats_requests.json');
17+
$local_filename = CACHE_PATH . 'stats_requests.json';
18+
$stats = $json_data
19+
->setURI($local_filename)
20+
->fetchContent();
1121

1222
foreach ($check as $k => $v) {
1323
if (in_array($k, $form_checkboxes) && $v == 1) {
@@ -18,6 +28,6 @@
1828
$stats[$v] = array_key_exists($v, $stats) ? $stats[$v] += 1 : 1;
1929
}
2030

21-
file_put_contents(CACHE_PATH . 'stats_requests.json', json_encode($stats));
31+
$json_data->saveFile($stats, $local_filename);
2232
}
2333
unset($stats);

app/views/json.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<?php
22
namespace Transvision;
33

4+
use Json\Json;
5+
46
/*
5-
* This view outputs a json or jsonp representation of search results
7+
* This view outputs a JSON or JSONP representation of search results
68
*/
79

810
// Log script performance in PHP integrated developement server console
911
Utils::logScriptPerformances();
1012

11-
// We die here because we never want to send anything more after the Json file
12-
die(Json::output(
13+
// We die here because we never want to send anything more after the JSON file
14+
$json_data = new Json;
15+
die($json_data->outputContent(
1316
$json,
1417
isset($_GET['callback']) ? $_GET['callback'] : false
1518
));

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"type": "vcs",
99
"url": "https://github.com/mozilla-l10n/phpclass-cache"
1010
},
11+
{
12+
"type": "vcs",
13+
"url": "https://github.com/mozilla-l10n/phpclass-json"
14+
},
1115
{
1216
"type": "vcs",
1317
"url": "https://github.com/pascalchevrel/Verif/"
@@ -47,6 +51,7 @@
4751
"monolog/monolog" : "~1.1",
4852
"mozillal10n/bugzilla": "~0.1",
4953
"mozillal10n/cache": "~0.1",
54+
"mozillal10n/json": "~0.1",
5055
"pascalc/tinyl10n" : "~0.1",
5156
"pascalc/vcs": "~0.1",
5257
"robloach/component-installer": "*",

tests/testfiles/json/empty.json

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/testfiles/json/test.json

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/testfiles/json/test1.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/units/Transvision/Json.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)