/**
  * {@inheritdoc}
  */
 public function normalize($object, $format = null, array $context = [])
 {
     $type = $context['type'];
     $formatType = $context[FormatterProvider::FORMAT_TYPE];
     $formatter = $this->formatterProvider->getFormatterFor($formatType, $type);
     return $formatter->formatType($object, $type);
 }
 public function testGetFormatterFor()
 {
     $testTypeFormatter = new \stdClass();
     $this->setContainerMock('test_formatter', $testTypeFormatter);
     $this->assertEquals($testTypeFormatter, $this->formatter->getFormatterFor('test_format_type', 'test_type'));
     // test already created formatter will be stored in provider
     $this->assertEquals($testTypeFormatter, $this->formatter->getFormatterFor('test_format_type', 'test_type'));
     $this->setExpectedException('Oro\\Bundle\\ImportExportBundle\\Exception\\InvalidArgumentException', 'No available formatters for "non_exist_type" format_type and "test_type" data_type.');
     $this->formatter->getFormatterFor('non_exist_type', 'test_type');
 }
Esempio n. 3
0
 public function testGetFormatterFor()
 {
     $testTypeFormatter = new \stdClass();
     $this->setContainerMock('test_formatter', $testTypeFormatter);
     $this->assertEquals($testTypeFormatter, $this->formatter->getFormatterFor('test_format_type', 'test_type'));
     // test already created formatter will be stored in provider
     $this->assertEquals($testTypeFormatter, $this->formatter->getFormatterFor('test_format_type', 'test_type'));
     // test not exists formatter
     $this->assertNull($this->formatter->getFormatterFor('non_exist_type', 'test_type'));
 }
 /**
  * @param string $type
  *
  * @return TypeFormatterInterface
  */
 protected function getFormatterForType($type)
 {
     $formatType = $this->context->getOption(FormatterProvider::FORMAT_TYPE);
     if (isset($this->formatters[$formatType][$type])) {
         return $this->formatters[$formatType][$type];
     }
     $formatter = $this->formatterProvider->getFormatterFor($formatType, $type);
     $this->formatters[$formatType][$type] = $formatter;
     return $formatter;
 }