@@ -44,12 +44,12 @@ public function __construct($object, FactoryManagerInterface $manager, AccessInt
4444 {
4545 if ( ! is_object ($ object ) )
4646 {
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. ' );
4848 }
4949
5050 if ( ! array_key_exists ('href ' , $ object ) )
5151 {
52- throw new ValidationException ('Link must habe a "href" attribute. ' );
52+ throw new ValidationException ('Link must have a "href" attribute. ' );
5353 }
5454
5555 $ this ->parent = $ parent ;
@@ -58,14 +58,7 @@ public function __construct($object, FactoryManagerInterface $manager, AccessInt
5858
5959 $ this ->container = new DataContainer ();
6060
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 )
6962 {
7063 $ this ->set ($ name , $ value );
7164 }
@@ -101,7 +94,7 @@ public function get($key)
10194 */
10295 protected function set ($ name , $ link )
10396 {
104- if ( $ name === 'meta ' and ! $ this -> parent instanceof ItemInterface )
97+ if ( $ name === 'meta ' )
10598 {
10699 $ this ->container ->set ($ name , $ this ->manager ->getFactory ()->make (
107100 'Meta ' ,
@@ -111,29 +104,13 @@ protected function set($name, $link)
111104 return $ this ;
112105 }
113106
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 ) )
117109 {
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. ' );
126111 }
127112
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 ));
137114
138115 return $ this ;
139116 }
0 commit comments