Spade
Mini Shell
| Directory:~$ /home/lmsyaran/public_html/joomla4/ |
| [Home] [System Details] [Kill Me] |
Ini.php000064400000017734151156723730006022 0ustar00<?php
/**
* Part of the Joomla Framework Registry Package
*
* @copyright Copyright (C) 2005 - 2019 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;
use Joomla\Utilities\ArrayHelper;
use stdClass;
/**
* INI format handler for Registry.
*
* @since 1.0
*/
class Ini extends AbstractRegistryFormat
{
/**
* Default options array
*
* @var array
* @since 1.3.0
*/
protected static $options = array(
'supportArrayValues' => false,
'parseBooleanWords' => false,
'processSections' => false,
);
/**
* A cache used by stringToObject.
*
* @var array
* @since 1.0
*/
protected static $cache = array();
/**
* Converts an object into an INI formatted string
* - Unfortunately, there is no way to have ini values nested further than
two
* levels deep. Therefore we will only go through the first two levels of
* the object.
*
* @param object $object Data source object.
* @param array $options Options used by the formatter.
*
* @return string INI formatted string.
*
* @since 1.0
*/
public function objectToString($object, $options = array())
{
$options = array_merge(self::$options, $options);
$supportArrayValues = $options['supportArrayValues'];
$local = array();
$global = array();
$variables = get_object_vars($object);
$last = \count($variables);
// Assume that the first element is in section
$inSection = true;
// Iterate over the object to set the properties.
foreach ($variables as $key => $value)
{
// If the value is an object then we need to put it in a local section.
if (\is_object($value))
{
// Add an empty line if previous string wasn't in a section
if (!$inSection)
{
$local[] = '';
}
// Add the section line.
$local[] = '[' . $key . ']';
// Add the properties for this section.
foreach (get_object_vars($value) as $k => $v)
{
if (\is_array($v) && $supportArrayValues)
{
$assoc = ArrayHelper::isAssociative($v);
foreach ($v as $arrayKey => $item)
{
$arrayKey = $assoc ? $arrayKey : '';
$local[] = $k . '[' . $arrayKey . ']=' .
$this->getValueAsIni($item);
}
}
else
{
$local[] = $k . '=' . $this->getValueAsIni($v);
}
}
// Add empty line after section if it is not the last one
if (--$last !== 0)
{
$local[] = '';
}
}
elseif (\is_array($value) && $supportArrayValues)
{
$assoc = ArrayHelper::isAssociative($value);
foreach ($value as $arrayKey => $item)
{
$arrayKey = $assoc ? $arrayKey : '';
$global[] = $key . '[' . $arrayKey . ']=' .
$this->getValueAsIni($item);
}
}
else
{
// Not in a section so add the property to the global array.
$global[] = $key . '=' . $this->getValueAsIni($value);
$inSection = false;
}
}
return implode("\n", array_merge($global, $local));
}
/**
* Parse an INI formatted string and convert it into an object.
*
* @param string $data INI formatted string to convert.
* @param array $options An array of options used by the formatter,
or a boolean setting to process sections.
*
* @return object Data object.
*
* @since 1.0
*/
public function stringToObject($data, array $options = array())
{
$options = array_merge(self::$options, $options);
// Check the memory cache for already processed strings.
$hash = md5($data . ':' . (int)
$options['processSections']);
if (isset(self::$cache[$hash]))
{
return self::$cache[$hash];
}
// If no lines present just return the object.
if (empty($data))
{
return new stdClass;
}
$obj = new stdClass;
$section = false;
$array = false;
$lines = explode("\n", $data);
// Process the lines.
foreach ($lines as $line)
{
// Trim any unnecessary whitespace.
$line = trim($line);
// Ignore empty lines and comments.
if (empty($line) || ($line[0] === ';'))
{
continue;
}
if ($options['processSections'])
{
$length = \strlen($line);
// If we are processing sections and the line is a section add the
object and continue.
if ($line[0] === '[' && ($line[$length - 1] ===
']'))
{
$section = substr($line, 1, $length - 2);
$obj->$section = new stdClass;
continue;
}
}
elseif ($line[0] === '[')
{
continue;
}
// Check that an equal sign exists and is not the first character of the
line.
if (!strpos($line, '='))
{
// Maybe throw exception?
continue;
}
// Get the key and value for the line.
list($key, $value) = explode('=', $line, 2);
// If we have an array item
if (substr($key, -1) === ']' && ($openBrace =
strpos($key, '[', 1)) !== false)
{
if ($options['supportArrayValues'])
{
$array = true;
$arrayKey = substr($key, $openBrace + 1, -1);
// If we have a multi-dimensional array or malformed key
if (strpos($arrayKey, '[') !== false || strpos($arrayKey,
']') !== false)
{
// Maybe throw exception?
continue;
}
$key = substr($key, 0, $openBrace);
}
else
{
continue;
}
}
// Validate the key.
if (preg_match('/[^A-Z0-9_]/i', $key))
{
// Maybe throw exception?
continue;
}
// If the value is quoted then we assume it is a string.
$length = \strlen($value);
if ($length && ($value[0] === '"') &&
($value[$length - 1] === '"'))
{
// Strip the quotes and Convert the new line characters.
$value = stripcslashes(substr($value, 1, $length - 2));
$value = str_replace('\n', "\n", $value);
}
else
{
// If the value is not quoted, we assume it is not a string.
// If the value is 'false' assume boolean false.
if ($value === 'false')
{
$value = false;
}
elseif ($value === 'true')
{
// If the value is 'true' assume boolean true.
$value = true;
}
elseif ($options['parseBooleanWords'] &&
\in_array(strtolower($value), array('yes', 'no'),
true))
{
// If the value is 'yes' or 'no' and option is
enabled assume appropriate boolean
$value = (strtolower($value) === 'yes');
}
elseif (is_numeric($value))
{
// If the value is numeric than it is either a float or int.
// If there is a period then we assume a float.
if (strpos($value, '.') !== false)
{
$value = (float) $value;
}
else
{
$value = (int) $value;
}
}
}
// If a section is set add the key/value to the section, otherwise top
level.
if ($section)
{
if ($array)
{
if (!isset($obj->$section->$key))
{
$obj->$section->$key = array();
}
if (!empty($arrayKey))
{
$obj->$section->{$key}[$arrayKey] = $value;
}
else
{
$obj->$section->{$key}[] = $value;
}
}
else
{
$obj->$section->$key = $value;
}
}
else
{
if ($array)
{
if (!isset($obj->$key))
{
$obj->$key = array();
}
if (!empty($arrayKey))
{
$obj->{$key}[$arrayKey] = $value;
}
else
{
$obj->{$key}[] = $value;
}
}
else
{
$obj->$key = $value;
}
}
$array = false;
}
// Cache the string to save cpu cycles -- thus the world :)
self::$cache[$hash] = clone $obj;
return $obj;
}
/**
* Method to get a value in an INI format.
*
* @param mixed $value The value to convert to INI format.
*
* @return string The value in INI format.
*
* @since 1.0
*/
protected function getValueAsIni($value)
{
$string = '';
switch (\gettype($value))
{
case 'integer':
case 'double':
$string = $value;
break;
case 'boolean':
$string = $value ? 'true' : 'false';
break;
case 'string':
// Sanitize any CRLF characters..
$string = '"' . str_replace(array("\r\n",
"\n"), '\\n', $value) . '"';
break;
}
return $string;
}
}
Json.php000064400000004172151156723730006204 0ustar00<?php
/**
* Part of the Joomla Framework Registry Package
*
* @copyright Copyright (C) 2005 - 2019 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())
{
$bitMask = isset($options['bitmask']) ?
$options['bitmask'] : 0;
// The depth parameter is only present as of PHP 5.5
if (version_compare(PHP_VERSION, '5.5', '>='))
{
$depth = isset($options['depth']) ?
$options['depth'] : 512;
return json_encode($object, $bitMask, $depth);
}
return json_encode($object, $bitMask);
}
/**
* 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
* @throws \RuntimeException
*/
public function stringToObject($data, array $options =
array('processSections' => false))
{
$data = trim($data);
// Because developers are clearly not validating their data before
pushing it into a Registry, we'll do it for them
if (empty($data))
{
return new \stdClass;
}
if ($data !== '' && $data[0] !== '{')
{
return
AbstractRegistryFormat::getInstance('Ini')->stringToObject($data,
$options);
}
$decoded = json_decode($data);
// Check for an error decoding the data
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE)
{
throw new \RuntimeException(sprintf('Error decoding JSON data:
%s', json_last_error_msg()));
}
return (object) $decoded;
}
}
Php.php000064400000005033151156723730006017 0ustar00<?php
/**
* Part of the Joomla Framework Registry Package
*
* @copyright Copyright (C) 2005 - 2019 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;
/**
* PHP class format handler for Registry
*
* @since 1.0
*/
class Php extends AbstractRegistryFormat
{
/**
* Converts an object into a php class string.
* - NOTE: Only one depth level is supported.
*
* @param object $object Data Source Object
* @param array $params Parameters used by the formatter
*
* @return string Config class formatted string
*
* @since 1.0
*/
public function objectToString($object, $params = array())
{
// A class must be provided
$class = !empty($params['class']) ? $params['class']
: 'Registry';
// Build the object variables string
$vars = '';
foreach (get_object_vars($object) as $k => $v)
{
if (is_scalar($v))
{
$vars .= "\tpublic $" . $k . " = '" .
addcslashes($v, '\\\'') . "';\n";
}
elseif (\is_array($v) || \is_object($v))
{
$vars .= "\tpublic $" . $k . ' = ' .
$this->getArrayString((array) $v) . ";\n";
}
}
$str = "<?php\n";
// If supplied, add a namespace to the class object
if (isset($params['namespace']) &&
$params['namespace'] !== '')
{
$str .= 'namespace ' . $params['namespace'] .
";\n\n";
}
$str .= 'class ' . $class . " {\n";
$str .= $vars;
$str .= '}';
// Use the closing tag if it not set to false in parameters.
if (!isset($params['closingtag']) ||
$params['closingtag'] !== false)
{
$str .= "\n?>";
}
return $str;
}
/**
* Parse a PHP class formatted string and convert it into an object.
*
* @param string $data PHP Class 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())
{
return new \stdClass;
}
/**
* Method to get an array as an exported string.
*
* @param array $a The array to get as a string.
*
* @return string
*
* @since 1.0
*/
protected function getArrayString($a)
{
$s = 'array(';
$i = 0;
foreach ($a as $k => $v)
{
$s .= $i ? ', ' : '';
$s .= '"' . $k . '" => ';
if (\is_array($v) || \is_object($v))
{
$s .= $this->getArrayString((array) $v);
}
else
{
$s .= '"' . addslashes($v) . '"';
}
$i++;
}
$s .= ')';
return $s;
}
}
Xml.php000064400000007135151156723730006035 0ustar00<?php
/**
* Part of the Joomla Framework Registry Package
*
* @copyright Copyright (C) 2005 - 2019 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;
use SimpleXMLElement;
use stdClass;
/**
* XML format handler for Registry.
*
* @since 1.0
*/
class Xml extends AbstractRegistryFormat
{
/**
* Converts an object into an XML formatted string.
* - If more than two levels of nested groups are necessary, since INI is
not
* useful, XML or another format should be used.
*
* @param object $object Data source object.
* @param array $options Options used by the formatter.
*
* @return string XML formatted string.
*
* @since 1.0
*/
public function objectToString($object, $options = array())
{
$rootName = isset($options['name']) ?
$options['name'] : 'registry';
$nodeName = isset($options['nodeName']) ?
$options['nodeName'] : 'node';
// Create the root node.
$root = simplexml_load_string('<' . $rootName . '
/>');
// Iterate over the object members.
$this->getXmlChildren($root, $object, $nodeName);
return $root->asXML();
}
/**
* Parse a XML formatted string and convert it into an object.
*
* @param string $data XML 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())
{
$obj = new stdClass;
// Parse the XML string.
$xml = simplexml_load_string($data);
foreach ($xml->children() as $node)
{
$obj->{$node['name']} = $this->getValueFromNode($node);
}
return $obj;
}
/**
* Method to get a PHP native value for a SimpleXMLElement object. --
called recursively
*
* @param object $node SimpleXMLElement object for which to get the
native value.
*
* @return mixed Native value of the SimpleXMLElement object.
*
* @since 1.0
*/
protected function getValueFromNode($node)
{
switch ($node['type'])
{
case 'integer':
$value = (string) $node;
return (int) $value;
case 'string':
return (string) $node;
case 'boolean':
$value = (string) $node;
return (bool) $value;
case 'double':
$value = (string) $node;
return (float) $value;
case 'array':
$value = array();
foreach ($node->children() as $child)
{
$value[(string) $child['name']] =
$this->getValueFromNode($child);
}
break;
default:
$value = new stdClass;
foreach ($node->children() as $child)
{
$value->{$child['name']} =
$this->getValueFromNode($child);
}
break;
}
return $value;
}
/**
* Method to build a level of the XML string -- called recursively
*
* @param SimpleXMLElement $node SimpleXMLElement object to attach
children.
* @param object $var Object that represents a node of
the XML document.
* @param string $nodeName The name to use for node
elements.
*
* @return void
*
* @since 1.0
*/
protected function getXmlChildren(SimpleXMLElement $node, $var, $nodeName)
{
// Iterate over the object members.
foreach ((array) $var as $k => $v)
{
if (is_scalar($v))
{
$n = $node->addChild($nodeName, $v);
$n->addAttribute('name', $k);
$n->addAttribute('type', \gettype($v));
}
else
{
$n = $node->addChild($nodeName);
$n->addAttribute('name', $k);
$n->addAttribute('type', \gettype($v));
$this->getXmlChildren($n, $v, $nodeName);
}
}
}
}
Yaml.php000064400000003637151156723730006202 0ustar00<?php
/**
* Part of the Joomla Framework Registry Package
*
* @copyright Copyright (C) 2005 - 2019 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;
use Symfony\Component\Yaml\Dumper as SymfonyYamlDumper;
use Symfony\Component\Yaml\Parser as SymfonyYamlParser;
/**
* YAML format handler for Registry.
*
* @since 1.0
*/
class Yaml extends AbstractRegistryFormat
{
/**
* The YAML parser class.
*
* @var \Symfony\Component\Yaml\Parser
* @since 1.0
*/
private $parser;
/**
* The YAML dumper class.
*
* @var \Symfony\Component\Yaml\Dumper
* @since 1.0
*/
private $dumper;
/**
* Construct to set up the parser and dumper
*
* @since 1.0
*/
public function __construct()
{
$this->parser = new SymfonyYamlParser;
$this->dumper = new SymfonyYamlDumper;
}
/**
* Converts an object into a YAML formatted string.
* We use json_* to convert the passed object to an array.
*
* @param object $object Data source object.
* @param array $options Options used by the formatter.
*
* @return string YAML formatted string.
*
* @since 1.0
*/
public function objectToString($object, $options = array())
{
$array = json_decode(json_encode($object), true);
return $this->dumper->dump($array, 2, 0);
}
/**
* Parse a YAML formatted string and convert it into an object.
* We use the json_* methods to convert the parsed YAML array to an
object.
*
* @param string $data YAML 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())
{
$array = $this->parser->parse(trim($data));
return (object) json_decode(json_encode($array));
}
}