[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Part of the Joomla Framework Registry Package 4 * 5 * @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE 7 */ 8 9 namespace Joomla\Registry; 10 11 /** 12 * Factory class to fetch Registry objects 13 * 14 * @since 1.5.0 15 */ 16 class Factory 17 { 18 /** 19 * Returns a FormatInterface object, only creating it if it doesn't already exist. 20 * 21 * @param string $type The format to load 22 * @param array $options Additional options to configure the object 23 * 24 * @return FormatInterface Registry format handler 25 * 26 * @since 1.5.0 27 * @throws \InvalidArgumentException 28 */ 29 public static function getFormat($type, array $options = []) 30 { 31 // Sanitize format type. 32 $type = strtolower(preg_replace('/[^A-Z0-9_]/i', '', $type)); 33 34 $localNamespace = __NAMESPACE__ . '\\Format'; 35 $namespace = $options['format_namespace'] ?? $localNamespace; 36 $class = $namespace . '\\' . ucfirst($type); 37 38 if (!class_exists($class)) 39 { 40 // Were we given a custom namespace? If not, there's nothing else we can do 41 if ($namespace === $localNamespace) 42 { 43 throw new \InvalidArgumentException(sprintf('Unable to load format class for type "%s".', $type), 500); 44 } 45 46 $class = $localNamespace . '\\' . ucfirst($type); 47 48 if (!class_exists($class)) 49 { 50 throw new \InvalidArgumentException(sprintf('Unable to load format class for type "%s".', $type), 500); 51 } 52 } 53 54 return new $class; 55 } 56 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |