Source for file Link.php

Documentation is available at Link.php

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