- md5
- 0f48d8198be68032a27be043ec0abfa1
- sha1
- ce3a60a68697547ac5caa2ddb02b6cd8de3a4359
- sha256
- 993d4d6063fe7470856a25cbf7b7aeb591785c0179ea3448792e0fd592c3592d
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
<?php
/**
* @package FrameworkOnFramework
* @subpackage config
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2, or later
* @note This file has been modified by the Joomla! Project and no longer reflects the original work of its author.
*/
defined('FOF_INCLUDED') or die();
/**
* Reads and parses the fof.xml file in the back-end of a FOF-powered component,
* provisioning the data to the rest of the FOF framework
*
* @package FrameworkOnFramework
* @since 2.1
*/
class FOFConfigProvider
{
/**
* Cache of FOF components' configuration variables
*
* @var array
*/
public static $configurations = array();
/**
* Parses the configuration of the specified component
*
* @param string $component The name of the component, e.g. com_foobar
* @param boolean $force Force reload even if it's already parsed?
*
* @return void
*/
public function parseComponent($component, $force = false)
{
if (!$force && isset(self::$configurations[$component]))
{
return;
}
if (FOFPlatform::getInstance()->isCli())
{
$order = array('cli', 'backend');
}
elseif (FOFPlatform::getInstance()->isBackend())
{
$order = array('backend');
}
else
{
$order = array('frontend');
}
$order[] = 'common';
$order = array_reverse($order);
self::$configurations[$component] = array();
foreach ($order as $area)
{
$config = $this->parseComponentArea($component, $area);
self::$configurations[$component] = array_merge_recursive(self::$configurations[$component], $config);
}
}
/**
* Returns the value of a variable. Variables use a dot notation, e.g.
* view.config.whatever where the first part is the domain, the rest of the
* parts specify the path to the variable.
*
* @param string $variable The variable name
* @param mixed $default The default value, or null if not specified
*
* @return mixed The value of the variable
*/
public function get($variable, $default = null)
{
static $domains = null;
if (is_null($domains))
{
$domains = $this->getDomains();
}
list($component, $domain, $var) = explode('.', $variable, 3);
if (!isset(self::$configurations[$component]))
{
$this->parseComponent($component);
}
if (!in_array($domain, $domains))
{
return $default;
}
$class = 'FOFConfigDomain' . ucfirst($domain);
$o = new $class;
return $o->get(self::$configurations[$component], $var, $default);
}
/**
* Parses the configuration options of a specific component area
*
* @param string $component Which component's configuration to parse
* @param string $area Which area to parse (frontend, backend, cli)
*
* @return array A hash array with the configuration data
*/
protected function parseComponentArea($component, $area)
{
// Initialise the return array
$ret = array();
// Get the folders of the component
$componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($component);
$filesystem = FOFPlatform::getInstance()->getIntegrationObject('filesystem');
// Check that the path exists
$path = $componentPaths['admin'];
$path = $filesystem->pathCheck($path);
if (!$filesystem->folderExists($path))
{
return $ret;
}
// Read the filename if it exists
$filename = $path . '/fof.xml';
if (!$filesystem->fileExists($filename))
{
return $ret;
}
$data = file_get_contents($filename);
// Load the XML data in a SimpleXMLElement object
$xml = simplexml_load_string($data);
if (!($xml instanceof SimpleXMLElement))
{
return $ret;
}
// Get this area's data
$areaData = $xml->xpath('//' . $area);
if (empty($areaData))
{
return $ret;
}
$xml = array_shift($areaData);
// Parse individual configuration domains
$domains = $this->getDomains();
foreach ($domains as $dom)
{
$class = 'FOFConfigDomain' . ucfirst($dom);
if (class_exists($class, true))
{
$o = new $class;
$o->parseDomain($xml, $ret);
}
}
// Finally, return the result
return $ret;
}
/**
* Gets a list of the available configuration domain adapters
*
* @return array A list of the available domains
*/
protected function getDomains()
{
static $domains = array();
if (empty($domains))
{
$filesystem = FOFPlatform::getInstance()->getIntegrationObject('filesystem');
$files = $filesystem->folderFiles(__DIR__ . '/domain', '.php');
if (!empty($files))
{
foreach ($files as $file)
{
$domain = basename($file, '.php');
if ($domain == 'interface')
{
continue;
}
$domain = preg_replace('/[^A-Za-z0-9]/', '', $domain);
$domains[] = $domain;
}
$domains = array_unique($domains);
}
}
return $domains;
}
}
The same content is in 46 releases, Joomla 3.9.20-rc to 3.10.12. See them all, or every version of this file.