ConfigViewHelper::initializeArguments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * @license GPLv3, http://www.gnu.org/copyleft/gpl.html
5
 * @copyright Aimeos (aimeos.org), 2017
6
 * @package Flow
7
 */
8
9
10
namespace Aimeos\Shop\ViewHelper;
11
12
13
use Neos\FluidAdaptor\Core\ViewHelper\Exception;
14
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
15
16
17
/**
18
 * Aimeos configuration view helper
19
 *
20
 * @package Flow
21
 * @subpackage ViewHelper
22
 */
23
class ConfigViewHelper extends AbstractViewHelper
24
{
25
	protected $escapeChildren = false;
26
27
28
	/**
29
	 * Registers the known arguments
30
	 */
31
	public function initializeArguments()
32
	{
33
		$this->registerArgument( 'key', 'string', 'Configuration key, e.g. client/html/catalog/lists/basket-add' );
34
		$this->registerArgument( 'default', 'mixed', 'Value if no configuration for the given key was found', false );
35
	}
36
37
38
	/**
39
	 * Returns the configuration value for the given key
40
	 *
41
	 * @return mixed Configuration value
42
	 */
43
	public function render()
44
	{
45
		$iface = '\Aimeos\MW\View\Iface';
46
		$view = $this->templateVariableContainer->get( '_aimeos_view' );
47
48
		if( !is_object( $view ) || !( $view instanceof $iface ) ) {
49
			throw new Exception( 'Aimeos view object is missing' );
50
		}
51
52
		if( !isset( $this->arguments['key'] ) ) {
53
			throw new Exception( 'Attribute "key" missing for Aimeos translate view helper' );
54
		}
55
56
		$key = $this->arguments['key'];
57
		$default = ( isset( $this->arguments['default'] ) ? $this->arguments['default'] : null );
58
59
		return $view->config( $key, $default );
60
	}
61
}