API16

JRegistryFormatPHP/objectToString: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Converts an object into a php class string. NOTE: Only one depth level is supported. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Descripti...
 
m preparing for archive only
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:




<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JRegistryFormatPHP/objectToString|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JRegistryFormatPHP/objectToString}}
 
 


===Syntax===
===Syntax===
Line 63: Line 61:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JRegistryFormatPHP/objectToString|Edit See Also]]<nowiki>]</nowiki>
 
</span>
{{SeeAlso:JRegistryFormatPHP/objectToString}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=objectToString
  category=objectToString
  category=JRegistryFormatPHP
  category=JRegistryFormatPHP
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>

Latest revision as of 02:00, 25 March 2017

Description

Converts an object into a php class string. NOTE: Only one depth level is supported.




Syntax

objectToString($object, $params)
Parameter Name Default Value Description
$object Data Source Object
$params Parameters used by the formatter

Returns

string Config class formatted string

Defined in

libraries/joomla/registry/format/php.php

Importing

jimport( 'joomla.registry.format.php' );

Source Body

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

Code Examples