PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Nette/Application/Link.php

https://github.com/DocX/nette
PHP | 126 lines | 40 code | 29 blank | 57 comment | 0 complexity | 25cecf831dc9f41502a72bc4a9ccf796 MD5 | raw file
Possible License(s): BSD-3-Clause
  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 Link provides a fluent interface
  61. */
  62. public function setParam($key, $value)
  63. {
  64. $this->params[$key] = $value;
  65. return $this;
  66. }
  67. /**
  68. * Returns link parameter.
  69. * @param string
  70. * @return mixed
  71. */
  72. public function getParam($key)
  73. {
  74. return isset($this->params[$key]) ? $this->params[$key] : NULL;
  75. }
  76. /**
  77. * Returns link parameters.
  78. * @return array
  79. */
  80. public function getParams()
  81. {
  82. return $this->params;
  83. }
  84. /**
  85. * Converts link to URL.
  86. * @return string
  87. */
  88. public function __toString()
  89. {
  90. try {
  91. return $this->component->link($this->destination, $this->params);
  92. } catch (/*\*/Exception $e) {
  93. trigger_error($e->getMessage(), E_USER_WARNING);
  94. return '';
  95. }
  96. }
  97. }