Exemple #1
0
 public function testSaveFile()
 {
     $obj = new _Json();
     $json_data = ['key1' => 'value1', 'key2' => 'value2'];
     $tmp_filename = TEST_FILES . 'tmp.json';
     // Check standard output
     $obj->saveFile($json_data, $tmp_filename);
     $file_content = file_get_contents($tmp_filename);
     $this->string($file_content)->isEqualTo('{"key1":"value1","key2":"value2"}');
     // Check prettified output
     $obj->saveFile($json_data, $tmp_filename, true);
     $file_content = file_get_contents($tmp_filename);
     $this->string($file_content)->isEqualTo("{\n    \"key1\": \"value1\",\n    \"key2\": \"value2\"\n}");
     // Remove temp file
     unlink($tmp_filename);
 }
Exemple #2
0
 public function checkConnection()
 {
     $admin = Json::get("./databases/JSONMyAdmin.json");
     $this->getConnector()["user"] == $admin["user"] ? true : die("Exception: 1");
     $this->getConnector()["password"] == $admin["password"] ? true : die("Exception: 2");
     $this->getConnector()["database"] == $admin["database"] ? true : die("Exception: 3");
 }
Exemple #3
0
<?php

namespace Transvision;

use Json\Json;
/*
 * This view outputs a JSON or JSONP representation of search results
 */
// Log script performance in PHP integrated developement server console
Utils::logScriptPerformances();
// We die here because we never want to send anything more after the JSON file
$json_data = new Json();
die($json_data->outputContent($json, isset($_GET['callback']) ? $_GET['callback'] : false));
 /**
  * Return array with data for all repositories
  *
  * @return array Data repositories
  */
 public function getRepositoriesJson()
 {
     $json_data = new Json($this->source_path . 'repositories.json');
     return $json_data->fetchContent();
 }
