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

/application/libs/Nette/Application/UI/Link.php

https://bitbucket.org/pavoleichler/2013_erichseemann_vypestujdobro
PHP | 117 lines | 40 code | 27 blank | 50 comment | 0 complexity | 72fdbc3779ef76e07ee3e16e88f2365d MD5 | raw file
  1. <?php
  2. /**
  3. * This file is part of the Nette Framework (http://nette.org)
  4. *
  5. * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  6. *
  7. * For the full copyright and license information, please view
  8. * the file license.txt that was distributed with this source code.
  9. */
  10. namespace Nette\Application\UI;
  11. use Nette;
  12. /**
  13. * Lazy encapsulation of PresenterComponent::link().
  14. * Do not instantiate directly, use PresenterComponent::lazyLink()
  15. *
  16. * @author David Grudl
  17. * @internal
  18. *
  19. * @property-read string $destination
  20. * @property-read array $parameters
  21. */
  22. class Link extends Nette\Object
  23. {
  24. /** @var PresenterComponent */
  25. private $component;
  26. /** @var string */
  27. private $destination;
  28. /** @var array */
  29. private $params;
  30. /**
  31. * Link specification.
  32. * @param PresenterComponent
  33. * @param string
  34. * @param array
  35. */
  36. public function __construct(PresenterComponent $component, $destination, array $params)
  37. {
  38. $this->component = $component;
  39. $this->destination = $destination;
  40. $this->params = $params;
  41. }
  42. /**
  43. * Returns link destination.
  44. * @return string
  45. */
  46. public function getDestination()
  47. {
  48. return $this->destination;
  49. }
  50. /**
  51. * Changes link parameter.
  52. * @param string
  53. * @param mixed
  54. * @return Link provides a fluent interface
  55. */
  56. public function setParameter($key, $value)
  57. {
  58. $this->params[$key] = $value;
  59. return $this;
  60. }
  61. /**
  62. * Returns link parameter.
  63. * @param string
  64. * @return mixed
  65. */
  66. public function getParameter($key)
  67. {
  68. return isset($this->params[$key]) ? $this->params[$key] : NULL;
  69. }
  70. /**
  71. * Returns link parameters.
  72. * @return array
  73. */
  74. public function getParameters()
  75. {
  76. return $this->params;
  77. }
  78. /**
  79. * Converts link to URL.
  80. * @return string
  81. */
  82. public function __toString()
  83. {
  84. try {
  85. return $this->component->link($this->destination, $this->params);
  86. } catch (\Exception $e) {
  87. Nette\Diagnostics\Debugger::toStringException($e);
  88. }
  89. }
  90. }