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