Browse Source

Passage à Spout 3.0.1

svn/root
real3t@gmail.com 2 years ago
parent
commit
6d8dd85709
  1. 40
      .gitattributes
  2. 24
      comptetraduction_export_fonctions.php
  3. 14
      lib/Spout/Autoloader/Psr4Autoloader.php
  4. 2
      lib/Spout/Autoloader/autoload.php
  5. 38
      lib/Spout/Common/Escaper/CSV.php
  6. 27
      lib/Spout/Common/Escaper/EscaperInterface.php
  7. 66
      lib/Spout/Common/Escaper/ODS.php
  8. 185
      lib/Spout/Common/Escaper/XLSX.php
  9. 3
      lib/Spout/Common/Exception/EncodingConversionException.php
  10. 3
      lib/Spout/Common/Exception/IOException.php
  11. 3
      lib/Spout/Common/Exception/InvalidArgumentException.php
  12. 1
      lib/Spout/Common/Exception/SpoutException.php
  13. 3
      lib/Spout/Common/Exception/UnsupportedTypeException.php
  14. 10
      lib/Spout/Common/Helper/EncodingHelper.php
  15. 14
      lib/Spout/Common/Helper/FileSystemHelper.php
  16. 35
      lib/Spout/Common/Helper/GlobalFunctionsHelper.php
  17. 4
      lib/Spout/Common/Helper/StringHelper.php
  18. 41
      lib/Spout/Common/Singleton.php
  19. 2
      lib/Spout/Common/Type.php
  20. 238
      lib/Spout/Reader/AbstractReader.php
  21. 51
      lib/Spout/Reader/CSV/Reader.php
  22. 110
      lib/Spout/Reader/CSV/ReaderOptions.php
  23. 96
      lib/Spout/Reader/CSV/RowIterator.php
  24. 22
      lib/Spout/Reader/CSV/Sheet.php
  25. 20
      lib/Spout/Reader/CSV/SheetIterator.php
  26. 58
      lib/Spout/Reader/Common/ReaderOptions.php
  27. 6
      lib/Spout/Reader/Common/XMLProcessor.php
  28. 3
      lib/Spout/Reader/Exception/IteratorNotRewindableException.php
  29. 3
      lib/Spout/Reader/Exception/NoSheetsFoundException.php
  30. 1
      lib/Spout/Reader/Exception/ReaderException.php
  31. 3
      lib/Spout/Reader/Exception/ReaderNotOpenedException.php
  32. 3
      lib/Spout/Reader/Exception/SharedStringNotFoundException.php
  33. 2
      lib/Spout/Reader/Exception/XMLProcessingException.php
  34. 2
      lib/Spout/Reader/IteratorInterface.php
  35. 62
      lib/Spout/Reader/ODS/Helper/CellValueFormatter.php
  36. 17
      lib/Spout/Reader/ODS/Helper/SettingsHelper.php
  37. 31
      lib/Spout/Reader/ODS/Reader.php
  38. 14
      lib/Spout/Reader/ODS/ReaderOptions.php
  39. 130
      lib/Spout/Reader/ODS/RowIterator.php
  40. 27
      lib/Spout/Reader/ODS/Sheet.php
  41. 117
      lib/Spout/Reader/ODS/SheetIterator.php
  42. 48
      lib/Spout/Reader/ReaderFactory.php
  43. 6
      lib/Spout/Reader/ReaderInterface.php
  44. 26
      lib/Spout/Reader/SheetInterface.php
  45. 7
      lib/Spout/Reader/Wrapper/XMLInternalErrorsHelper.php
  46. 21
      lib/Spout/Reader/Wrapper/XMLReader.php
  47. 28
      lib/Spout/Reader/XLSX/Helper/CellHelper.php
  48. 183
      lib/Spout/Reader/XLSX/Helper/CellValueFormatter.php
  49. 5
      lib/Spout/Reader/XLSX/Helper/DateFormatHelper.php
  50. 159
      lib/Spout/Reader/XLSX/Helper/SharedStringsCaching/CachingStrategyFactory.php
  51. 44
      lib/Spout/Reader/XLSX/Helper/SharedStringsCaching/CachingStrategyInterface.php
  52. 193
      lib/Spout/Reader/XLSX/Helper/SharedStringsCaching/FileBasedStrategy.php
  53. 83
      lib/Spout/Reader/XLSX/Helper/SharedStringsCaching/InMemoryStrategy.php
  54. 234
      lib/Spout/Reader/XLSX/Helper/SharedStringsHelper.php
  55. 156
      lib/Spout/Reader/XLSX/Helper/SheetHelper.php
  56. 330
      lib/Spout/Reader/XLSX/Helper/StyleHelper.php
  57. 69
      lib/Spout/Reader/XLSX/Reader.php
  58. 33
      lib/Spout/Reader/XLSX/ReaderOptions.php
  59. 132
      lib/Spout/Reader/XLSX/RowIterator.php
  60. 28
      lib/Spout/Reader/XLSX/Sheet.php
  61. 26
      lib/Spout/Reader/XLSX/SheetIterator.php
  62. 119
      lib/Spout/Writer/AbstractMultiSheetsWriter.php
  63. 384
      lib/Spout/Writer/AbstractWriter.php
  64. 45
      lib/Spout/Writer/CSV/Writer.php
  65. 138
      lib/Spout/Writer/Common/Helper/AbstractStyleHelper.php
  66. 48
      lib/Spout/Writer/Common/Helper/CellHelper.php
  67. 82
      lib/Spout/Writer/Common/Helper/ZipHelper.php
  68. 192
      lib/Spout/Writer/Common/Internal/AbstractWorkbook.php
  69. 74
      lib/Spout/Writer/Common/Internal/WorkbookInterface.php
  70. 40
      lib/Spout/Writer/Common/Internal/WorksheetInterface.php
  71. 183
      lib/Spout/Writer/Common/Sheet.php
  72. 2
      lib/Spout/Writer/Exception/Border/InvalidNameException.php
  73. 2
      lib/Spout/Writer/Exception/Border/InvalidStyleException.php
  74. 2
      lib/Spout/Writer/Exception/Border/InvalidWidthException.php
  75. 13
      lib/Spout/Writer/Exception/InvalidColorException.php
  76. 3
      lib/Spout/Writer/Exception/InvalidSheetNameException.php
  77. 3
      lib/Spout/Writer/Exception/SheetNotFoundException.php
  78. 3
      lib/Spout/Writer/Exception/WriterAlreadyOpenedException.php
  79. 1
      lib/Spout/Writer/Exception/WriterException.php
  80. 3
      lib/Spout/Writer/Exception/WriterNotOpenedException.php
  81. 10
      lib/Spout/Writer/ODS/Helper/BorderHelper.php
  82. 76
      lib/Spout/Writer/ODS/Helper/FileSystemHelper.php
  83. 356
      lib/Spout/Writer/ODS/Helper/StyleHelper.php
  84. 119
      lib/Spout/Writer/ODS/Internal/Workbook.php
  85. 233
      lib/Spout/Writer/ODS/Internal/Worksheet.php
  86. 72
      lib/Spout/Writer/ODS/Writer.php
  87. 85
      lib/Spout/Writer/Style/Border.php
  88. 75
      lib/Spout/Writer/Style/BorderBuilder.php
  89. 184
      lib/Spout/Writer/Style/BorderPart.php
  90. 87
      lib/Spout/Writer/Style/Color.php
  91. 426
      lib/Spout/Writer/Style/Style.php
  92. 159
      lib/Spout/Writer/Style/StyleBuilder.php
  93. 48
      lib/Spout/Writer/WriterFactory.php
  94. 60
      lib/Spout/Writer/WriterInterface.php
  95. 24
      lib/Spout/Writer/XLSX/Helper/BorderHelper.php
  96. 127
      lib/Spout/Writer/XLSX/Helper/FileSystemHelper.php
  97. 107
      lib/Spout/Writer/XLSX/Helper/SharedStringsHelper.php
  98. 344
      lib/Spout/Writer/XLSX/Helper/StyleHelper.php
  99. 135
      lib/Spout/Writer/XLSX/Internal/Workbook.php
  100. 275
      lib/Spout/Writer/XLSX/Internal/Worksheet.php

