Skip to content
Snippets Groups Projects
Commit 901424a9 authored by Diego Restrepo's avatar Diego Restrepo Committed by Matthew Grasmick
Browse files

Issue #3295036: Automated Drupal 10 compatibility fixes

parent d4482950
No related branches found
No related tags found
2 merge requests!19Issue #3344114: Resolve PHPCS issues,!11Issue #3295036: Automated Drupal 10 compatibility fixes
......@@ -21,8 +21,8 @@
}
},
"require": {
"drupal/core": "^8 || ^9",
"league/csv": "^9.1"
"drupal/core": "^8 || ^9 || ^10",
"league/csv": "^9.7"
},
"require-dev": {
"drupal/coder": "^8.3",
......
......@@ -2,7 +2,7 @@ name: 'Serialization (CSV)'
type: module
description: 'Provides CSV as a serialization format.'
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^8 || ^9 || ^10
package: Web services
dependencies:
- drupal:serialization (>=8.0.4)
<?php
use League\Csv\Writer;
/**
* @file
* Install file for module.
*/
use League\Csv\Writer;
/**
* Implements hook_requirements().
*
* @param $phase
*
* @return array
*/
function csv_serialization_requirements($phase) {
$requirements = [];
......
......@@ -2,16 +2,13 @@
namespace Drupal\csv_serialization\Encoder;
use Exception;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use League\Csv\Writer;
use League\Csv\Reader;
use SplTempFileObject;
use Drupal\Component\Utility\Html;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use League\Csv\ByteSequence;
use League\Csv\CharsetConverter;
/**
* Adds CSV encoder support for the Serialization API.
......@@ -143,7 +140,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface {
try {
// Instantiate CSV writer with options.
$csv = Writer::createFromFileObject(new SplTempFileObject());
$csv = Writer::createFromFileObject(new \SplTempFileObject());
$csv->setDelimiter($this->delimiter);
$csv->setEnclosure($this->enclosure);
$csv->setEscape($this->escapeChar);
......@@ -167,11 +164,11 @@ class CsvEncoder implements EncoderInterface, DecoderInterface {
$csv->insertOne($row);
}
}
$output = $csv->getContent();
$output = $csv->toString();
return trim($output);
}
catch (Exception $e) {
catch (\Exception $e) {
throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
}
}
......@@ -255,12 +252,12 @@ class CsvEncoder implements EncoderInterface, DecoderInterface {
return implode('|', $data);
}
$cell_value = "";
foreach ($data as $item) {
$cell_value .= '|' . (is_array($item) ? $this->flattenCell($item) : $item);
}
$cell_value = "";
foreach ($data as $item) {
$cell_value .= '|' . (is_array($item) ? $this->flattenCell($item) : $item);
}
return trim($cell_value, '|');
return trim($cell_value, '|');
}
/**
......@@ -284,12 +281,13 @@ class CsvEncoder implements EncoderInterface, DecoderInterface {
return $value;
}
/**
* {@inheritdoc}
* @throws \League\Csv\Exception
* @throws \League\Csv\Exception
* @throws \League\Csv\Exception
*/
/**
* {@inheritdoc}
*
* @throws \League\Csv\Exception
* @throws \League\Csv\Exception
* @throws \League\Csv\Exception
*/
public function decode($data, $format, array $context = []) {
$csv = Reader::createFromString($data);
$csv->setDelimiter($this->delimiter);
......@@ -383,7 +381,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface {
$this->enclosure = $settings['enclosure'];
$this->escapeChar = $settings['escape_char'];
$this->useUtf8Bom = ($settings['encoding'] === 'utf8' && !empty($settings['utf8_bom']));
$this->newline = isset($settings['new_line']) ? $settings['new_line'] : NULL;
$this->newline = $settings['new_line'] ?? NULL;
$this->stripTags = $settings['strip_tags'];
$this->trimValues = $settings['trim'];
if (array_key_exists('output_header', $settings)) {
......
......@@ -3,8 +3,8 @@
namespace Drupal\csv_serialization\EventSubscriber;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
/**
* Event subscriber for adding CSV content types to the request.
......@@ -14,10 +14,10 @@ class CsvSubscriber implements EventSubscriberInterface {
/**
* Register content type formats on the request object.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
* The Event to process.
*/
public function onKernelRequest(GetResponseEvent $event) {
public function onKernelRequest(RequestEvent $event) {
$event->getRequest()->setFormat('csv', ['text/csv']);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment