/** * Apply converter on request based on the given configuration. * * @param Request $request * @param ConfigurationInterface $configuration */ protected function applyConverter(Request $request, ConfigurationInterface $configuration) { $value = $request->attributes->get($configuration->getName()); $className = $configuration->getClass(); // If the value is already an instance of the class we are trying to convert it into // we should continue as no conversion is required if (is_object($value) && $value instanceof $className) { return; } if ($converterName = $configuration->getConverter()) { if (!isset($this->namedConverters[$converterName])) { throw new \RuntimeException(sprintf("No converter named '%s' found for conversion of parameter '%s'.", $converterName, $configuration->getName())); } $converter = $this->namedConverters[$converterName]; if (!$converter->supports($configuration)) { throw new \RuntimeException(sprintf("Converter '%s' does not support conversion of parameter '%s'.", $converterName, $configuration->getName())); } $converter->apply($request, $configuration); return; } foreach ($this->all() as $converter) { if ($converter->supports($configuration)) { if ($converter->apply($request, $configuration)) { return; } } } }