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 (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  7. 7:  *
  8. 8:  * This source file is subject to the "Nette license" that is bundled
  9. 9:  * with this package in the file license.txt.
  10. 10:  *
  11. 11:  * For more information please see http://nettephp.com
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    http://nettephp.com/license  Nette license
  15. 15:  * @link       http://nettephp.com
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Application
  18. 18:  */
  19. 19:  
  20. 20:  
  21. 21:  
  22. 22: require_once dirname(__FILE__'/../Object.php';
  23. 23:  
  24. 24:  
  25. 25:  
  26. 26: /**
  27. 27:  * Lazy encapsulation of PresenterComponent::link().
  28. 28:  * Do not instantiate directly, use PresenterComponent::lazyLink()
  29. 29:  *
  30. 30:  * @author     David Grudl
  31. 31:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  32. 32:  * @package    Nette\Application
  33. 33:  */
  34. 34: class Link extends Object
  35. 35: {
  36. 36:     /** @var PresenterComponent */
  37. 37:     private $component;
  38. 38:  
  39. 39:     /** @var string */
  40. 40:     private $destination;
  41. 41:  
  42. 42:     /** @var array */
  43. 43:     private $params;
  44. 44:  
  45. 45:  
  46. 46:     /**
  47. 47:      * Link specification.
  48. 48:      * @param  PresenterComponent 
  49. 49:      * @param  string 
  50. 50:      * @param  array 
  51. 51:      */
  52. 52:     public function __construct(PresenterComponent $component$destinationarray $params)
  53. 53:     {
  54. 54:         $this->component $component;
  55. 55:         $this->destination $destination;
  56. 56:         $this->params $params;
  57. 57:     }
  58. 58:  
  59. 59:  
  60. 60:  
  61. 61:     /**
  62. 46: /**
  63. 47:      * Returns link destination.
  64. 48:      * @return string 
  65. 64:      */
  66. 65:     public function getDestination()
  67. 66:     {
  68. 67:         return $this->destination;
  69. 68:     }
  70. 69:  
  71. 70:  
  72. 71:  
  73. 72:     /**
  74. 73:      * Changes link parameter.
  75. 74:      * @param  string 
  76. 75:      * @param  mixed 
  77. 76:      * @return Link  provides a fluent interface
  78. 77:      */
  79. 78:     public function setParam($key$value)
  80. 79:     {
  81. 80:         $this->params[$key$value;
  82. 81:         return $this;
  83. 82:     }
  84. 83:  
  85. 84:  
  86. 85:  
  87. 86:     /**
  88. 87:      * Returns link parameter.
  89. 88:      * @param  string 
  90. 89:      * @return mixed 
  91. 90:      */
  92. 91:     public function getParam($key)
  93. 92:     {
  94. 93:         return isset($this->params[$key]$this->params[$keyNULL;
  95. 94:     }
  96. 95:  
  97. 96:  
  98. 97:  
  99. 98:     /**
  100. 99:      * Returns link parameters.
  101. 100:      * @return array 
  102. 101:      */
  103. 102:     public function getParams()
  104. 103:     {
  105. 104:         return $this->params;
  106. 105:     }
  107. 106:  
  108. 107:  
  109. 108:  
  110. 109:     /**
  111. 110:      * Converts link to URL.
  112. 111:      * @return string 
  113. 112:      */
  114. 113:     public function __toString()
  115. 114:     {
  116. 115:         try {
  117. 116:             return $this->component->link($this->destination$this->params);
  118. 117:  
  119. 118:         catch (Exception $e{
  120. 119:             trigger_error($e->getMessage()E_USER_WARNING);
  121. 120:             return '';
  122. 121:         }
  123. 122:     }
  124. 123: