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