1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2025 |
6
|
|
|
* @package MW |
7
|
|
|
* @subpackage View |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Base\View\Helper\Url; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* View helper class for building URLs using Symfony Router. |
16
|
|
|
* |
17
|
|
|
* @package MW |
18
|
|
|
* @subpackage View |
19
|
|
|
*/ |
20
|
|
|
class Symfony |
21
|
|
|
extends \Aimeos\Base\View\Helper\Url\Base |
22
|
|
|
implements \Aimeos\Base\View\Helper\Url\Iface |
23
|
|
|
{ |
24
|
|
|
private \Symfony\Component\Routing\RouterInterface $router; |
25
|
|
|
private array $fixed; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Initializes the URL view helper. |
30
|
|
|
* |
31
|
|
|
* @param \Aimeos\Base\View\Iface $view View instance with registered view helpers |
32
|
|
|
* @param \Symfony\Component\Routing\RouterInterface $router Symfony Router implementation |
33
|
|
|
* @param array $fixed Fixed parameters that should be added to each URL |
34
|
|
|
*/ |
35
|
|
|
public function __construct( \Aimeos\Base\View\Iface $view, \Symfony\Component\Routing\RouterInterface $router, array $fixed ) |
36
|
|
|
{ |
37
|
|
|
parent::__construct( $view ); |
38
|
|
|
|
39
|
|
|
$this->router = $router; |
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
|
|
|
if( !empty( $trailing ) ) { |
59
|
|
|
$params['trailing'] = join( '_', $trailing ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$params = $this->sanitize( $params ); |
63
|
|
|
$refType = \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_PATH; |
64
|
|
|
|
65
|
|
|
if( isset( $config['absoluteUri'] ) ) { |
66
|
|
|
$refType = \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_URL; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $this->router->generate( $target, $params + $this->fixed, $refType ); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|