-
-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathLink.php
More file actions
117 lines (91 loc) · 1.92 KB
/
Link.php
File metadata and controls
117 lines (91 loc) · 1.92 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Application\UI;
use Nette;
/**
* Lazy encapsulation of Component::link().
* Do not instantiate directly, use Component::lazyLink()
*/
final class Link
{
use Nette\SmartObject;
/** @var Component */
private $component;
/** @var string */
private $destination;
/** @var array */
private $params;
/**
* Link specification.
*/
public function __construct(Component $component, string $destination, array $params = [])
{
$this->component = $component;
$this->destination = $destination;
$this->params = $params;
}
/**
* Returns link component.
*/
public function getComponent(): Component
{
return $this->component;
}
/**
* Returns link destination.
*/
public function getDestination(): string
{
return $this->destination;
}
/**
* Changes link parameter.
* @return static
*/
public function setParameter(string $key, $value)
{
$this->params[$key] = $value;
return $this;
}
/**
* Returns link parameter.
* @return mixed
*/
public function getParameter(string $key)
{
return $this->params[$key] ?? null;
}
/**
* Returns link parameters.
*/
public function getParameters(): array
{
return $this->params;
}
/**
* Determines whether this links to the current page.
*/
public function isLinkCurrent(): bool
{
return $this->component->isLinkCurrent($this->destination, $this->params);
}
/**
* Converts link to URL.
*/
public function __toString(): string
{
try {
return $this->component->link($this->destination, $this->params);
} catch (\Throwable $e) {
if (func_num_args() || PHP_VERSION_ID >= 70400) {
throw $e;
}
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
return '';
}
}
}