Flow   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 31
c 2
b 0
f 0
dl 0
loc 85
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getValues() 0 26 5
A transform() 0 15 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014-2018
6
 * @package MW
7
 * @subpackage View
8
 */
9
10
11
namespace Aimeos\MW\View\Helper\Url;
12
13
14
/**
15
 * View helper class for generating URLs using the Flow URI builder.
16
 *
17
 * @package MW
18
 * @subpackage View
19
 */
20
class Flow
21
	extends \Aimeos\MW\View\Helper\Url\Base
22
	implements \Aimeos\MW\View\Helper\Url\Iface
23
{
24
	private $builder;
25
	private $fixed;
26
27
28
	/**
29
	 * Initializes the URL view helper.
30
	 *
31
	 * @param \Aimeos\MW\View\Iface $view View instance with registered view helpers
32
	 * @param \Neos\Flow\Mvc\Routing\UriBuilder $builder Flow URI builder object
33
	 * @param array $fixed Associative list of fixed parameters that should be available for all routes
34
	 */
35
	public function __construct( $view, \Neos\Flow\Mvc\Routing\UriBuilder $builder, array $fixed )
36
	{
37
		parent::__construct( $view );
38
39
		$this->builder = $builder;
40
		$this->fixed = $fixed;
41
	}
42
43
44
	/**
45
	 * Returns the URL assembled from the given arguments.
46
	 *
47
	 * @param string|null $target Route or page which should be the target of the link (if any)
48
	 * @param string|null $controller Name of the controller which should be part of the link (if any)
49
	 * @param string|null $action Name of the action which should be part of the link (if any)
50
	 * @param array $params Associative list of parameters that should be part of the URL
51
	 * @param array $trailing Trailing URL parts that are not relevant to identify the resource (for pretty URLs)
52
	 * @param array $config Additional configuration parameter per URL
53
	 * @return string Complete URL that can be used in the template
54
	 */
55
	public function transform( string $target = null, string $controller = null, string $action = null,
56
		array $params = [], array $trailing = [], array $config = [] ) : string
57
	{
58
		$params = $this->sanitize( $params );
59
		$values = $this->getValues( $config );
60
61
		$this->builder
62
			->reset()
63
			->setSection( join( '/', $trailing ) )
64
			->setCreateAbsoluteUri( $values['absoluteUri'] )
65
			->setFormat( $values['format'] );
66
67
		$params['node'] = $target;
68
69
		return $this->builder->uriFor( (string) $action, $params + $this->fixed, $controller, $values['package'], $values['subpackage'] );
70
	}
71
72
73
	/**
74
	 * Returns the sanitized configuration values.
75
	 *
76
	 * @param array $config Associative list of key/value pairs
77
	 * @return array Associative list of sanitized key/value pairs
78
	 */
79
	protected function getValues( array $config ) : array
80
	{
81
		$values = array(
82
			'package' => 'Aimeos.Shop',
83
			'subpackage' => null,
84
			'absoluteUri' => false,
85
			'format' => 'html',
86
		);
87
88
		if( isset( $config['package'] ) ) {
89
			$values['package'] = (string) $config['package'];
90
		}
91
92
		if( isset( $config['subpackage'] ) ) {
93
			$values['subpackage'] = (string) $config['subpackage'];
94
		}
95
96
		if( isset( $config['absoluteUri'] ) ) {
97
			$values['absoluteUri'] = (bool) $config['absoluteUri'];
98
		}
99
100
		if( isset( $config['format'] ) ) {
101
			$values['format'] = (string) $config['format'];
102
		}
103
104
		return $values;
105
	}
106
}
107