PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/libs/Nette/Application/Link.php

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