예제 #1
0
 /**
  * Get the serializer service
  *
  * @param View $view view instance from which the serializer should be configured
  *
  * @return JMS\SerializerBundle\Serializer\SerializerInterface
  */
 protected function getSerializer(View $view = null)
 {
     $serializer = $this->container->get('fos_rest.serializer');
     if ($view) {
         $type = $view->getSerializerExclusionStrategy() ?: $this->container->getParameter('fos_rest.serializer.exclusion_strategy.type');
         if ($type) {
             $value = $view->{'getSerializer' . ucfirst($type)}() ?: $this->container->getParameter('fos_rest.serializer.exclusion_strategy.value');
             $serializer->{'set' . ucfirst($type)}($value);
         }
         $callback = $view->getSerializerCallback();
         if ($callback) {
             call_user_func($callback, $this, $serializer);
         }
     }
     return $serializer;
 }