private function linkOrUnlinkResources(array $resources, $user, $follow = false)
{
$matched = false;
foreach ($resources as $key => $objectArray) {
if (!is_array($objectArray)) {
return true;
}
$object = $objectArray['object'];
if ($object instanceof \Exception) {
throw $object;
}
if ($object instanceof Topic) {
$userTopicService = $this->get('user.topic');
if ($follow) {
$userTopicService->followTopic($user, $object);
} else {
$userTopicService->unfollowTopic($user, $object);
}
$matched = true;
continue;
}
}
if ($matched === false) {
throw new InvalidParametersException('Any supported link object not found');
}
}