CoreFiles by mySites.guru
Autoconfigurable.php100 lines, 2,250 bytes, from Joomla_4.0.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 3.10.0-alpha9
md5
fda279c78b0eb4ca38f1066d5e817688
sha1
a61e73630c927b62535d131d578981fb1366fb5f
sha256
39d33ebaa132ec6b2ce9fcf0347abcf86f954eac5c0428880fb5c007ef2aa949
<?php
/**
 * Joomla! Content Management System
 *
 * @copyright  Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE
 */

namespace Joomla\CMS\Application;

defined('JPATH_PLATFORM') or die;

use Joomla\Registry\Registry;

/**
 * Trait for application classes which can automatically retrieve the global configuration
 *
 * @since  4.0
 */
trait Autoconfigurable
{
	/**
	 * Method to load a PHP configuration class file based on convention and return the instantiated data object.
	 *
	 * @param   string  $file   The path and filename of the configuration file. If not provided, configuration.php
	 *                          in JPATH_CONFIGURATION will be used.
	 * @param   string  $class  The class name to instantiate.
	 *
	 * @return  mixed   Either an array or object to be loaded into the configuration object.
	 *
	 * @since   4.0
	 * @throws  \RuntimeException
	 */
	protected function fetchConfigurationData($file = '', $class = 'JConfig')
	{
		// Instantiate variables.
		$config = [];

		if (empty($file))
		{
			$file = JPATH_CONFIGURATION . '/configuration.php';

			// Applications can choose not to have any configuration data by not implementing this method and not having a config file.
			if (!file_exists($file))
			{
				$file = '';
			}
		}

		if (!empty($file))
		{
			\JLoader::register($class, $file);

			if (!class_exists($class))
			{
				throw new \RuntimeException('Configuration class does not exist.');
			}

			$config = new $class;
		}

		return $config;
	}

	/**
	 * Retrieve the application configuration object.
	 *
	 * @return  Registry
	 *
	 * @since   4.0
	 */
	public function getConfig()
	{
		return $this->config;
	}

	/**
	 * Load an object or array into the application configuration object.
	 *
	 * @param   mixed  $data  Either an array or object to be loaded into the configuration object.
	 *
	 * @return  $this
	 *
	 * @since   4.0
	 */
	public function loadConfiguration($data)
	{
		// Load the data into the configuration object.
		if (is_array($data))
		{
			$this->getConfig()->loadArray($data);
		}
		elseif (is_object($data))
		{
			$this->getConfig()->loadObject($data);
		}

		return $this;
	}
}

No other release has this exact content. See every version of this file.