Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
php.php
Aller à la documentation de ce fichier.
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  */
20 {
21  /**
22  * Converts an object into a php class string.
23  * - NOTE: Only one depth level is supported.
24  *
25  * @param object $object Data Source Object
26  * @param array $params Parameters used by the formatter
27  *
28  * @return string Config class formatted string
29  *
30  * @since 11.1
31  */
32  public function objectToString($object, $params = array())
33  {
34  // Build the object variables string
35  $vars = '';
36 
37  foreach (get_object_vars($object) as $k => $v)
38  {
39  if (is_scalar($v))
40  {
41  $vars .= "\tpublic $" . $k . " = '" . addcslashes($v, '\\\'') . "';\n";
42  }
43  elseif (is_array($v) || is_object($v))
44  {
45  $vars .= "\tpublic $" . $k . " = " . $this->getArrayString((array) $v) . ";\n";
46  }
47  }
48 
49  $str = "<?php\nclass " . $params['class'] . " {\n";
50  $str .= $vars;
51  $str .= "}";
52 
53  // Use the closing tag if it not set to false in parameters.
54  if (!isset($params['closingtag']) || $params['closingtag'] !== false)
55  {
56  $str .= "\n?>";
57  }
58 
59  return $str;
60  }
61 
62  /**
63  * Parse a PHP class formatted string and convert it into an object.
64  *
65  * @param string $data PHP Class formatted string to convert.
66  * @param array $options Options used by the formatter.
67  *
68  * @return object Data object.
69  *
70  * @since 11.1
71  */
72  public function stringToObject($data, array $options = array())
73  {
74  return true;
75  }
76 
77  /**
78  * Method to get an array as an exported string.
79  *
80  * @param array $a The array to get as a string.
81  *
82  * @return array
83  *
84  * @since 11.1
85  */
86  protected function getArrayString($a)
87  {
88  $s = 'array(';
89  $i = 0;
90 
91  foreach ($a as $k => $v)
92  {
93  $s .= ($i) ? ', ' : '';
94  $s .= '"' . $k . '" => ';
95 
96  if (is_array($v) || is_object($v))
97  {
98  $s .= $this->getArrayString((array) $v);
99  }
100  else
101  {
102  $s .= '"' . addslashes($v) . '"';
103  }
104 
105  $i++;
106  }
107 
108  $s .= ')';
109 
110  return $s;
111  }
112 }