1 <?php
2 /**
3 * @package FrameworkOnFramework
4 * @subpackage config
5 * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
6 * @license GNU General Public License version 2, or later
7 */
8
9 defined('FOF_INCLUDED') or die();
10
11 /**
12 * Configuration parser for the dispatcher-specific settings
13 *
14 * @package FrameworkOnFramework
15 * @since 2.1
16 */
17 class FOFConfigDomainDispatcher implements FOFConfigDomainInterface
18 {
19 /**
20 * Parse the XML data, adding them to the $ret array
21 *
22 * @param SimpleXMLElement $xml The XML data of the component's configuration area
23 * @param array &$ret The parsed data, in the form of a hash array
24 *
25 * @return void
26 */
27 public function parseDomain(SimpleXMLElement $xml, array &$ret)
28 {
29 // Initialise
30 $ret['dispatcher'] = array();
31
32 // Parse the dispatcher configuration
33 $dispatcherData = $xml->dispatcher;
34
35 // Sanity check
36
37 if (empty($dispatcherData))
38 {
39 return;
40 }
41
42 $options = $xml->xpath('dispatcher/option');
43
44 if (!empty($options))
45 {
46 foreach ($options as $option)
47 {
48 $key = (string) $option['name'];
49 $ret['dispatcher'][$key] = (string) $option;
50 }
51 }
52 }
53
54 /**
55 * Return a configuration variable
56 *
57 * @param string &$configuration Configuration variables (hashed array)
58 * @param string $var The variable we want to fetch
59 * @param mixed $default Default value
60 *
61 * @return mixed The variable's value
62 */
63 public function get(&$configuration, $var, $default)
64 {
65 if (isset($configuration['dispatcher'][$var]))
66 {
67 return $configuration['dispatcher'][$var];
68 }
69 else
70 {
71 return $default;
72 }
73 }
74 }
75