- md5
- 077f702bfaaefee9a2fc80f493dbadc1
- sha1
- ce9f62942c7e9cb2309008e88f4531b828857ccc
- sha256
- 58bb277b681cf5d2d702fcf8b259c47af2dc1dda59c881fcd15a0e12b952d0c3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
<?php
/**
* Part of the Joomla Framework Registry Package
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Registry\Format;
use Joomla\Registry\AbstractRegistryFormat;
/**
* JSON format handler for Registry.
*
* @since 1.0
*/
class Json extends AbstractRegistryFormat
{
/**
* Converts an object into a JSON formatted string.
*
* @param object $object Data source object.
* @param array $options Options used by the formatter.
*
* @return string JSON formatted string.
*
* @since 1.0
*/
public function objectToString($object, $options = array())
{
return json_encode($object);
}
/**
* Parse a JSON formatted string and convert it into an object.
*
* If the string is not in JSON format, this method will attempt to parse it as INI format.
*
* @param string $data JSON formatted string to convert.
* @param array $options Options used by the formatter.
*
* @return object Data object.
*
* @since 1.0
*/
public function stringToObject($data, array $options = array('processSections' => false))
{
$data = trim($data);
if ((substr($data, 0, 1) != '{') && (substr($data, -1, 1) != '}'))
{
$ini = AbstractRegistryFormat::getInstance('Ini');
$obj = $ini->stringToObject($data, $options);
}
else
{
$obj = json_decode($data);
}
return $obj;
}
}
The same content is in 7 releases, Joomla 3.3.0 to 3.3.6. See them all, or every version of this file.