40
.gitattributes

@ -474,10 +474,6 @@ lettres/hr-small.gif -text
lettres/top-arrow.gif -text
lib/Spout/Autoloader/Psr4Autoloader.php -text
lib/Spout/Autoloader/autoload.php -text
lib/Spout/Common/Escaper/CSV.php -text
lib/Spout/Common/Escaper/EscaperInterface.php -text
lib/Spout/Common/Escaper/ODS.php -text
lib/Spout/Common/Escaper/XLSX.php -text
lib/Spout/Common/Exception/EncodingConversionException.php -text
lib/Spout/Common/Exception/IOException.php -text
lib/Spout/Common/Exception/InvalidArgumentException.php -text
@ -487,15 +483,11 @@ lib/Spout/Common/Helper/EncodingHelper.php -text
lib/Spout/Common/Helper/FileSystemHelper.php -text
lib/Spout/Common/Helper/GlobalFunctionsHelper.php -text
lib/Spout/Common/Helper/StringHelper.php -text
lib/Spout/Common/Singleton.php -text
lib/Spout/Common/Type.php -text
lib/Spout/Reader/AbstractReader.php -text
lib/Spout/Reader/CSV/Reader.php -text
lib/Spout/Reader/CSV/ReaderOptions.php -text
lib/Spout/Reader/CSV/RowIterator.php -text
lib/Spout/Reader/CSV/Sheet.php -text
lib/Spout/Reader/CSV/SheetIterator.php -text
lib/Spout/Reader/Common/ReaderOptions.php -text
lib/Spout/Reader/Common/XMLProcessor.php -text
lib/Spout/Reader/Exception/IteratorNotRewindableException.php -text
lib/Spout/Reader/Exception/NoSheetsFoundException.php -text
@ -507,11 +499,9 @@ lib/Spout/Reader/IteratorInterface.php -text
lib/Spout/Reader/ODS/Helper/CellValueFormatter.php -text
lib/Spout/Reader/ODS/Helper/SettingsHelper.php -text
lib/Spout/Reader/ODS/Reader.php -text
lib/Spout/Reader/ODS/ReaderOptions.php -text
lib/Spout/Reader/ODS/RowIterator.php -text
lib/Spout/Reader/ODS/Sheet.php -text
lib/Spout/Reader/ODS/SheetIterator.php -text
lib/Spout/Reader/ReaderFactory.php -text
lib/Spout/Reader/ReaderInterface.php -text
lib/Spout/Reader/SheetInterface.php -text
lib/Spout/Reader/Wrapper/XMLInternalErrorsHelper.php -text
@ -519,32 +509,16 @@ lib/Spout/Reader/Wrapper/XMLReader.php -text
lib/Spout/Reader/XLSX/Helper/CellHelper.php -text
lib/Spout/Reader/XLSX/Helper/CellValueFormatter.php -text
lib/Spout/Reader/XLSX/Helper/DateFormatHelper.php -text
lib/Spout/Reader/XLSX/Helper/SharedStringsCaching/CachingStrategyFactory.php -text
lib/Spout/Reader/XLSX/Helper/SharedStringsCaching/CachingStrategyInterface.php -text
lib/Spout/Reader/XLSX/Helper/SharedStringsCaching/FileBasedStrategy.php -text
lib/Spout/Reader/XLSX/Helper/SharedStringsCaching/InMemoryStrategy.php -text
lib/Spout/Reader/XLSX/Helper/SharedStringsHelper.php -text
lib/Spout/Reader/XLSX/Helper/SheetHelper.php -text
lib/Spout/Reader/XLSX/Helper/StyleHelper.php -text
lib/Spout/Reader/XLSX/Reader.php -text
lib/Spout/Reader/XLSX/ReaderOptions.php -text
lib/Spout/Reader/XLSX/RowIterator.php -text
lib/Spout/Reader/XLSX/Sheet.php -text
lib/Spout/Reader/XLSX/SheetIterator.php -text
lib/Spout/Writer/AbstractMultiSheetsWriter.php -text
lib/Spout/Writer/AbstractWriter.php -text
lib/Spout/Writer/CSV/Writer.php -text
lib/Spout/Writer/Common/Helper/AbstractStyleHelper.php -text
lib/Spout/Writer/Common/Helper/CellHelper.php -text
lib/Spout/Writer/Common/Helper/ZipHelper.php -text
lib/Spout/Writer/Common/Internal/AbstractWorkbook.php -text
lib/Spout/Writer/Common/Internal/WorkbookInterface.php -text
lib/Spout/Writer/Common/Internal/WorksheetInterface.php -text
lib/Spout/Writer/Common/Sheet.php -text
lib/Spout/Writer/Exception/Border/InvalidNameException.php -text
lib/Spout/Writer/Exception/Border/InvalidStyleException.php -text
lib/Spout/Writer/Exception/Border/InvalidWidthException.php -text
lib/Spout/Writer/Exception/InvalidColorException.php -text
lib/Spout/Writer/Exception/InvalidSheetNameException.php -text
lib/Spout/Writer/Exception/SheetNotFoundException.php -text
lib/Spout/Writer/Exception/WriterAlreadyOpenedException.php -text
@ -552,24 +526,10 @@ lib/Spout/Writer/Exception/WriterException.php -text
lib/Spout/Writer/Exception/WriterNotOpenedException.php -text
lib/Spout/Writer/ODS/Helper/BorderHelper.php -text
lib/Spout/Writer/ODS/Helper/FileSystemHelper.php -text
lib/Spout/Writer/ODS/Helper/StyleHelper.php -text
lib/Spout/Writer/ODS/Internal/Workbook.php -text
lib/Spout/Writer/ODS/Internal/Worksheet.php -text
lib/Spout/Writer/ODS/Writer.php -text
lib/Spout/Writer/Style/Border.php -text
lib/Spout/Writer/Style/BorderBuilder.php -text
lib/Spout/Writer/Style/BorderPart.php -text
lib/Spout/Writer/Style/Color.php -text
lib/Spout/Writer/Style/Style.php -text
lib/Spout/Writer/Style/StyleBuilder.php -text
lib/Spout/Writer/WriterFactory.php -text
lib/Spout/Writer/WriterInterface.php -text
lib/Spout/Writer/XLSX/Helper/BorderHelper.php -text
lib/Spout/Writer/XLSX/Helper/FileSystemHelper.php -text
lib/Spout/Writer/XLSX/Helper/SharedStringsHelper.php -text
lib/Spout/Writer/XLSX/Helper/StyleHelper.php -text
lib/Spout/Writer/XLSX/Internal/Workbook.php -text
lib/Spout/Writer/XLSX/Internal/Worksheet.php -text
lib/Spout/Writer/XLSX/Writer.php -text
lib/Spout/version.txt -text
/liste_mail.html -text

24
comptetraduction_export_fonctions.php

@ -2,8 +2,9 @@
require_once find_in_path('lib/Spout/Autoloader/autoload.php');
use Box\Spout\Writer\WriterFactory;
use Box\Spout\Common\Type;
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Common\Entity\Style\Color;
function trad_export_csv($trads) {
@ -14,12 +15,21 @@ function trad_export_csv($trads) {
'Contenu'
);
$writer = WriterFactory::create(Type::XLSX); // for XLSX files
$writer->openToBrowser('traduction'); // stream data directly to the browser
$defaultStyle = (new StyleBuilder())
->setFontName('Arial')
->setFontSize(11)
->build();
$writer = WriterEntityFactory::createXLSXWriter(); // for XLSX files
$writer->addRow($entetes); // add a row at a time
$writer->addRows($trads); // add multiple rows at a time
$writer->openToBrowser('traduction.xlsx'); // stream data directly to the browser
$writer->addRow(WriterEntityFactory::createRowFromArray($entetes, $defaultStyle)); // add a row at a time
foreach ($trads as $trad) {
$writer->addRow(WriterEntityFactory::createRowFromArray($trad, $defaultStyle));
}
$writer->close();
}

14
lib/Spout/Autoloader/Psr4Autoloader.php

@ -5,8 +5,6 @@ namespace Box\Spout\Autoloader;
/**
* Class Psr4Autoloader
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md#class-example
*
* @package Box\Spout\Autoloader
*/
class Psr4Autoloader
{
@ -16,7 +14,7 @@ class Psr4Autoloader
*
* @var array
*/
protected $prefixes = array();
protected $prefixes = [];
/**
* Register loader with SPL autoloader stack.
@ -25,7 +23,7 @@ class Psr4Autoloader
*/
public function register()
{
spl_autoload_register(array($this, 'loadClass'));
spl_autoload_register([$this, 'loadClass']);
}
/**
@ -49,7 +47,7 @@ class Psr4Autoloader
// initialize the namespace prefix array
if (isset($this->prefixes[$prefix]) === false) {
$this->prefixes[$prefix] = array();
$this->prefixes[$prefix] = [];
}
// retain the base directory for the namespace prefix
@ -74,8 +72,7 @@ class Psr4Autoloader
// work backwards through the namespace names of the fully-qualified
// class name to find a mapped file name
while (false !== $pos = strrpos($prefix, '\\')) {
while (($pos = strrpos($prefix, '\\')) !== false) {
// retain the trailing namespace separator in the prefix
$prefix = substr($class, 0, $pos + 1);
@ -114,7 +111,6 @@ class Psr4Autoloader
// look through base directories for this namespace prefix
foreach ($this->prefixes[$prefix] as $baseDir) {
// replace the namespace prefix with the base directory,
// replace namespace separators with directory separators
// in the relative class name, append with .php
@ -143,8 +139,10 @@ class Psr4Autoloader
{
if (file_exists($file)) {
require $file;
return true;
}
return false;
}
}

2
lib/Spout/Autoloader/autoload.php

@ -5,7 +5,7 @@ namespace Box\Spout\Autoloader;
require_once 'Psr4Autoloader.php';
/**
* @var string $srcBaseDirectory
* @var string
* Full path to "src/Spout" which is what we want "Box\Spout" to map to.
*/
$srcBaseDirectory = dirname(dirname(__FILE__));

38
lib/Spout/Common/Escaper/CSV.php

@ -1,38 +0,0 @@
<?php
namespace Box\Spout\Common\Escaper;
/**
* Class CSV
* Provides functions to escape and unescape data for CSV files
*
* @package Box\Spout\Common\Escaper
*/
class CSV implements EscaperInterface
{
/**
* Escapes the given string to make it compatible with CSV
*
* @codeCoverageIgnore
*
* @param string $string The string to escape
* @return string The escaped string
*/
public function escape($string)
{
return $string;
}
/**
* Unescapes the given string to make it compatible with CSV
*
* @codeCoverageIgnore
*
* @param string $string The string to unescape
* @return string The unescaped string
*/
public function unescape($string)
{
return $string;
}
}

27
lib/Spout/Common/Escaper/EscaperInterface.php

@ -1,27 +0,0 @@
<?php
namespace Box\Spout\Common\Escaper;
/**
* Interface EscaperInterface
*
* @package Box\Spout\Common\Escaper
*/
interface EscaperInterface
{
/**
* Escapes the given string to make it compatible with PHP
*
* @param string $string The string to escape
* @return string The escaped string
*/
public function escape($string);
/**
* Unescapes the given string to make it compatible with PHP
*
* @param string $string The string to unescape
* @return string The unescaped string
*/
public function unescape($string);
}

66
lib/Spout/Common/Escaper/ODS.php

@ -1,66 +0,0 @@
<?php
namespace Box\Spout\Common\Escaper;
use Box\Spout\Common\Singleton;
/**
* Class ODS
* Provides functions to escape and unescape data for ODS files
*
* @package Box\Spout\Common\Escaper
*/
class ODS implements EscaperInterface
{
use Singleton;
/**
* Escapes the given string to make it compatible with XLSX
*
* @param string $string The string to escape
* @return string The escaped string
*/
public function escape($string)
{
if (defined('ENT_DISALLOWED')) {
// 'ENT_DISALLOWED' ensures that invalid characters in the given document type are replaced.
// Otherwise control characters like a vertical tab "\v" will make the XML document unreadable by the XML processor
// @link https://github.com/box/spout/issues/329
$replacedString = htmlspecialchars($string, ENT_NOQUOTES | ENT_DISALLOWED);
} else {
// We are on hhvm or any other engine that does not support ENT_DISALLOWED.
//
// @NOTE: Using ENT_NOQUOTES as only XML entities ('<', '>', '&') need to be encoded.
// Single and double quotes can be left as is.
$escapedString = htmlspecialchars($string, ENT_NOQUOTES);
// control characters values are from 0 to 1F (hex values) in the ASCII table
// some characters should not be escaped though: "\t", "\r" and "\n".
$regexPattern = '[\x00-\x08' .
// skipping "\t" (0x9) and "\n" (0xA)
'\x0B-\x0C' .
// skipping "\r" (0xD)
'\x0E-\x1F]';
$replacedString = preg_replace("/$regexPattern/", '�', $escapedString);
}
return $replacedString;
}
/**
* Unescapes the given string to make it compatible with XLSX
*
* @param string $string The string to unescape
* @return string The unescaped string
*/
public function unescape($string)
{
// ==============
// = WARNING =
// ==============
// It is assumed that the given string has already had its XML entities decoded.
// This is true if the string is coming from a DOMNode (as DOMNode already decode XML entities on creation).
// Therefore there is no need to call "htmlspecialchars_decode()".
return $string;
}
}

185
lib/Spout/Common/Escaper/XLSX.php

@ -1,185 +0,0 @@
<?php
namespace Box\Spout\Common\Escaper;
use Box\Spout\Common\Singleton;
/**
* Class XLSX
* Provides functions to escape and unescape data for XLSX files
*
* @package Box\Spout\Common\Escaper
*/
class XLSX implements EscaperInterface
{
use Singleton;
/** @var string Regex pattern to detect control characters that need to be escaped */
protected $escapableControlCharactersPattern;
/** @var string[] Map containing control characters to be escaped (key) and their escaped value (value) */
protected $controlCharactersEscapingMap;
/** @var string[] Map containing control characters to be escaped (value) and their escaped value (key) */
protected $controlCharactersEscapingReverseMap;
/**
* Initializes the singleton instance
*/
protected function init()
{
$this->escapableControlCharactersPattern = $this->getEscapableControlCharactersPattern();
$this->controlCharactersEscapingMap = $this->getControlCharactersEscapingMap();
$this->controlCharactersEscapingReverseMap = array_flip($this->controlCharactersEscapingMap);
}
/**
* Escapes the given string to make it compatible with XLSX
*
* @param string $string The string to escape
* @return string The escaped string
*/
public function escape($string)
{
$escapedString = $this->escapeControlCharacters($string);
// @NOTE: Using ENT_NOQUOTES as only XML entities ('<', '>', '&') need to be encoded.
// Single and double quotes can be left as is.
$escapedString = htmlspecialchars($escapedString, ENT_NOQUOTES);
return $escapedString;
}
/**
* Unescapes the given string to make it compatible with XLSX
*
* @param string $string The string to unescape
* @return string The unescaped string
*/
public function unescape($string)
{
// ==============
// = WARNING =
// ==============
// It is assumed that the given string has already had its XML entities decoded.
// This is true if the string is coming from a DOMNode (as DOMNode already decode XML entities on creation).
// Therefore there is no need to call "htmlspecialchars_decode()".
$unescapedString = $this->unescapeControlCharacters($string);
return $unescapedString;
}
/**
* @return string Regex pattern containing all escapable control characters
*/
protected function getEscapableControlCharactersPattern()
{
// control characters values are from 0 to 1F (hex values) in the ASCII table
// some characters should not be escaped though: "\t", "\r" and "\n".
return '[\x00-\x08' .
// skipping "\t" (0x9) and "\n" (0xA)
'\x0B-\x0C' .
// skipping "\r" (0xD)
'\x0E-\x1F]';
}
/**
* Builds the map containing control characters to be escaped
* mapped to their escaped values.
* "\t", "\r" and "\n" don't need to be escaped.
*
* NOTE: the logic has been adapted from the XlsxWriter library (BSD License)
* @link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89
*
* @return string[]
*/
protected function getControlCharactersEscapingMap()
{
$controlCharactersEscapingMap = [];
// control characters values are from 0 to 1F (hex values) in the ASCII table
for ($charValue = 0x00; $charValue <= 0x1F; $charValue++) {
$character = chr($charValue);
if (preg_match("/{$this->escapableControlCharactersPattern}/", $character)) {
$charHexValue = dechex($charValue);
$escapedChar = '_x' . sprintf('%04s' , strtoupper($charHexValue)) . '_';
$controlCharactersEscapingMap[$escapedChar] = $character;
}
}
return $controlCharactersEscapingMap;
}
/**
* Converts PHP control characters from the given string to OpenXML escaped control characters
*
* Excel escapes control characters with _xHHHH_ and also escapes any
* literal strings of that type by encoding the leading underscore.
* So "\0" -> _x0000_ and "_x0000_" -> _x005F_x0000_.
*
* NOTE: the logic has been adapted from the XlsxWriter library (BSD License)
* @link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89
*
* @param string $string String to escape
* @return string
*/
protected function escapeControlCharacters($string)
{
$escapedString = $this->escapeEscapeCharacter($string);
// if no control characters
if (!preg_match("/{$this->escapableControlCharactersPattern}/", $escapedString)) {
return $escapedString;
}
return preg_replace_callback("/({$this->escapableControlCharactersPattern})/", function($matches) {
return $this->controlCharactersEscapingReverseMap[$matches[0]];
}, $escapedString);
}
/**
* Escapes the escape character: "_x0000_" -> "_x005F_x0000_"
*
* @param string $string String to escape
* @return string The escaped string
*/
protected function escapeEscapeCharacter($string)
{
return preg_replace('/_(x[\dA-F]{4})_/', '_x005F_$1_', $string);
}
/**
* Converts OpenXML escaped control characters from the given string to PHP control characters
*
* Excel escapes control characters with _xHHHH_ and also escapes any
* literal strings of that type by encoding the leading underscore.
* So "_x0000_" -> "\0" and "_x005F_x0000_" -> "_x0000_"
*
* NOTE: the logic has been adapted from the XlsxWriter library (BSD License)
* @link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89
*
* @param string $string String to unescape
* @return string
*/
protected function unescapeControlCharacters($string)
{
$unescapedString = $string;
foreach ($this->controlCharactersEscapingMap as $escapedCharValue => $charValue) {
// only unescape characters that don't contain the escaped escape character for now
$unescapedString = preg_replace("/(?<!_x005F)($escapedCharValue)/", $charValue, $unescapedString);
}
return $this->unescapeEscapeCharacter($unescapedString);
}
/**
* Unecapes the escape character: "_x005F_x0000_" => "_x0000_"
*
* @param string $string String to unescape
* @return string The unescaped string
*/
protected function unescapeEscapeCharacter($string)
{
return preg_replace('/_x005F(_x[\dA-F]{4}_)/', '$1', $string);
}
}

3
lib/Spout/Common/Exception/EncodingConversionException.php

@ -4,9 +4,6 @@ namespace Box\Spout\Common\Exception;
/**
* Class EncodingConversionException
*
* @api
* @package Box\Spout\Common\Exception
*/
class EncodingConversionException extends SpoutException
{

3
lib/Spout/Common/Exception/IOException.php

@ -4,9 +4,6 @@ namespace Box\Spout\Common\Exception;
/**
* Class IOException
*
* @api
* @package Box\Spout\Common\Exception
*/
class IOException extends SpoutException
{

3
lib/Spout/Common/Exception/InvalidArgumentException.php

@ -4,9 +4,6 @@ namespace Box\Spout\Common\Exception;
/**
* Class InvalidArgumentException
*
* @api
* @package Box\Spout\Common\Exception
*/
class InvalidArgumentException extends SpoutException
{

1
lib/Spout/Common/Exception/SpoutException.php

@ -5,7 +5,6 @@ namespace Box\Spout\Common\Exception;
/**
* Class SpoutException
*
* @package Box\Spout\Common\Exception
* @abstract
*/
abstract class SpoutException extends \Exception

3
lib/Spout/Common/Exception/UnsupportedTypeException.php

@ -4,9 +4,6 @@ namespace Box\Spout\Common\Exception;
/**
* Class UnsupportedTypeException
*
* @api
* @package Box\Spout\Common\Exception
*/
class UnsupportedTypeException extends SpoutException
{

10
lib/Spout/Common/Helper/EncodingHelper.php

@ -7,8 +7,6 @@ use Box\Spout\Common\Exception\EncodingConversionException;
/**
* Class EncodingHelper
* This class provides helper functions to work with encodings.
*
* @package Box\Spout\Common\Helper
*/
class EncodingHelper
{
@ -97,8 +95,8 @@ class EncodingHelper
*
* @param string $string Non UTF-8 string to be converted
* @param string $sourceEncoding The encoding used to encode the source string
* @return string The converted, UTF-8 string
* @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
* @return string The converted, UTF-8 string
*/
public function attemptConversionToUTF8($string, $sourceEncoding)
{
@ -110,8 +108,8 @@ class EncodingHelper
*
* @param string $string UTF-8 string to be converted
* @param string $targetEncoding The encoding the string should be re-encoded into
* @return string The converted string, encoded with the given encoding
* @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
* @return string The converted string, encoded with the given encoding
*/
public function attemptConversionFromUTF8($string, $targetEncoding)
{
@ -125,8 +123,8 @@ class EncodingHelper
* @param string $string string to be converted
* @param string $sourceEncoding The encoding used to encode the source string
* @param string $targetEncoding The encoding the string should be re-encoded into
* @return string The converted string, encoded with the given encoding
* @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
* @return string The converted string, encoded with the given encoding
*/
protected function attemptConversion($string, $sourceEncoding, $targetEncoding)
{
@ -139,7 +137,7 @@ class EncodingHelper
if ($this->canUseIconv()) {
$convertedString = $this->globalFunctionsHelper->iconv($string, $sourceEncoding, $targetEncoding);
} else if ($this->canUseMbString()) {
} elseif ($this->canUseMbString()) {
$convertedString = $this->globalFunctionsHelper->mb_convert_encoding($string, $sourceEncoding, $targetEncoding);
} else {
throw new EncodingConversionException("The conversion from $sourceEncoding to $targetEncoding is not supported. Please install \"iconv\" or \"PHP Intl\".");

14
lib/Spout/Common/Helper/FileSystemHelper.php

@ -8,10 +8,8 @@ use Box\Spout\Common\Exception\IOException;
* Class FileSystemHelper
* This class provides helper functions to help with the file system operations
* like files/folders creation & deletion
*
* @package Box\Spout\Common\Helper
*/
class FileSystemHelper
class FileSystemHelper implements FileSystemHelperInterface
{
/** @var string Real path of the base folder where all the I/O can occur */
protected $baseFolderRealPath;
@ -29,8 +27,8 @@ class FileSystemHelper
*
* @param string $parentFolderPath The parent folder path under which the folder is going to be created
* @param string $folderName The name of the folder to create
* @return string Path of the created folder
* @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or if the folder path is not inside of the base folder
* @return string Path of the created folder
*/
public function createFolder($parentFolderPath, $folderName)
{
@ -53,8 +51,8 @@ class FileSystemHelper
* @param string $parentFolderPath The parent folder path where the file is going to be created
* @param string $fileName The name of the file to create
* @param string $fileContents The contents of the file to create
* @return string Path of the created file
* @throws \Box\Spout\Common\Exception\IOException If unable to create the file or if the file path is not inside of the base folder
* @return string Path of the created file
*/
public function createFileWithContents($parentFolderPath, $fileName, $fileContents)
{
@ -74,8 +72,8 @@ class FileSystemHelper
* Delete the file at the given path
*
* @param string $filePath Path of the file to delete
* @return void
* @throws \Box\Spout\Common\Exception\IOException If the file path is not inside of the base folder
* @return void
*/
public function deleteFile($filePath)
{
@ -90,8 +88,8 @@ class FileSystemHelper
* Delete the folder at the given path as well as all its contents
*
* @param string $folderPath Path of the folder to delete
* @return void
* @throws \Box\Spout\Common\Exception\IOException If the folder path is not inside of the base folder
* @return void
*/
public function deleteFolderRecursively($folderPath)
{
@ -119,8 +117,8 @@ class FileSystemHelper
* should occur is not inside the base folder.
*
* @param string $operationFolderPath The path of the folder where the I/O operation should occur
* @return void
* @throws \Box\Spout\Common\Exception\IOException If the folder where the I/O operation should occur is not inside the base folder
* @return void
*/
protected function throwIfOperationNotInBaseFolder($operationFolderPath)
{

35
lib/Spout/Common/Helper/GlobalFunctionsHelper.php

@ -7,8 +7,6 @@ namespace Box\Spout\Common\Helper;
* This class wraps global functions to facilitate testing
*
* @codeCoverageIgnore
*
* @package Box\Spout\Common\Helper
*/
class GlobalFunctionsHelper
{
@ -30,7 +28,7 @@ class GlobalFunctionsHelper
* @see fgets()
*
* @param resource $handle
* @param int|void $length
* @param int|null $length
* @return string
*/
public function fgets($handle, $length = null)
@ -81,14 +79,20 @@ class GlobalFunctionsHelper
* @see fgetcsv()
*
* @param resource $handle
* @param int|void $length
* @param string|void $delimiter
* @param string|void $enclosure
* @param int|null $length
* @param string|null $delimiter
* @param string|null $enclosure
* @return array
*/
public function fgetcsv($handle, $length = null, $delimiter = null, $enclosure = null)
{
return fgetcsv($handle, $length, $delimiter, $enclosure);
// PHP uses '\' as the default escape character. This is not RFC-4180 compliant...
// To fix that, simply disable the escape character.
// @see https://bugs.php.net/bug.php?id=43225
// @see http://tools.ietf.org/html/rfc4180
$escapeCharacter = "\0";
return fgetcsv($handle, $length, $delimiter, $enclosure, $escapeCharacter);
}
/**
@ -97,13 +101,19 @@ class GlobalFunctionsHelper
*
* @param resource $handle
* @param array $fields
* @param string|void $delimiter
* @param string|void $enclosure
* @param string|null $delimiter
* @param string|null $enclosure
* @return int
*/
public function fputcsv($handle, array $fields, $delimiter = null, $enclosure = null)
{
return fputcsv($handle, $fields, $delimiter, $enclosure);
// PHP uses '\' as the default escape character. This is not RFC-4180 compliant...
// To fix that, simply disable the escape character.
// @see https://bugs.php.net/bug.php?id=43225
// @see http://tools.ietf.org/html/rfc4180
$escapeCharacter = "\0";
return fputcsv($handle, $fields, $delimiter, $enclosure, $escapeCharacter);
}
/**
@ -165,6 +175,7 @@ class GlobalFunctionsHelper
public function file_get_contents($filePath)
{
$realFilePath = $this->convertToUseRealPath($filePath);
return file_get_contents($realFilePath);
}
@ -207,7 +218,7 @@ class GlobalFunctionsHelper
* Wrapper around global function feof()
* @see feof()
*
* @param resource
* @param resource $handle
* @return bool
*/
public function feof($handle)
@ -232,7 +243,7 @@ class GlobalFunctionsHelper
* @see basename()
*
* @param string $path
* @param string|void $suffix
* @param string|null $suffix
* @return string
*/
public function basename($path, $suffix = null)

4
lib/Spout/Common/Helper/StringHelper.php

@ -7,8 +7,6 @@ namespace Box\Spout\Common\Helper;
* This class provides helper functions to work with strings and multibyte strings.
*
* @codeCoverageIgnore
*
* @package Box\Spout\Common\Helper
*/
class StringHelper
{
@ -50,6 +48,7 @@ class StringHelper
public function getCharFirstOccurrencePosition($char, $string)
{
$position = $this->hasMbstringSupport ? mb_strpos($string, $char) : strpos($string, $char);
return ($position !== false) ? $position : -1;
}
@ -66,6 +65,7 @@ class StringHelper
public function getCharLastOccurrencePosition($char, $string)
{
$position = $this->hasMbstringSupport ? mb_strrpos($string, $char) : strrpos($string, $char);
return ($position !== false) ? $position : -1;
}
}

41
lib/Spout/Common/Singleton.php

@ -1,41 +0,0 @@
<?php
namespace Box\Spout\Common;
/**
* Class Singleton
* Defines a class as a singleton.
*
* @package Box\Spout\Common
*/
trait Singleton
{
protected static $instance;
/**
* @return static
*/
final public static function getInstance()
{
return isset(static::$instance)
? static::$instance
: static::$instance = new static;
}
/**
* Singleton constructor.
*/
final private function __construct()
{
$this->init();
}
/**
* Initializes the singleton
* @return void
*/
protected function init() {}
final private function __wakeup() {}
final private function __clone() {}
}

2
lib/Spout/Common/Type.php

@ -5,8 +5,6 @@ namespace Box\Spout\Common;
/**
* Class Type
* This class references the supported types
*
* @api
*/
abstract class Type
{

238
lib/Spout/Reader/AbstractReader.php

@ -1,238 +0,0 @@
<?php
namespace Box\Spout\Reader;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Reader\Exception\ReaderNotOpenedException;
/**
* Class AbstractReader
*
* @package Box\Spout\Reader
* @abstract
*/
abstract class AbstractReader implements ReaderInterface
{
/** @var bool Indicates whether the stream is currently open */
protected $isStreamOpened = false;
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */
protected $globalFunctionsHelper;
/** @var \Box\Spout\Reader\Common\ReaderOptions Reader's customized options */
protected $options;
/**
* Returns the reader's current options
*
* @return \Box\Spout\Reader\Common\ReaderOptions
*/
abstract protected function getOptions();
/**
* Returns whether stream wrappers are supported
*
* @return bool
*/
abstract protected function doesSupportStreamWrapper();
/**
* Opens the file at the given file path to make it ready to be read
*
* @param string $filePath Path of the file to be read
* @return void
*/
abstract protected function openReader($filePath);
/**
* Returns an iterator to iterate over sheets.
*
* @return \Iterator To iterate over sheets
*/
abstract protected function getConcreteSheetIterator();
/**
* Closes the reader. To be used after reading the file.
*
* @return AbstractReader
*/
abstract protected function closeReader();
/**
* @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper
* @return AbstractReader
*/
public function setGlobalFunctionsHelper($globalFunctionsHelper)
{
$this->globalFunctionsHelper = $globalFunctionsHelper;
return $this;
}
/**
* Sets whether date/time values should be returned as PHP objects or be formatted as strings.
*
* @api
* @param bool $shouldFormatDates
* @return AbstractReader
*/
public function setShouldFormatDates($shouldFormatDates)
{
$this->getOptions()->setShouldFormatDates($shouldFormatDates);
return $this;
}
/**
* Sets whether empty rows should be returned or skipped.
*
* @api
* @param bool $shouldPreserveEmptyRows
* @return AbstractReader
*/
public function setShouldPreserveEmptyRows($shouldPreserveEmptyRows)
{
$this->getOptions()->setShouldPreserveEmptyRows($shouldPreserveEmptyRows);
return $this;
}
/**
* Prepares the reader to read the given file. It also makes sure
* that the file exists and is readable.
*
* @api
* @param string $filePath Path of the file to be read
* @return void
* @throws \Box\Spout\Common\Exception\IOException If the file at the given path does not exist, is not readable or is corrupted
*/
public function open($filePath)
{
if ($this->isStreamWrapper($filePath) && (!$this->doesSupportStreamWrapper() || !$this->isSupportedStreamWrapper($filePath))) {
throw new IOException("Could not open $filePath for reading! Stream wrapper used is not supported for this type of file.");
}
if (!$this->isPhpStream($filePath)) {
// we skip the checks if the provided file path points to a PHP stream
if (!$this->globalFunctionsHelper->file_exists($filePath)) {
throw new IOException("Could not open $filePath for reading! File does not exist.");
} else if (!$this->globalFunctionsHelper->is_readable($filePath)) {
throw new IOException("Could not open $filePath for reading! File is not readable.");
}
}
try {
$fileRealPath = $this->getFileRealPath($filePath);
$this->openReader($fileRealPath);
$this->isStreamOpened = true;
} catch (\Exception $exception) {
throw new IOException("Could not open $filePath for reading! ({$exception->getMessage()})");
}
}
/**
* Returns the real path of the given path.
* If the given path is a valid stream wrapper, returns the path unchanged.
*
* @param string $filePath
* @return string
*/
protected function getFileRealPath($filePath)
{
if ($this->isSupportedStreamWrapper($filePath)) {
return $filePath;
}
// Need to use realpath to fix "Can't open file" on some Windows setup
return realpath($filePath);
}
/**
* Returns the scheme of the custom stream wrapper, if the path indicates a stream wrapper is used.
* For example, php://temp => php, s3://path/to/file => s3...
*
* @param string $filePath Path of the file to be read
* @return string|null The stream wrapper scheme or NULL if not a stream wrapper
*/
protected function getStreamWrapperScheme($filePath)
{
$streamScheme = null;
if (preg_match('/^(\w+):\/\//', $filePath, $matches)) {
$streamScheme = $matches[1];
}
return $streamScheme;
}
/**
* Checks if the given path is an unsupported stream wrapper
* (like local path, php://temp, mystream://foo/bar...).
*
* @param string $filePath Path of the file to be read
* @return bool Whether the given path is an unsupported stream wrapper
*/
protected function isStreamWrapper($filePath)
{
return ($this->getStreamWrapperScheme($filePath) !== null);
}
/**
* Checks if the given path is an supported stream wrapper
* (like php://temp, mystream://foo/bar...).
* If the given path is a local path, returns true.
*
* @param string $filePath Path of the file to be read
* @return bool Whether the given path is an supported stream wrapper
*/
protected function isSupportedStreamWrapper($filePath)
{
$streamScheme = $this->getStreamWrapperScheme($filePath);
return ($streamScheme !== null) ?
in_array($streamScheme, $this->globalFunctionsHelper->stream_get_wrappers()) :
true;
}
/**
* Checks if a path is a PHP stream (like php://output, php://memory, ...)
*
* @param string $filePath Path of the file to be read
* @return bool Whether the given path maps to a PHP stream
*/
protected function isPhpStream($filePath)
{
$streamScheme = $this->getStreamWrapperScheme($filePath);
return ($streamScheme === 'php');
}
/**
* Returns an iterator to iterate over sheets.
*
* @api
* @return \Iterator To iterate over sheets
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException If called before opening the reader
*/
public function getSheetIterator()
{
if (!$this->isStreamOpened) {
throw new ReaderNotOpenedException('Reader should be opened first.');
}
return $this->getConcreteSheetIterator();
}
/**
* Closes the reader, preventing any additional reading
*
* @api
* @return void
*/
public function close()
{
if ($this->isStreamOpened) {
$this->closeReader();
$sheetIterator = $this->getConcreteSheetIterator();
if ($sheetIterator) {
$sheetIterator->end();
}
$this->isStreamOpened = false;
}
}
}

51
lib/Spout/Reader/CSV/Reader.php

@ -2,16 +2,16 @@
namespace Box\Spout\Reader\CSV;
use Box\Spout\Reader\AbstractReader;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
use Box\Spout\Reader\ReaderAbstract;
/**
* Class Reader
* This class provides support to read data from a CSV file.
*
* @package Box\Spout\Reader\CSV
*/
class Reader extends AbstractReader
class Reader extends ReaderAbstract
{
/** @var resource Pointer to the file to be written */
protected $filePointer;
@ -22,19 +22,6 @@ class Reader extends AbstractReader
/** @var string Original value for the "auto_detect_line_endings" INI value */
protected $originalAutoDetectLineEndings;
/**
* Returns the reader's current options
*
* @return ReaderOptions
*/
protected function getOptions()
{
if (!isset($this->options)) {
$this->options = new ReaderOptions();
}
return $this->options;
}
/**
* Sets the field delimiter for the CSV.
* Needs to be called before opening the reader.
@ -44,7 +31,8 @@ class Reader extends AbstractReader
*/
public function setFieldDelimiter($fieldDelimiter)
{
$this->getOptions()->setFieldDelimiter($fieldDelimiter);
$this->optionsManager->setOption(Options::FIELD_DELIMITER, $fieldDelimiter);
return $this;
}
@ -57,7 +45,8 @@ class Reader extends AbstractReader
*/
public function setFieldEnclosure($fieldEnclosure)
{
$this->getOptions()->setFieldEnclosure($fieldEnclosure);
$this->optionsManager->setOption(Options::FIELD_ENCLOSURE, $fieldEnclosure);
return $this;
}
@ -70,20 +59,8 @@ class Reader extends AbstractReader
*/
public function setEncoding($encoding)
{
$this->getOptions()->setEncoding($encoding);
return $this;
}
$this->optionsManager->setOption(Options::ENCODING, $encoding);
/**
* Sets the EOL for the CSV.
* Needs to be called before opening the reader.
*
* @param string $endOfLineCharacter used to properly get lines from the CSV file.
* @return Reader
*/
public function setEndOfLineCharacter($endOfLineCharacter)
{
$this->getOptions()->setEndOfLineCharacter($endOfLineCharacter);
return $this;
}
@ -102,8 +79,8 @@ class Reader extends AbstractReader
* If setEncoding() was not called, it assumes that the file is encoded in UTF-8.
*
* @param string $filePath Path of the CSV file to be read
* @return void
* @throws \Box\Spout\Common\Exception\IOException
* @return void
*/
protected function openReader($filePath)
{
@ -115,9 +92,12 @@ class Reader extends AbstractReader
throw new IOException("Could not open file $filePath for reading.");
}
$this->sheetIterator = new SheetIterator(
/** @var InternalEntityFactory $entityFactory */
$entityFactory = $this->entityFactory;
$this->sheetIterator = $entityFactory->createSheetIterator(
$this->filePointer,
$this->getOptions(),
$this->optionsManager,
$this->globalFunctionsHelper
);
}
@ -132,7 +112,6 @@ class Reader extends AbstractReader
return $this->sheetIterator;
}
/**
* Closes the reader. To be used after reading the file.
*

110
lib/Spout/Reader/CSV/ReaderOptions.php

@ -1,110 +0,0 @@
<?php
namespace Box\Spout\Reader\CSV;
use Box\Spout\Common\Helper\EncodingHelper;
/**
* Class ReaderOptions
* This class is used to customize the reader's behavior
*
* @package Box\Spout\Reader\CSV
*/
class ReaderOptions extends \Box\Spout\Reader\Common\ReaderOptions
{
/** @var string Defines the character used to delimit fields (one character only) */
protected $fieldDelimiter = ',';
/** @var string Defines the character used to enclose fields (one character only) */
protected $fieldEnclosure = '"';
/** @var string Encoding of the CSV file to be read */
protected $encoding = EncodingHelper::ENCODING_UTF8;
/** @var string Defines the End of line */
protected $endOfLineCharacter = "\n";
/**
* @return string
*/
public function getFieldDelimiter()
{
return $this->fieldDelimiter;
}
/**
* Sets the field delimiter for the CSV.
* Needs to be called before opening the reader.
*
* @param string $fieldDelimiter Character that delimits fields
* @return ReaderOptions
*/
public function setFieldDelimiter($fieldDelimiter)
{
$this->fieldDelimiter = $fieldDelimiter;
return $this;
}
/**
* @return string
*/
public function getFieldEnclosure()
{
return $this->fieldEnclosure;
}
/**
* Sets the field enclosure for the CSV.
* Needs to be called before opening the reader.
*
* @param string $fieldEnclosure Character that enclose fields
* @return ReaderOptions
*/
public function setFieldEnclosure($fieldEnclosure)
{
$this->fieldEnclosure = $fieldEnclosure;
return $this;
}
/**
* @return string
*/
public function getEncoding()
{
return $this->encoding;
}
/**
* Sets the encoding of the CSV file to be read.
* Needs to be called before opening the reader.
*
* @param string $encoding Encoding of the CSV file to be read
* @return ReaderOptions
*/
public function setEncoding($encoding)
{
$this->encoding = $encoding;
return $this;
}
/**
* @return string EOL for the CSV
*/
public function getEndOfLineCharacter()
{
return $this->endOfLineCharacter;
}
/**
* Sets the EOL for the CSV.
* Needs to be called before opening the reader.
*
* @param string $endOfLineCharacter used to properly get lines from the CSV file.
* @return ReaderOptions
*/
public function setEndOfLineCharacter($endOfLineCharacter)
{
$this->endOfLineCharacter = $endOfLineCharacter;
return $this;
}
}

96
lib/Spout/Reader/CSV/RowIterator.php

@ -2,14 +2,17 @@
namespace Box\Spout\Reader\CSV;
use Box\Spout\Reader\IteratorInterface;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Common\Helper\EncodingHelper;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
use Box\Spout\Reader\IteratorInterface;
/**
* Class RowIterator
* Iterate over CSV rows.
*
* @package Box\Spout\Reader\CSV
*/
class RowIterator implements IteratorInterface
{
@ -24,8 +27,8 @@ class RowIterator implements IteratorInterface
/** @var int Number of read rows */
protected $numReadRows = 0;
/** @var array|null Buffer used to store the row data, while checking if there are more rows to read */
protected $rowDataBuffer = null;
/** @var Row|null Buffer used to store the current row, while checking if there are more rows to read */
protected $rowBuffer;
/** @var bool Indicates whether all rows have been read */
protected $hasReachedEndOfFile = false;
@ -39,42 +42,45 @@ class RowIterator implements IteratorInterface
/** @var string Encoding of the CSV file to be read */
protected $encoding;
/** @var string End of line delimiter, given by the user as input. */
protected $inputEOLDelimiter;
/** @var bool Whether empty rows should be returned or skipped */
protected $shouldPreserveEmptyRows;
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */
protected $globalFunctionsHelper;
/** @var \Box\Spout\Common\Helper\EncodingHelper Helper to work with different encodings */
protected $encodingHelper;
/** @var string End of line delimiter, encoded using the same encoding as the CSV */
protected $encodedEOLDelimiter;
/** @var \Box\Spout\Reader\CSV\Creator\InternalEntityFactory Factory to create entities */
protected $entityFactory;
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */
protected $globalFunctionsHelper;
/**
* @param resource $filePointer Pointer to the CSV file to read
* @param \Box\Spout\Reader\CSV\ReaderOptions $options
* @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper
* @param OptionsManagerInterface $optionsManager
* @param EncodingHelper $encodingHelper
* @param InternalEntityFactory $entityFactory
* @param GlobalFunctionsHelper $globalFunctionsHelper
*/
public function __construct($filePointer, $options, $globalFunctionsHelper)
{
public function __construct(
$filePointer,
OptionsManagerInterface $optionsManager,
EncodingHelper $encodingHelper,
InternalEntityFactory $entityFactory,
GlobalFunctionsHelper $globalFunctionsHelper
) {
$this->filePointer = $filePointer;
$this->fieldDelimiter = $options->getFieldDelimiter();
$this->fieldEnclosure = $options->getFieldEnclosure();
$this->encoding = $options->getEncoding();
$this->inputEOLDelimiter = $options->getEndOfLineCharacter();
$this->shouldPreserveEmptyRows = $options->shouldPreserveEmptyRows();
$this->fieldDelimiter = $optionsManager->getOption(Options::FIELD_DELIMITER);
$this->fieldEnclosure = $optionsManager->getOption(Options::FIELD_ENCLOSURE);
$this->encoding = $optionsManager->getOption(Options::ENCODING);
$this->shouldPreserveEmptyRows = $optionsManager->getOption(Options