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: * @package Nette\Application
11: */
12:
13:
14:
15: /**
16: * Lazy encapsulation of NPresenterComponent::link().
17: * Do not instantiate directly, use NPresenterComponent::lazyLink()
18: *
19: * @author David Grudl
20: * @package Nette\Application
21: */
22: class NLink extends NObject
23: {
24: /** @var NPresenterComponent */
25: private $component;
26:
27: /** @var string */
28: private $destination;
29:
30: /** @var array */
31: private $params;
32:
33:
34: /**
35: * Link specification.
36: * @param NPresenterComponent
37: * @param string
38: * @param array
39: */
40: public function __construct(NPresenterComponent $component, $destination, array $params)
41: {
42: $this->component = $component;
43: $this->destination = $destination;
44: $this->params = $params;
45: }
46:
47:
48:
49: /**
50: * Returns link destination.
51: * @return string
52: */
53: public function getDestination()
54: {
55: return $this->destination;
56: }
57:
58:
59:
60: /**
61: * Changes link parameter.
62: * @param string
63: * @param mixed
64: * @return NLink provides a fluent interface
65: */
66: public function setParam($key, $value)
67: {
68: $this->params[$key] = $value;
69: return $this;
70: }
71:
72:
73:
74: /**
75: * Returns link parameter.
76: * @param string
77: * @return mixed
78: */
79: public function getParam($key)
80: {
81: return isset($this->params[$key]) ? $this->params[$key] : NULL;
82: }
83:
84:
85:
86: /**
87: * Returns link parameters.
88: * @return array
89: */
90: public function getParams()
91: {
92: return $this->params;
93: }
94:
95:
96:
97: /**
98: * Converts link to URL.
99: * @return string
100: */
101: public function __toString()
102: {
103: try {
104: return $this->component->link($this->destination, $this->params);
105:
106: } catch (Exception $e) {
107: NDebug::toStringException($e);
108: }
109: }
110:
111: }
112: