PageRenderTime 18ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/libraries/vendor/joomla/registry/src/AbstractRegistryFormat.php

https://gitlab.com/vitaliylukin91/idea-rating
PHP | 79 lines | 47 code | 4 blank | 28 comment | 1 complexity | 7676f2c559cc92cd5fc05dcda3eb23a3 MD5 | raw file
 1<?php
 2/**
 3 * Part of the Joomla Framework Registry Package
 4 *
 5 * @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 6 * @license    GNU General Public License version 2 or later; see LICENSE
 7 */
 8
 9namespace Joomla\Registry;
10
11/**
12 * Abstract Format for Registry
13 *
14 * @since  1.0
15 */
16abstract class AbstractRegistryFormat
17{
18	/**
19	 * @var    array  Format instances container.
20	 * @since  1.0
21	 */
22	protected static $instances = array();
23
24	/**
25	 * Returns a reference to a Format object, only creating it
26	 * if it doesn't already exist.
27	 *
28	 * @param   string  $type  The format to load
29	 *
30	 * @return  AbstractRegistryFormat  Registry format handler
31	 *
32	 * @since   1.0
33	 * @throws  \InvalidArgumentException
34	 */
35	public static function getInstance($type)
36	{
37		// Sanitize format type.
38		$type = strtolower(preg_replace('/[^A-Z0-9_]/i', '', $type));
39
40		// Only instantiate the object if it doesn't already exist.
41		if (!isset(self::$instances[$type]))
42		{
43			$class = '\\Joomla\\Registry\\Format\\' . ucfirst($type);
44
45			if (!class_exists($class))
46			{
47				throw new \InvalidArgumentException('Unable to load format class.', 500);
48			}
49
50			self::$instances[$type] = new $class;
51		}
52
53		return self::$instances[$type];
54	}
55
56	/**
57	 * Converts an object into a formatted string.
58	 *
59	 * @param   object  $object   Data Source Object.
60	 * @param   array   $options  An array of options for the formatter.
61	 *
62	 * @return  string  Formatted string.
63	 *
64	 * @since   1.0
65	 */
66	abstract public function objectToString($object, $options = null);
67
68	/**
69	 * Converts a formatted string into an object.
70	 *
71	 * @param   string  $data     Formatted string
72	 * @param   array   $options  An array of options for the formatter.
73	 *
74	 * @return  object  Data Object
75	 *
76	 * @since   1.0
77	 */
78	abstract public function stringToObject($data, array $options = array());
79}