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

/libraries/fof/hal/link.php

https://github.com/J2MTecnologia/joomla-3.x
PHP | 137 lines | 50 code | 13 blank | 74 comment | 6 complexity | d375b70dd7bfd4f485b121c2c0bf0dd8 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * @package FrameworkOnFramework
  4. * @subpackage hal
  5. * @copyright Copyright (C) 2010 - 2014 Akeeba Ltd. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. defined('FOF_INCLUDED') or die;
  9. /**
  10. * Implementation of the Hypertext Application Language link in PHP.
  11. *
  12. * @package FrameworkOnFramework
  13. * @since 2.1
  14. */
  15. class FOFHalLink
  16. {
  17. /**
  18. * For indicating the target URI. Corresponds with the ’Target IRI’ as
  19. * defined in Web Linking (RFC 5988). This attribute MAY contain a URI
  20. * Template (RFC6570) and in which case, SHOULD be complemented by an
  21. * additional templated attribtue on the link with a boolean value true.
  22. *
  23. * @var string
  24. */
  25. protected $_href = '';
  26. /**
  27. * This attribute SHOULD be present with a boolean value of true when the
  28. * href of the link contains a URI Template (RFC6570).
  29. *
  30. * @var boolean
  31. */
  32. protected $_templated = false;
  33. /**
  34. * For distinguishing between Resource and Link elements that share the
  35. * same relation
  36. *
  37. * @var string
  38. */
  39. protected $_name = null;
  40. /**
  41. * For indicating what the language of the result of dereferencing the link should be.
  42. *
  43. * @var string
  44. */
  45. protected $_hreflang = null;
  46. /**
  47. * For labeling the destination of a link with a human-readable identifier.
  48. *
  49. * @var string
  50. */
  51. protected $_title = null;
  52. /**
  53. * Public constructor of a FOFHalLink object
  54. *
  55. * @param string $href See $this->_href
  56. * @param boolean $templated See $this->_templated
  57. * @param string $name See $this->_name
  58. * @param string $hreflang See $this->_hreflang
  59. * @param string $title See $this->_title
  60. *
  61. * @throws RuntimeException If $href is empty
  62. */
  63. public function __construct($href, $templated = false, $name = null, $hreflang = null, $title = null)
  64. {
  65. if (empty($href))
  66. {
  67. throw new RuntimeException('A HAL link must always have a non-empty href');
  68. }
  69. $this->_href = $href;
  70. $this->_templated = $templated;
  71. $this->_name = $name;
  72. $this->_hreflang = $hreflang;
  73. $this->_title = $title;
  74. }
  75. /**
  76. * Is this a valid link? Checks the existence of required fields, not their
  77. * values.
  78. *
  79. * @return boolean
  80. */
  81. public function check()
  82. {
  83. return !empty($this->_href);
  84. }
  85. /**
  86. * Magic getter for the protected properties
  87. *
  88. * @param string $name The name of the property to retrieve, sans the underscore
  89. *
  90. * @return mixed Null will always be returned if the property doesn't exist
  91. */
  92. public function __get($name)
  93. {
  94. $property = '_' . $name;
  95. if (property_exists($this, $property))
  96. {
  97. return $this->$property;
  98. }
  99. else
  100. {
  101. return null;
  102. }
  103. }
  104. /**
  105. * Magic setter for the protected properties
  106. *
  107. * @param string $name The name of the property to set, sans the underscore
  108. * @param mixed $value The value of the property to set
  109. *
  110. * @return void
  111. */
  112. public function __set($name, $value)
  113. {
  114. if (($name == 'href') && empty($value))
  115. {
  116. return;
  117. }
  118. $property = '_' . $name;
  119. if (property_exists($this, $property))
  120. {
  121. $this->$property = $value;
  122. }
  123. }
  124. }