More deprecations fixes
This commit is contained in:
parent
7517e5c4de
commit
64a09a748d
@ -3,6 +3,9 @@
|
|||||||
namespace Box\Spout\Reader\CSV;
|
namespace Box\Spout\Reader\CSV;
|
||||||
|
|
||||||
use Box\Spout\Common\Exception\IOException;
|
use Box\Spout\Common\Exception\IOException;
|
||||||
|
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
|
||||||
|
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||||
|
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
|
||||||
use Box\Spout\Reader\Common\Entity\Options;
|
use Box\Spout\Reader\Common\Entity\Options;
|
||||||
use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
|
use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
|
||||||
use Box\Spout\Reader\ReaderAbstract;
|
use Box\Spout\Reader\ReaderAbstract;
|
||||||
@ -22,6 +25,23 @@ class Reader extends ReaderAbstract
|
|||||||
/** @var string Original value for the "auto_detect_line_endings" INI value */
|
/** @var string Original value for the "auto_detect_line_endings" INI value */
|
||||||
protected $originalAutoDetectLineEndings;
|
protected $originalAutoDetectLineEndings;
|
||||||
|
|
||||||
|
/** @var bool Whether the code is running with PHP >= 8.1 */
|
||||||
|
private $isRunningAtLeastPhp81;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param OptionsManagerInterface $optionsManager
|
||||||
|
* @param GlobalFunctionsHelper $globalFunctionsHelper
|
||||||
|
* @param InternalEntityFactoryInterface $entityFactory
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
OptionsManagerInterface $optionsManager,
|
||||||
|
GlobalFunctionsHelper $globalFunctionsHelper,
|
||||||
|
InternalEntityFactoryInterface $entityFactory
|
||||||
|
) {
|
||||||
|
parent::__construct($optionsManager, $globalFunctionsHelper, $entityFactory);
|
||||||
|
$this->isRunningAtLeastPhp81 = \version_compare(PHP_VERSION, '8.1.0') >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the field delimiter for the CSV.
|
* Sets the field delimiter for the CSV.
|
||||||
* Needs to be called before opening the reader.
|
* Needs to be called before opening the reader.
|
||||||
@ -84,8 +104,11 @@ class Reader extends ReaderAbstract
|
|||||||
*/
|
*/
|
||||||
protected function openReader($filePath)
|
protected function openReader($filePath)
|
||||||
{
|
{
|
||||||
|
// "auto_detect_line_endings" is deprecated in PHP 8.1
|
||||||
|
if (!$this->isRunningAtLeastPhp81) {
|
||||||
$this->originalAutoDetectLineEndings = \ini_get('auto_detect_line_endings');
|
$this->originalAutoDetectLineEndings = \ini_get('auto_detect_line_endings');
|
||||||
\ini_set('auto_detect_line_endings', '1');
|
\ini_set('auto_detect_line_endings', '1');
|
||||||
|
}
|
||||||
|
|
||||||
$this->filePointer = $this->globalFunctionsHelper->fopen($filePath, 'r');
|
$this->filePointer = $this->globalFunctionsHelper->fopen($filePath, 'r');
|
||||||
if (!$this->filePointer) {
|
if (!$this->filePointer) {
|
||||||
@ -123,6 +146,9 @@ class Reader extends ReaderAbstract
|
|||||||
$this->globalFunctionsHelper->fclose($this->filePointer);
|
$this->globalFunctionsHelper->fclose($this->filePointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "auto_detect_line_endings" is deprecated in PHP 8.1
|
||||||
|
if (!$this->isRunningAtLeastPhp81) {
|
||||||
\ini_set('auto_detect_line_endings', $this->originalAutoDetectLineEndings);
|
\ini_set('auto_detect_line_endings', $this->originalAutoDetectLineEndings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user