Skip to content

Commit

Permalink
Start using Hydrator\CloneObjectMap
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Aug 17, 2014
1 parent e1f1f28 commit e0327b7
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions src/Client.php
Expand Up @@ -68,26 +68,21 @@ public function __construct($appId, $appSecret)
}

/**
* @var \SocialConnect\Common\Hydrator\ObjectMap|null
* @return \SocialConnect\Common\Hydrator\CloneObjectMap
*/
protected $hydrator;

/**
* @return \SocialConnect\Common\Hydrator\ObjectMap
*/
public function getHydrator()
public function getHydrator($object)
{
if (!$this->hydrator) {
return $this->hydrator = new \SocialConnect\Common\Hydrator\ObjectMap(array(
'id' => 'id',
'first_name' => 'firstname',
'last_name' => 'lastname',
'hidden' => 'hidden',
'deactivated' => 'deactivated'
));
}

return $this->hydrator;
/**
* @todo Think more about cache hydrators in class property
*/

return new \SocialConnect\Common\Hydrator\CloneObjectMap(array(
'id' => 'id',
'first_name' => 'firstname',
'last_name' => 'lastname',
'hidden' => 'hidden',
'deactivated' => 'deactivated'
), $object);
}

/**
Expand Down Expand Up @@ -149,7 +144,7 @@ public function getUser($id)
if ($result) {
$result = $result[0];

return $this->getHydrator()->hydrate(new Entity\User(), $result);
return $this->getHydrator(new Entity\User())->hydrate($result);
}

return false;
Expand All @@ -172,7 +167,7 @@ public function getUsers(array $ids)
'uids' => $ids
));

return $this->hydrateCollection($apiResult, $this->getHydrator(), new Entity\User());
return $this->hydrateCollection($apiResult, $this->getHydrator(new Entity\User()));
}

/**
Expand Down Expand Up @@ -206,7 +201,7 @@ public function getFriends($id = null, array $fields = array('first_name', 'last

if ($result) {
return new Response\Collection(
$this->hydrateCollection($result->items, $this->getHydrator(), new Entity\User()),
$this->hydrateCollection($result->items, $this->getHydrator(new Entity\User())),
$result->count,
function() {}
);
Expand All @@ -218,16 +213,15 @@ function() {}
/**
* @param $apiResult
* @param $hydrator
* @param $instance
* @return array|bool
*/
protected function hydrateCollection($apiResult, $hydrator, $instance)
protected function hydrateCollection($apiResult, $hydrator)
{
if ($apiResult && is_array($apiResult)) {
$result = array();

foreach ($apiResult as $row) {
$result[] = $hydrator->hydrate(clone $instance, $row);
$result[] = $hydrator->hydrate($row);
}

return $result;
Expand Down

0 comments on commit e0327b7

Please sign in to comment.