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