PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Nette/Application/Link.php

https://github.com/vrana/nette
PHP | 125 lines | 39 code | 29 blank | 57 comment | 0 complexity | 45e7fabf3eabfd1b7a0e7e3a4835494e MD5 | raw file
  1. <?php
  2. /**
  3. * Nette Framework
  4. *
  5. * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  6. *
  7. * This source file is subject to the "Nette license" that is bundled
  8. * with this package in the file license.txt.
  9. *
  10. * For more information please see http://nettephp.com
  11. *
  12. * @copyright Copyright (c) 2004, 2009 David Grudl
  13. * @license http://nettephp.com/license Nette license
  14. * @link http://nettephp.com
  15. * @category Nette
  16. * @package Nette\Application
  17. */
  18. /*namespace Nette\Application;*/
  19. require_once dirname(__FILE__) . '/../Object.php';
  20. /**
  21. * Lazy encapsulation of PresenterComponent::link().
  22. * Do not instantiate directly, use PresenterComponent::lazyLink()
  23. *
  24. * @author David Grudl
  25. * @copyright Copyright (c) 2004, 2009 David Grudl
  26. * @package Nette\Application
  27. */
  28. class Link extends /*Nette\*/Object
  29. {
  30. /** @var PresenterComponent */
  31. private $component;
  32. /** @var string */
  33. private $destination;
  34. /** @var array */
  35. private $params;
  36. /**
  37. * Link specification.
  38. * @param PresenterComponent
  39. * @param string
  40. * @param array
  41. */
  42. public function __construct(PresenterComponent $component, $destination, array $params)
  43. {
  44. $this->component = $component;
  45. $this->destination = $destination;
  46. $this->params = $params;
  47. }
  48. /**
  49. * Returns link destination.
  50. * @return string
  51. */
  52. public function getDestination()
  53. {
  54. return $this->destination;
  55. }
  56. /**
  57. * Changes link parameter.
  58. * @param string
  59. * @param mixed
  60. * @return void
  61. */
  62. public function setParam($key, $value)
  63. {
  64. $this->params[$key] = $value;
  65. }
  66. /**
  67. * Returns link parameter.
  68. * @param string
  69. * @return mixed
  70. */
  71. public function getParam($key)
  72. {
  73. return isset($this->params[$key]) ? $this->params[$key] : NULL;
  74. }
  75. /**
  76. * Returns link parameters.
  77. * @return array
  78. */
  79. public function getParams()
  80. {
  81. return $this->params;
  82. }
  83. /**
  84. * Converts link to URL.
  85. * @return string
  86. */
  87. public function __toString()
  88. {
  89. try {
  90. return $this->component->link($this->destination, $this->params);
  91. } catch (/*\*/Exception $e) {
  92. trigger_error($e->getMessage(), E_USER_WARNING);
  93. return '';
  94. }
  95. }
  96. }