@@ -44,12 +44,12 @@ public function __construct($object, FactoryManagerInterface $manager, AccessInt
44
44
{
45
45
if ( ! is_object ($ object ) )
46
46
{
47
- throw new ValidationException ('Link has to be an object, " ' . gettype ($ object ) . '" given. ' );
47
+ throw new ValidationException ('Link has to be an object or string , " ' . gettype ($ object ) . '" given. ' );
48
48
}
49
49
50
50
if ( ! array_key_exists ('href ' , $ object ) )
51
51
{
52
- throw new ValidationException ('Link must habe a "href" attribute. ' );
52
+ throw new ValidationException ('Link must have a "href" attribute. ' );
53
53
}
54
54
55
55
$ this ->parent = $ parent ;
@@ -58,14 +58,7 @@ public function __construct($object, FactoryManagerInterface $manager, AccessInt
58
58
59
59
$ this ->container = new DataContainer ();
60
60
61
- $ object_vars = get_object_vars ($ object );
62
-
63
- if ( count ($ object_vars ) === 0 )
64
- {
65
- return $ this ;
66
- }
67
-
68
- foreach ($ object_vars as $ name => $ value )
61
+ foreach (get_object_vars ($ object ) as $ name => $ value )
69
62
{
70
63
$ this ->set ($ name , $ value );
71
64
}
@@ -101,7 +94,7 @@ public function get($key)
101
94
*/
102
95
protected function set ($ name , $ link )
103
96
{
104
- if ( $ name === 'meta ' and ! $ this -> parent instanceof ItemInterface )
97
+ if ( $ name === 'meta ' )
105
98
{
106
99
$ this ->container ->set ($ name , $ this ->manager ->getFactory ()->make (
107
100
'Meta ' ,
@@ -111,29 +104,13 @@ protected function set($name, $link)
111
104
return $ this ;
112
105
}
113
106
114
- // from spec: an object ("link object") which can contain the following members:
115
- // - href: a string containing the link's URL.
116
- if ( $ name === 'href ' or ! is_object ($ link ) )
107
+ // every link must be an URL
108
+ if ( ! is_string ($ link ) )
117
109
{
118
- if ( ! is_string ($ link ) )
119
- {
120
- throw new ValidationException ('Link has to be an object or string, " ' . gettype ($ link ) . '" given. ' );
121
- }
122
-
123
- $ this ->container ->set ($ name , strval ($ link ));
124
-
125
- return $ this ;
110
+ throw new ValidationException ('Every link attribute has to be a string, " ' . gettype ($ link ) . '" given. ' );
126
111
}
127
112
128
- // Now $link can only be an object
129
- // Create Link object if needed
130
- if ( ! ($ link instanceof LinkInterface) )
131
- {
132
- $ this ->container ->set ($ name , $ this ->manager ->getFactory ()->make (
133
- 'Link ' ,
134
- [$ link , $ this ->manager , $ this ]
135
- ));
136
- }
113
+ $ this ->container ->set ($ name , strval ($ link ));
137
114
138
115
return $ this ;
139
116
}
0 commit comments