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

/www/libs/nette-dev/Application/Link.php

https://github.com/bazo/Mokuji
PHP | 111 lines | 38 code | 25 blank | 48 comment | 0 complexity | c34f2e84464b2d443dac7e6264d853fc MD5 | raw file
Possible License(s): BSD-3-Clause, MIT
  1. <?php
  2. /**
  3. * Nette Framework
  4. *
  5. * @copyright Copyright (c) 2004, 2010 David Grudl
  6. * @license http://nettephp.com/license Nette license
  7. * @link http://nettephp.com
  8. * @category Nette
  9. * @package Nette\Application
  10. */
  11. /**
  12. * Lazy encapsulation of PresenterComponent::link().
  13. * Do not instantiate directly, use PresenterComponent::lazyLink()
  14. *
  15. * @copyright Copyright (c) 2004, 2010 David Grudl
  16. * @package Nette\Application
  17. */
  18. class Link extends Object
  19. {
  20. /** @var PresenterComponent */
  21. private $component;
  22. /** @var string */
  23. private $destination;
  24. /** @var array */
  25. private $params;
  26. /**
  27. * Link specification.
  28. * @param PresenterComponent
  29. * @param string
  30. * @param array
  31. */
  32. public function __construct(PresenterComponent $component, $destination, array $params)
  33. {
  34. $this->component = $component;
  35. $this->destination = $destination;
  36. $this->params = $params;
  37. }
  38. /**
  39. * Returns link destination.
  40. * @return string
  41. */
  42. public function getDestination()
  43. {
  44. return $this->destination;
  45. }
  46. /**
  47. * Changes link parameter.
  48. * @param string
  49. * @param mixed
  50. * @return Link provides a fluent interface
  51. */
  52. public function setParam($key, $value)
  53. {
  54. $this->params[$key] = $value;
  55. return $this;
  56. }
  57. /**
  58. * Returns link parameter.
  59. * @param string
  60. * @return mixed
  61. */
  62. public function getParam($key)
  63. {
  64. return isset($this->params[$key]) ? $this->params[$key] : NULL;
  65. }
  66. /**
  67. * Returns link parameters.
  68. * @return array
  69. */
  70. public function getParams()
  71. {
  72. return $this->params;
  73. }
  74. /**
  75. * Converts link to URL.
  76. * @return string
  77. */
  78. public function __toString()
  79. {
  80. try {
  81. return $this->component->link($this->destination, $this->params);
  82. } catch (Exception $e) {
  83. Debug::toStringException($e);
  84. }
  85. }
  86. }