1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: *
6: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: */
11:
12: namespace Nette\Application;
13:
14: use Nette;
15:
16:
17:
18: /**
19: * Lazy encapsulation of PresenterComponent::link().
20: * Do not instantiate directly, use PresenterComponent::lazyLink()
21: *
22: * @author David Grudl
23: */
24: class Link extends Nette\Object
25: {
26: /** @var PresenterComponent */
27: private $component;
28:
29: /** @var string */
30: private $destination;
31:
32: /** @var array */
33: private $params;
34:
35:
36: /**
37: * Link specification.
38: * @param PresenterComponent
39: * @param string
40: * @param array
41: */
42: public function __construct(PresenterComponent $component, $destination, array $params)
43: {
44: $this->component = $component;
45: $this->destination = $destination;
46: $this->params = $params;
47: }
48:
49:
50:
51: /**
52: * Returns link destination.
53: * @return string
54: */
55: public function getDestination()
56: {
57: return $this->destination;
58: }
59:
60:
61:
62: /**
63: * Changes link parameter.
64: * @param string
65: * @param mixed
66: * @return Link provides a fluent interface
67: */
68: public function setParam($key, $value)
69: {
70: $this->params[$key] = $value;
71: return $this;
72: }
73:
74:
75:
76: /**
77: * Returns link parameter.
78: * @param string
79: * @return mixed
80: */
81: public function getParam($key)
82: {
83: return isset($this->params[$key]) ? $this->params[$key] : NULL;
84: }
85:
86:
87:
88: /**
89: * Returns link parameters.
90: * @return array
91: */
92: public function getParams()
93: {
94: return $this->params;
95: }
96:
97:
98:
99: /**
100: * Converts link to URL.
101: * @return string
102: */
103: public function __toString()
104: {
105: try {
106: return $this->component->link($this->destination, $this->params);
107:
108: } catch (\Exception $e) {
109: Nette\Debug::toStringException($e);
110: }
111: }
112:
113: }
114: