Zend   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 27 5
A __construct() 0 6 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2014-2018
7
 * @package MW
8
 * @subpackage View
9
 */
10
11
12
namespace Aimeos\MW\View\Helper\Url;
13
14
15
/**
16
 * View helper class for building URLs using Zend Router.
17
 *
18
 * @package MW
19
 * @subpackage View
20
 */
21
class Zend
22
	extends \Aimeos\MW\View\Helper\Base
23
	implements \Aimeos\MW\View\Helper\Iface
24
{
25
	private $router;
26
	private $serverUrl;
27
28
29
	/**
30
	 * Initializes the URL view helper.
31
	 *
32
	 * @param \Aimeos\MW\View\Iface $view View instance with registered view helpers
33
	 * @param \Zend_Controller_Router_Interface $router Zend Router implementation
34
	 * @param string $serverUrl Url of the server including scheme, host and port
35
	 */
36
	public function __construct( $view, \Zend_Controller_Router_Interface $router, $serverUrl )
0 ignored issues
show
Bug introduced by
The type Zend_Controller_Router_Interface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
	{
38
		parent::__construct( $view );
39
40
		$this->router = $router;
41
		$this->serverUrl = $serverUrl;
42
	}
43
44
45
	/**
46
	 * Returns the URL assembled from the given arguments.
47
	 *
48
	 * @param string|null $target Route or page which should be the target of the link (if any)
49
	 * @param string|null $controller Name of the controller which should be part of the link (if any)
50
	 * @param string|null $action Name of the action which should be part of the link (if any)
51
	 * @param array $params Associative list of parameters that should be part of the URL
52
	 * @param array $trailing Trailing URL parts that are not relevant to identify the resource (for pretty URLs)
53
	 * @param array $config Additional configuration parameter per URL
54
	 * @return string Complete URL that can be used in the template
55
	 */
56
	public function transform( $target = null, $controller = null, $action = null, array $params = [], array $trailing = [], array $config = [] )
57
	{
58
		$paramList = array( 'controller' => $controller, 'action' => $action );
59
60
61
		foreach( $params as $key => $value )
62
		{
63
			// Slashes in URL parameters confuses the router
64
			$paramList[$key] = str_replace( '/', '_', $value );
65
66
			// Arrays are not supported
67
			if( is_array( $value ) ) {
68
				$paramList[$key] = implode( ' ', $value );
69
			}
70
		}
71
72
		if( !empty( $trailing ) ) {
73
			$paramList['trailing'] = str_replace( '/', '_', join( '_', $trailing ) );
74
		}
75
76
		$url = $this->router->assemble( $paramList, $target, true );
77
78
		if( isset( $config['absoluteUri'] ) ) {
79
			$url = $this->serverUrl . $url;
80
		}
81
82
		return $url;
83
	}
84
}