/** * Test if \u0119 (196+153) will get correctly formatted * See ticket #2613 */ public function testUnicodeWithPrependedSlash() { if (!extension_loaded('mbstring')) { $this->markTestSkipped('Test requires the mbstring extension'); } $data = '"' . chr(92) . chr(92) . chr(92) . 'u0119"'; $encodedData = JsonFormatter::format($data, true, true); $expected = '34+92+92+196+153+34'; $this->assertEquals($expected, $this->getCharacterCodes($encodedData)); }
/** * save loaded data to plugin composer file * * @return void */ public function write() { $json = json_encode($this->data); if (function_exists('json_format')) { $json = json_format($json); } else { $json = \Composer\Json\JsonFormatter::format($json, true, true); } file_put_contents($this->path, $json); }
/** * Encodes an array into (optionally pretty-printed) JSON * * @param mixed $data Data to encode into a formatted JSON string * @param int $options json_encode options (defaults to JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) * @return string Encoded json */ public static function encode($data, $options = 448) { if (PHP_VERSION_ID >= 50400) { $json = json_encode($data, $options); if (false === $json) { self::throwEncodeError(json_last_error()); } // compact brackets to follow recent php versions if (PHP_VERSION_ID < 50428 || PHP_VERSION_ID >= 50500 && PHP_VERSION_ID < 50512 || defined('JSON_C_VERSION') && version_compare(phpversion('json'), '1.3.6', '<')) { $json = preg_replace('/\\[\\s+\\]/', '[]', $json); $json = preg_replace('/\\{\\s+\\}/', '{}', $json); } return $json; } $json = json_encode($data); if (false === $json) { self::throwEncodeError(json_last_error()); } $prettyPrint = (bool) ($options & self::JSON_PRETTY_PRINT); $unescapeUnicode = (bool) ($options & self::JSON_UNESCAPED_UNICODE); $unescapeSlashes = (bool) ($options & self::JSON_UNESCAPED_SLASHES); if (!$prettyPrint && !$unescapeUnicode && !$unescapeSlashes) { return $json; } $result = JsonFormatter::format($json, $unescapeUnicode, $unescapeSlashes); return $result; }
/** * Encodes an array into (optionally pretty-printed) JSON * * @param mixed $data Data to encode into a formatted JSON string * @param int $options json_encode options (defaults to JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) * @return string Encoded json */ public static function encode($data, $options = 448) { if (version_compare(PHP_VERSION, '5.4', '>=')) { return json_encode($data, $options); } $json = json_encode($data); $prettyPrint = (bool) ($options & self::JSON_PRETTY_PRINT); $unescapeUnicode = (bool) ($options & self::JSON_UNESCAPED_UNICODE); $unescapeSlashes = (bool) ($options & self::JSON_UNESCAPED_SLASHES); if (!$prettyPrint && !$unescapeUnicode && !$unescapeSlashes) { return $json; } $result = JsonFormatter::format($json, $unescapeUnicode, $unescapeSlashes); return $result; }
/** * Encodes an array into (optionally pretty-printed) JSON * * @param mixed $data Data to encode into a formatted JSON string * @param int $options json_encode options (defaults to JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) * @return string Encoded json */ public static function encode($data, $options = 448) { if (version_compare(PHP_VERSION, '5.4', '>=')) { $json = json_encode($data, $options); // compact brackets to follow recent php versions if (PHP_VERSION_ID < 50428 || PHP_VERSION_ID >= 50500 && PHP_VERSION_ID < 50512) { $json = preg_replace('/\\[\\s+\\]/', '[]', $json); $json = preg_replace('/\\{\\s+\\}/', '{}', $json); } return $json; } $json = json_encode($data); $prettyPrint = (bool) ($options & self::JSON_PRETTY_PRINT); $unescapeUnicode = (bool) ($options & self::JSON_UNESCAPED_UNICODE); $unescapeSlashes = (bool) ($options & self::JSON_UNESCAPED_SLASHES); if (!$prettyPrint && !$unescapeUnicode && !$unescapeSlashes) { return $json; } $result = JsonFormatter::format($json, $unescapeUnicode, $unescapeSlashes); return $result; }
public function postInstallOrUpdate(Event $event) { if (!$this->enabled) { return; } $extra = $event->getComposer()->getPackage()->getExtra(); $path = $extra['xpressengine-plugin']['path']; $data = json_decode(file_get_contents($path)); $data->{"xpressengine-plugin"}->changed = XpressengineInstaller::$changed; $dataJson = json_encode($data); $dataJson = JsonFormatter::format($dataJson, true, true); file_put_contents($path, $dataJson); }
public function update() { $json = json_encode($this->getLicenses(), true); $prettyJson = JsonFormatter::format($json, true, true); file_put_contents(__DIR__ . '/../../../res/spdx-licenses.json', $prettyJson); }