protected function convertObjectTo(ValueObject $object, $type) { $type = strtolower($type); switch ($type) { case 'json': case 'xml': $visitor = $this->getKernel()->getContainer()->get('ezpublish_rest.output.visitor.' . $type); break; default: throw new InvalidArgumentException('rest body type', $type); } return $visitor->visit($object); }