[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/registry/format/ -> php.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: php.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla.Framework
   5   * @subpackage    Registry
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant
   9   * to the GNU General Public License, and as distributed it includes or
  10   * is derivative of works licensed under the GNU General Public License or
  11   * other free or open source software licenses.
  12   * See COPYRIGHT.php for copyright notices and details.
  13   */
  14  
  15  // Check to ensure this file is within the rest of the framework
  16  defined('JPATH_BASE') or die();
  17  
  18  /**
  19   * PHP class format handler for JRegistry
  20   *
  21   * @package     Joomla.Framework
  22   * @subpackage        Registry
  23   * @since        1.5
  24   */
  25  class JRegistryFormatPHP extends JRegistryFormat {
  26  
  27      /**
  28       * Converts an object into a php class string.
  29       *     - NOTE: Only one depth level is supported.
  30       *
  31       * @access public
  32       * @param object $object Data Source Object
  33       * @param array  $param  Parameters used by the formatter
  34       * @return string Config class formatted string
  35       * @since 1.5
  36       */
  37  	function objectToString( &$object, $params ) {
  38  
  39          // Build the object variables string
  40          $vars = '';
  41          foreach (get_object_vars( $object ) as $k => $v)
  42          {
  43              if (is_scalar($v)) {
  44                  $vars .= "\tvar $". $k . " = '" . addcslashes($v, '\\\'') . "';\n";
  45              } elseif (is_array($v)) {
  46                  $vars .= "\tvar $". $k . " = " . $this->_getArrayString($v) . ";\n";
  47              }
  48          }
  49  
  50          $str = "<?php\nclass ".$params['class']." {\n";
  51          $str .= $vars;
  52          $str .= "}\n?>";
  53  
  54          return $str;
  55      }
  56  
  57      /**
  58       * Placeholder method
  59       *
  60       * @access public
  61       * @return boolean True
  62       * @since 1.5
  63       */
  64  	function stringToObject() {
  65          return true;
  66      }
  67  
  68  	function _getArrayString($a)
  69      {
  70          $s = 'array(';
  71          $i = 0;
  72          foreach ($a as $k => $v)
  73          {
  74              $s .= ($i) ? ', ' : '';
  75              $s .= '"'.$k.'" => ';
  76              if (is_array($v)) {
  77                  $s .= $this->_getArrayString($v);
  78              } else {
  79                  $s .= '"'.addslashes($v).'"';
  80              }
  81              $i++;
  82          }
  83          $s .= ')';
  84          return $s;
  85      }
  86  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1