Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
format.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  * Abstract Format for JRegistry
14  *
15  * @package Joomla.Platform
16  * @subpackage Registry
17  * @since 11.1
18  */
19 abstract class JRegistryFormat
20 {
21  /**
22  * @var array JRegistryFormat instances container.
23  * @since 11.3
24  */
25  protected static $instances = array();
26 
27  /**
28  * Returns a reference to a Format object, only creating it
29  * if it doesn't already exist.
30  *
31  * @param string $type The format to load
32  *
33  * @return JRegistryFormat Registry format handler
34  *
35  * @since 11.1
36  * @throws InvalidArgumentException
37  */
38  public static function getInstance($type)
39  {
40  // Sanitize format type.
41  $type = strtolower(preg_replace('/[^A-Z0-9_]/i', '', $type));
42 
43  // Only instantiate the object if it doesn't already exist.
44  if (!isset(self::$instances[$type]))
45  {
46  // Only load the file if the class does not exist.
47  $class = 'JRegistryFormat' . $type;
48 
49  if (!class_exists($class))
50  {
51  $path = __DIR__ . '/format/' . $type . '.php';
52 
53  if (is_file($path))
54  {
55  include_once $path;
56  }
57  else
58  {
59  throw new InvalidArgumentException('Unable to load format class.', 500);
60  }
61  }
62 
63  self::$instances[$type] = new $class;
64  }
65 
66  return self::$instances[$type];
67  }
68 
69  /**
70  * Converts an object into a formatted string.
71  *
72  * @param object $object Data Source Object.
73  * @param array $options An array of options for the formatter.
74  *
75  * @return string Formatted string.
76  *
77  * @since 11.1
78  */
79  abstract public function objectToString($object, $options = null);
80 
81  /**
82  * Converts a formatted string into an object.
83  *
84  * @param string $data Formatted string
85  * @param array $options An array of options for the formatter.
86  *
87  * @return object Data Object
88  *
89  * @since 11.1
90  */
91  abstract public function stringToObject($data, array $options = array());
92 }