JRegistryFormatPHP/objectToString
From Joomla! Documentation
< API16:JRegistryFormatPHP
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Converts an object into a php class string. NOTE: Only one depth level is supported.
Syntax[edit]
objectToString($object, $params)
Parameter Name | Default Value | Description |
---|---|---|
$object | Data Source Object | |
$params | Parameters used by the formatter |
Returns[edit]
string Config class formatted string
Defined in[edit]
libraries/joomla/registry/format/php.php
Importing[edit]
jimport( 'joomla.registry.format.php' );
Source Body[edit]
public function objectToString($object, $params)
{
// Build the object variables string
$vars = '';
foreach (get_object_vars($object) as $k => $v) {
if (is_scalar($v)) {
$vars .= "\tpublic $". $k . " = '" . addcslashes($v, '\\\'') . "';\n";
} else if (is_array($v)) {
$vars .= "\tpublic $". $k . " = " . $this->_getArrayString($v) . ";\n";
}
}
$str = "<?php\nclass ".$params['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;
}
Examples[edit]
Code Examples[edit]