/**
  * Check if number provided respects the pattern of the localizer.
  * If false, throw an exception.
  * It true, delocalize localized number to the default format
  *
  * @param string $number
  *
  * @throws TransformationFailedException
  *
  * @return string
  */
 public function reverseTransform($number)
 {
     $violations = $this->localizer->validate($number, 'code', $this->options);
     if (null === $violations || 0 === $violations->count()) {
         return $this->localizer->delocalize($number, $this->options);
     }
     throw new TransformationFailedException($violations->get(0)->getMessage());
 }
 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     if (empty($data)) {
         return null;
     }
     $metric = $this->factory->createMetric($context['attribute']->getMetricFamily());
     $metric->setData($this->localizer->localize($data['data'], $context));
     $metric->setUnit($data['unit']);
     return $metric;
 }
 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     if (empty($data)) {
         return null;
     }
     $prices = new ArrayCollection();
     foreach ($data as $priceData) {
         $data = $this->localizer->localize($priceData['data'], $context);
         $prices->add(new $this->productPriceClass($data, $priceData['currency']));
     }
     return $prices;
 }
 function it_returns_null_if_there_is_no_localizer(LocalizerInterface $localizer)
 {
     $localizer->supports('pim_catalog_number')->willReturn(false);
     $this->register($localizer);
     $this->getLocalizer('pim_catalog_number')->shouldReturn(null);
 }
 /**
  * Convert a localized attribute
  *
  * @param LocalizerInterface $localizer
  * @param array              $item
  * @param array              $options
  * @param string             $path
  *
  * @return array
  */
 protected function convertToDefaultFormat(LocalizerInterface $localizer, array $item, array $options, $path)
 {
     $violations = $localizer->validate($item['data'], $path, $options);
     if (null !== $violations) {
         $this->violations->addAll($violations);
     }
     $item['data'] = $localizer->delocalize($item['data'], $options);
     return $item;
 }
 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     return '' === $data ? null : $this->localizer->localize($data, $context);
 }