Source for file php.php

Documentation is available at php.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Registry
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * PHP class format handler for JRegistry
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Registry
  17.  * @since       11.1
  18.  */
  19. {
  20.     /**
  21.      * Converts an object into a php class string.
  22.      * - NOTE: Only one depth level is supported.
  23.      *
  24.      * @param   object  $object  Data Source Object
  25.      * @param   array   $params  Parameters used by the formatter
  26.      *
  27.      * @return  string  Config class formatted string
  28.      *
  29.      * @since   11.1
  30.      */
  31.     public function objectToString($object$params array())
  32.     {
  33.         // Build the object variables string
  34.         $vars '';
  35.  
  36.         foreach (get_object_vars($objectas $k => $v)
  37.         {
  38.             if (is_scalar($v))
  39.             {
  40.                 $vars .= "\tpublic $" $k " = '" addcslashes($v'\\\''"';\n";
  41.             }
  42.             elseif (is_array($v|| is_object($v))
  43.             {
  44.                 $vars .= "\tpublic $" $k " = " $this->getArrayString((array) $v";\n";
  45.             }
  46.         }
  47.  
  48.         $str "<?php\nclass " $params['class'" {\n";
  49.         $str .= $vars;
  50.         $str .= "}";
  51.  
  52.         // Use the closing tag if it not set to false in parameters.
  53.         if (!isset($params['closingtag']|| $params['closingtag'!== false)
  54.         {
  55.             $str .= "\n?>";
  56.         }
  57.  
  58.         return $str;
  59.     }
  60.  
  61.     /**
  62.      * Parse a PHP class formatted string and convert it into an object.
  63.      *
  64.      * @param   string  $data     PHP Class formatted string to convert.
  65.      * @param   array   $options  Options used by the formatter.
  66.      *
  67.      * @return  object   Data object.
  68.      *
  69.      * @since   11.1
  70.      */
  71.     public function stringToObject($dataarray $options array())
  72.     {
  73.         return true;
  74.     }
  75.  
  76.     /**
  77.      * Method to get an array as an exported string.
  78.      *
  79.      * @param   array  $a  The array to get as a string.
  80.      *
  81.      * @return  array 
  82.      *
  83.      * @since   11.1
  84.      */
  85.     protected function getArrayString($a)
  86.     {
  87.         $s 'array(';
  88.         $i 0;
  89.  
  90.         foreach ($a as $k => $v)
  91.         {
  92.             $s .= ($i', ' '';
  93.             $s .= '"' $k '" => ';
  94.  
  95.             if (is_array($v|| is_object($v))
  96.             {
  97.                 $s .= $this->getArrayString((array) $v);
  98.             }
  99.             else
  100.             {
  101.                 $s .= '"' addslashes($v'"';
  102.             }
  103.  
  104.             $i++;
  105.         }
  106.  
  107.         $s .= ')';
  108.  
  109.         return $s;
  110.     }
  111. }

Documentation generated on Tue, 19 Nov 2013 15:10:31 +0100 by phpDocumentor 1.4.3