Exemple #5
0
date_default_timezone_set('Europe/Paris');
// Autoloading of composer dependencies
$root_folder = realpath(__DIR__ . '/../..');
require_once "{$root_folder}/vendor/autoload.php";
// Set an environment variable so that the instance will use content from test files
putenv("AUTOMATED_TESTS=true");
// Launch PHP dev server in the background
chdir("{$root_folder}/web");
exec('php -S 0.0.0.0:8083 > /dev/null 2>&1 & echo $!', $output);
// We will need the pid to kill it, beware, this is the pid of the php server started above
$pid = $output[0];
// Pause to let time for the dev server to launch in the background
sleep(3);
$failures = [];
$base_url = 'http://localhost:8083/';
$json_data = new Json();
// Base URL
$headers = get_headers($base_url, 1);
if (strpos($headers[0], '200 OK') === false) {
    $failures[] = "HTTP status for base URL is: {$headers[0]}. Expected: 200.";
}
$response = $json_data->setURI($base_url)->fetchContent();
if (!isset($response[0])) {
    $failures[] = "Product 0 is missing.";
} else {
    if ($response[0]['id'] !== 'beta') {
        $failures[] = "Product 0 is not 'beta'.";
    }
    if (!in_array('de', $response[0]['locales'])) {
        $failures[] = "'de' is missing from product 0.";
    }
Exemple #6
0
<?php

use Json\Json;
$file = INSTALL_ROOT . 'data/stats.json';
$link = isset($_GET['link']) ? $_GET['link'] : '';
$json_obj = new Json($file);
if (file_exists($file)) {
    $stats = $json_obj->fetchContent();
    if (!is_array($stats)) {
        trigger_error("JSON content is not an array, aborting stats recording.", E_USER_ERROR);
        exit;
    }
} else {
    $stats = [];
}
$stats[$link] = in_array($link, array_keys($stats)) ? $stats[$link] + 1 : 1;
$json_obj->saveFile($stats, $file, true);
 /**
  * Return array with data for all Bugzilla l10n components
  *
  * @return array Data repositories
  */
 public function getBugzillaComponentsJson()
 {
     $json_data = new Json($this->source_path . 'bugzilla_components.json');
     return $json_data->fetchContent();
 }
Exemple #8
0
    $statement = function ($json) {
        return @json_decode($json, false, 512, JSON_BIGINT_AS_STRING);
    };
} else {
    $statement = function ($json) {
        return @json_decode($json);
    };
}
foreach (timeattack('Function-JSON decoding (Array)', 100000) as $_) {
    $ignore = $statement($json_array);
}
foreach (timeattack('Json\\Json encoding (Object)', 100000) as $_) {
    $ignore = \Json\Json::stringify($php_object);
}
foreach (timeattack('JSON encoding (Array)', 100000) as $_) {
    $ignore = \Json\Json::stringify($php_array);
}
foreach (timeattack('Raw-JSON encoding (Object)', 100000) as $_) {
    $ignore = @json_encode($php_object, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
foreach (timeattack('Raw-JSON encoding (Array)', 100000) as $_) {
    $ignore = @json_encode($php_array, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
$is_supported = version_compare(PHP_VERSION, '5.4.0', '>=');
foreach (timeattack('IfVersioning-JSON encoding (Object)', 100000) as $_) {
    if ($is_supported) {
        $ignore = @json_encode($php_object, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    } else {
        $ignore = @json_encode($php_object);
    }
}
Exemple #9
0
<?php

include "libs/autoloader.php";
use Database\Cascade;
use Database\Request;
use Database\Response;
use Database\Connector;
use Json\Json;
$cascade = new Cascade("kek123", "kek", "testDatabase");
$cascade->connector->checkConnection();
// New request from testTable Table
new Request("testTable", function (Cascade $db) {
    Request::getRequest();
    new Response(function () use($db) {
    }, Json::get()["TABLE_NOT_FOUND"]);
}, [$cascade]);
<?php

namespace Transvision;

use Json\Json;
// Create a JSON file logging locale/number of requests
$json_data = new Json();
$local_filename = CACHE_PATH . 'stats_locales.json';
$stats = $json_data->setURI($local_filename)->fetchContent();
$stats[$locale] = array_key_exists($locale, $stats) ? $stats[$locale] += 1 : 1;
$json_data->saveFile($stats, $local_filename);
// Create a JSON file logging search options to determine if some are unused
$local_filename = CACHE_PATH . 'stats_requests.json';
$stats = $json_data->setURI($local_filename)->fetchContent();
foreach ($check as $k => $v) {
    if (in_array($k, $form_checkboxes) && $v == 1) {
        $stats[$k] = array_key_exists($k, $stats) ? $stats[$k] += 1 : 1;
    }
    if (in_array($k, array_diff($form_search_options, $form_checkboxes))) {
        $stats[$v] = array_key_exists($v, $stats) ? $stats[$v] += 1 : 1;
    }
    $json_data->saveFile($stats, $local_filename);
}
unset($stats);
Exemple #11
0
timeattack('JSON encoding (Object)', 100000, function () use($object) {
    // $ignore = json_encode($object);
    $ignore = \Json\Json::stringify($object);
});
timeattack('JSON encoding (Array)', 100000, function () use($array) {
    // $ignore = json_encode($array);
    $ignore = \Json\Json::stringify($array);
});
timeattack('JSON encoding (Null)', 100000, function () {
    // $ignore = json_encode(null);
    $ignore = \Json\Json::stringify(null);
});
timeattack('JSON encoding (hasError)', 100000, function () use($fp) {
    // $ignore = json_encode(array($fp));
    try {
        $ignore = \Json\Json::stringify(array($fp));
    } catch (\Json\Exception\Encoding $e) {
    }
});
echo "-------------------------\n";
echo "done.\n";
ob_start(function ($buffer) {
    return '';
});
?>

5.5.27
-------------------------
JSON encoding (Object) * 100000: 0.51506591 sec
JSON encoding (Array) * 100000: 0.27953506 sec
JSON encoding (Null) * 100000: 0.05300689 sec
Exemple #12
0
// Autoloading of composer dependencies
$root_folder = realpath(__DIR__ . '/..');
require_once "{$root_folder}/vendor/autoload.php";
// Override sources for functional tests both locally and on Travis
if (getenv('TRAVIS') || getenv('AUTOMATED_TESTS')) {
    $source_path = "{$root_folder}/tests/testfiles/";
} else {
    $source_path = "{$root_folder}/app/sources/";
}
// Query request
$type = Utils::getQueryParam('type');
$repo = Utils::getQueryParam('repo');
$bugzilla = Utils::getQueryParam('bugzilla');
$tool = Utils::getQueryParam('tool');
$repos = new Repositories($source_path);
$json_data = new Json();
// Only one repo requested
if ($repo != '') {
    $locales = $repos->getSingleRepository($repo);
    if ($locales) {
        die($json_data->outputContent($locales));
    } else {
        http_response_code(400);
        die('ERROR: unknown repository.');
    }
}
// Only one type of repo requested
if ($type != '') {
    die($json_data->outputContent($repos->getTypeRepositories($type)));
}
// Bugzilla components
Exemple #13
0
}
$object = '{"name":"Luke Skywalker","teacher":"Yoda","job":"Jedi","force":true,"height":1.72,"weight":77,"droid":["C-3PO","R2-D2"]}';
$array = '[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]';
echo PHP_VERSION . "\n";
echo "-------------------------\n";
timeattack('JSON decoding (Object)', 100000, function () use($object) {
    // $ignore = json_decode($object);
    $ignore = \Json\Json::parse($object);
});
timeattack('JSON decoding (Array)', 100000, function () use($array) {
    // $ignore = json_decode($array);
    $ignore = \Json\Json::parse($array);
});
timeattack('JSON decoding (Null)', 100000, function () {
    // $ignore = json_decode('');
    $ignore = \Json\Json::parse('');
});
echo "-------------------------\n";
echo "done.\n";
ob_start(function ($buffer) {
    return '';
});
?>

5.5.27
-------------------------
JSON decoding (Object) * 100000: 0.96562314 sec
JSON decoding (Array) * 100000: 0.78059888 sec
JSON decoding (Null) * 100000: 0.09851217 sec

5.5.27