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 https://nette.org
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    https://nette.org/license  Nette license
  15. 15:  * @link       https://nette.org
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Application
  18. 18:  * @version    $Id$
  19. 19:  */
  20. 20:  
  21. 21:  
  22. 22:  
  23. 23: require_once dirname(__FILE__'/../Object.php';
  24. 24:  
  25. 25:  
  26. 26:  
  27. 27: /**
  28. 28:  * Lazy encapsulation of PresenterComponent::link().
  29. 29:  * Do not instantiate directly, use PresenterComponent::lazyLink()
  30. 30:  *
  31. 31:  * @author     David Grudl
  32. 32:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  33. 33:  * @package    Nette\Application
  34. 34:  */
  35. 35: class Link extends Object
  36. 36: {
  37. 37:     /** @var PresenterComponent */
  38. 38:     private $component;
  39. 39:  
  40. 40:     /** @var string */
  41. 41:     private $destination;
  42. 42:  
  43. 43:     /** @var array */
  44. 44:     private $args;
  45. 45:  
  46. 46:  
  47. 47:     /**
  48. 48:      * Link specification.
  49. 49:      * @param  PresenterComponent 
  50. 50:      * @param  string 
  51. 51:      * @param  array 
  52. 52:      */
  53. 53:     public function __construct(PresenterComponent $component$destinationarray $args)
  54. 54:     {
  55. 55:         $this->component $component;
  56. 56:         $this->destination $destination;
  57. 57:         $this->args $args;
  58. 58:     }
  59. 59:  
  60. 60:  
  61. 61:  
  62. 62:     /**
  63. 47: /**
  64. 48:      * Returns link destination.
  65. 49:      * @return string 
  66. 65:      */
  67. 66:     public function getDestination()
  68. 67:     {
  69. 68:         return $this->destination;
  70. 69:     }
  71. 70:  
  72. 71:  
  73. 72:  
  74. 73:     /**
  75. 74:      * Changes link parameter.
  76. 75:      * @param  string 
  77. 76:      * @param  mixed 
  78. 77:      * @return void 
  79. 78:      */
  80. 79:     public function setParam($key$value)
  81. 80:     {
  82. 81:         $this->args[$key$value;
  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->args[$key]$this->args[$keyNULL;
  95. 94:     }
  96. 95:  
  97. 96:  
  98. 97:  
  99. 98:     /**
  100. 99:      * Converts link to URL.
  101. 100:      * @return string 
  102. 101:      */
  103. 102:     public function __toString()
  104. 103:     {
  105. 104:         try {
  106. 105:             return $this->component->link($this->destination$this->args);
  107. 106:  
  108. 107:         catch (Exception $e{
  109. 108:             trigger_error($e->getMessage()E_USER_WARNING);
  110. 109:             return '';
  111. 110:         }
  112. 111:     }
  113. 112: