/**
  * {@inheritdoc}
  */
 public function convert(array $item, array $options = [])
 {
     $standardizedItem = $this->converter->convert($item, $options);
     $delocalizedItem = $this->delocalizer->convertToDefaultFormats($standardizedItem, $options);
     $violations = $this->delocalizer->getViolations();
     if ($violations->count() > 0) {
         throw new DataArrayConversionException('An error occurred during the delocalization of the product.', 0, null, $violations);
     }
     return $delocalizedItem;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if (count($this->remainingItems) > 0) {
         $item = array_shift($this->remainingItems);
         return $item;
     }
     $items = $this->reader->read();
     if (null !== $items) {
         $this->remainingItems = $this->converter->convert($items);
         return $this->read();
     }
     return null;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function write(array $items)
 {
     $exportDirectory = dirname($this->getPath());
     if (!is_dir($exportDirectory)) {
         $this->localFs->mkdir($exportDirectory);
     }
     $flatItems = [];
     foreach ($items as $item) {
         $flatItems[] = $this->arrayConverter->convert($item);
     }
     $parameters = $this->stepExecution->getJobParameters();
     $options = [];
     $options['withHeader'] = $parameters->get('withHeader');
     $this->flatRowBuffer->write($flatItems, $options);
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if (null === $this->yaml) {
         $fileData = $this->getFileData();
         if (null === $fileData) {
             return null;
         }
         $this->yaml = new \ArrayIterator($fileData);
     }
     if ($data = $this->yaml->current()) {
         $this->yaml->next();
         if (null !== $this->stepExecution) {
             $this->stepExecution->incrementSummaryInfo('read_lines');
         }
         try {
             $data = $this->converter->convert($data);
         } catch (DataArrayConversionException $e) {
             $this->skipItemFromConversionException($data, $e);
         }
         return $data;
     }
     // if not used in the context of an ItemStep, the previous read file will be returned
     $this->flush();
     return null;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     $filePath = null;
     if (null === $this->fileIterator) {
         $jobParameters = $this->stepExecution->getJobParameters();
         $filePath = $jobParameters->get('filePath');
         $delimiter = $jobParameters->get('delimiter');
         $enclosure = $jobParameters->get('enclosure');
         $defaultOptions = ['reader_options' => ['fieldDelimiter' => $delimiter, 'fieldEnclosure' => $enclosure]];
         $this->fileIterator = $this->fileIteratorFactory->create($filePath, array_merge($defaultOptions, $this->options));
         $this->fileIterator->rewind();
     }
     $this->fileIterator->next();
     if ($this->fileIterator->valid() && null !== $this->stepExecution) {
         $this->stepExecution->incrementSummaryInfo('read_lines');
     }
     $data = $this->fileIterator->current();
     if (null === $data) {
         return null;
     }
     $headers = $this->fileIterator->getHeaders();
     $countHeaders = count($headers);
     $countData = count($data);
     $this->checkColumnNumber($countHeaders, $countData, $data, $filePath);
     if ($countHeaders > $countData) {
         $missingValuesCount = $countHeaders - $countData;
         $missingValues = array_fill(0, $missingValuesCount, '');
         $data = array_merge($data, $missingValues);
     }
     $item = array_combine($this->fileIterator->getHeaders(), $data);
     try {
         $item = $this->converter->convert($item, $this->getArrayConverterOptions());
     } catch (DataArrayConversionException $e) {
         $this->skipItemFromConversionException($item, $e);
     }
     return $item;
 }
 /**
  * {@inheritdoc}
  */
 public function write(array $items)
 {
     $parameters = $this->stepExecution->getJobParameters();
     $converterOptions = $this->getConverterOptions($parameters);
     $flatItems = [];
     $directory = $this->stepExecution->getJobExecution()->getExecutionContext()->get(JobInterface::WORKING_DIRECTORY_PARAMETER);
     foreach ($items as $item) {
         if ($parameters->has('with_media') && $parameters->get('with_media')) {
             $item = $this->resolveMediaPaths($item, $directory);
         }
         $flatItems[] = $this->arrayConverter->convert($item, $converterOptions);
     }
     $options = [];
     $options['withHeader'] = $parameters->get('withHeader');
     $this->flatRowBuffer->write($flatItems, $options);
 }
 /**
  * {@inheritdoc}
  */
 public function convert(array $productStandard, array $options = [])
 {
     $productStandard['values'] = $this->localizer->convertToLocalizedFormats($productStandard['values'], $options);
     $productFlat = $this->converter->convert($productStandard, $options);
     return $productFlat;
 }