@@ -15,6 +15,36 @@ class Client extends \SocialConnect\Common\ClientAbstract
1515
1616 const VK_API_VERSION = 5.24 ;
1717
18+ /**
19+ * @var Entity\User
20+ */
21+ protected $ entityUser ;
22+
23+ /**
24+ * @var Entity\Audio
25+ */
26+ protected $ entityAudio ;
27+
28+ /**
29+ * @var Entity\Friend
30+ */
31+ protected $ entityFriend ;
32+
33+ /**
34+ * {@inheritdoc}
35+ */
36+ public function __construct ($ appId , $ appSecret , $ accessToken = null )
37+ {
38+ parent ::__construct ($ appId , $ appSecret , $ accessToken );
39+
40+ /**
41+ * Init base entities
42+ */
43+ $ this ->entityUser = new Entity \User ();
44+ $ this ->entityAudio = new Entity \Audio ();
45+ $ this ->entityFriend = new Entity \Friend ();
46+ }
47+
1848 /**
1949 * @var array
2050 */
@@ -129,7 +159,7 @@ public function getUser($id, array $fields = array('id', 'first_name', 'last_nam
129159 if ($ result ) {
130160 $ result = $ result [0 ];
131161
132- return $ this ->getHydrator (new Entity \ User () )->hydrate ($ result );
162+ return $ this ->getHydrator (clone $ this -> entityUser )->hydrate ($ result );
133163 }
134164
135165 return false ;
@@ -162,7 +192,7 @@ public function getUsers(array $ids, array $fields = array('id', 'first_name', '
162192
163193 if ($ result ) {
164194 return new Response \Collection (
165- $ this ->hydrateCollection ($ result , $ this ->getHydrator (new Entity \ User () )),
195+ $ this ->hydrateCollection ($ result , $ this ->getHydrator (clone $ this -> entityUser )),
166196 count ($ result ),
167197 function () {}
168198 );
@@ -202,7 +232,7 @@ public function getFriends($id = null, array $fields = array('first_name', 'last
202232
203233 if ($ result ) {
204234 return new Response \Collection (
205- $ this ->hydrateCollection ($ result ->items , $ this ->getHydrator (new Entity \ Friend () )),
235+ $ this ->hydrateCollection ($ result ->items , $ this ->getHydrator (clone $ this -> entityFriend )),
206236 $ result ->count ,
207237 function () {}
208238 );
@@ -292,12 +322,60 @@ public function getAudio($ownerId)
292322
293323 if ($ result ) {
294324 return new Response \Collection (
295- $ this ->hydrateCollection ($ result ->items , $ this ->getHydrator (new Entity \ Audio () )),
325+ $ this ->hydrateCollection ($ result ->items , $ this ->getHydrator (clone $ this -> entityAudio )),
296326 $ result ->count ,
297327 function () {}
298328 );
299329 }
300330
301331 return false ;
302332 }
333+
334+ /**
335+ * @return Entity\User
336+ */
337+ public function getEntityUser ()
338+ {
339+ return $ this ->entityUser ;
340+ }
341+
342+ /**
343+ * @param Entity\User $entityUser
344+ */
345+ public function setEntityUser (Entity \User $ entityUser )
346+ {
347+ $ this ->entityUser = $ entityUser ;
348+ }
349+
350+ /**
351+ * @return Entity\Audio
352+ */
353+ public function getEntityAudio ()
354+ {
355+ return $ this ->entityAudio ;
356+ }
357+
358+ /**
359+ * @param Entity\Audio $entityAudio
360+ */
361+ public function setEntityAudio (Entity \Audio $ entityAudio )
362+ {
363+ $ this ->entityAudio = $ entityAudio ;
364+ }
365+
366+ /**
367+ * @return Entity\Friend
368+ */
369+ public function getEntityFriend ()
370+ {
371+ return $ this ->entityFriend ;
372+ }
373+
374+ /**
375+ * @param Entity\Friend $entityFriend
376+ */
377+ public function setEntityFriend (Entity \Friend $ entityFriend )
378+ {
379+ $ this ->entityFriend = $ entityFriend ;
380+ }
303381}
0 commit comments