Changeset 115670 in spip-zone


Ignore:
Timestamp:
Jun 14, 2019, 12:23:49 PM (7 months ago)
Author:
real3t@…
Message:

Passage à Spout 3.0.1

Location:
_squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs
Files:
25 deleted
62 edited

Legend:

Unmodified
Added
Removed
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/comptetraduction_export_fonctions.php

    r112447 r115670  
    33require_once find_in_path('lib/Spout/Autoloader/autoload.php');
    44       
    5 use Box\Spout\Writer\WriterFactory;
    6 use Box\Spout\Common\Type;
     5use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
     6use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
     7use Box\Spout\Common\Entity\Style\Color;
    78
    89function trad_export_csv($trads) {
     
    1516        );
    1617       
    17         $writer = WriterFactory::create(Type::XLSX); // for XLSX files
     18        $defaultStyle = (new StyleBuilder())
     19                ->setFontName('Arial')
     20                ->setFontSize(11)
     21                ->build();
     22       
     23       
     24        $writer = WriterEntityFactory::createXLSXWriter(); // for XLSX files
    1825
    19         $writer->openToBrowser('traduction'); // stream data directly to the browser
    20 
    21         $writer->addRow($entetes); // add a row at a time
    22         $writer->addRows($trads); // add multiple rows at a time
     26        $writer->openToBrowser('traduction.xlsx'); // stream data directly to the browser
     27       
     28        $writer->addRow(WriterEntityFactory::createRowFromArray($entetes, $defaultStyle)); // add a row at a time
     29       
     30        foreach ($trads as $trad) {
     31                $writer->addRow(WriterEntityFactory::createRowFromArray($trad, $defaultStyle));
     32        }
    2333
    2434        $writer->close();
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Autoloader/Psr4Autoloader.php

    r112446 r115670  
    66 * Class Psr4Autoloader
    77 * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md#class-example
    8  *
    9  * @package Box\Spout\Autoloader
    108 */
    119class Psr4Autoloader
     
    1715     * @var array
    1816     */
    19     protected $prefixes = array();
     17    protected $prefixes = [];
    2018
    2119    /**
     
    2624    public function register()
    2725    {
    28         spl_autoload_register(array($this, 'loadClass'));
     26        spl_autoload_register([$this, 'loadClass']);
    2927    }
    3028
     
    5048        // initialize the namespace prefix array
    5149        if (isset($this->prefixes[$prefix]) === false) {
    52             $this->prefixes[$prefix] = array();
     50            $this->prefixes[$prefix] = [];
    5351        }
    5452
     
    7573        // work backwards through the namespace names of the fully-qualified
    7674        // class name to find a mapped file name
    77         while (false !== $pos = strrpos($prefix, '\\')) {
    78 
     75        while (($pos = strrpos($prefix, '\\')) !== false) {
    7976            // retain the trailing namespace separator in the prefix
    8077            $prefix = substr($class, 0, $pos + 1);
     
    115112        // look through base directories for this namespace prefix
    116113        foreach ($this->prefixes[$prefix] as $baseDir) {
    117 
    118114            // replace the namespace prefix with the base directory,
    119115            // replace namespace separators with directory separators
     
    144140        if (file_exists($file)) {
    145141            require $file;
     142
    146143            return true;
    147144        }
     145
    148146        return false;
    149147    }
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Autoloader/autoload.php

    r112446 r115670  
    66
    77/**
    8  * @var string $srcBaseDirectory
     8 * @var string
    99 * Full path to "src/Spout" which is what we want "Box\Spout" to map to.
    1010 */
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Common/Exception/EncodingConversionException.php

    r112446 r115670  
    55/**
    66 * Class EncodingConversionException
    7  *
    8  * @api
    9  * @package Box\Spout\Common\Exception
    107 */
    118class EncodingConversionException extends SpoutException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Common/Exception/IOException.php

    r112446 r115670  
    55/**
    66 * Class IOException
    7  *
    8  * @api
    9  * @package Box\Spout\Common\Exception
    107 */
    118class IOException extends SpoutException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Common/Exception/InvalidArgumentException.php

    r112446 r115670  
    55/**
    66 * Class InvalidArgumentException
    7  *
    8  * @api
    9  * @package Box\Spout\Common\Exception
    107 */
    118class InvalidArgumentException extends SpoutException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Common/Exception/SpoutException.php

    r112446 r115670  
    66 * Class SpoutException
    77 *
    8  * @package Box\Spout\Common\Exception
    98 * @abstract
    109 */
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Common/Exception/UnsupportedTypeException.php

    r112446 r115670  
    55/**
    66 * Class UnsupportedTypeException
    7  *
    8  * @api
    9  * @package Box\Spout\Common\Exception
    107 */
    118class UnsupportedTypeException extends SpoutException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Common/Helper/EncodingHelper.php

    r112446 r115670  
    88 * Class EncodingHelper
    99 * This class provides helper functions to work with encodings.
    10  *
    11  * @package Box\Spout\Common\Helper
    1210 */
    1311class EncodingHelper
     
    9896     * @param string $string Non UTF-8 string to be converted
    9997     * @param string $sourceEncoding The encoding used to encode the source string
     98     * @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
    10099     * @return string The converted, UTF-8 string
    101      * @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
    102100     */
    103101    public function attemptConversionToUTF8($string, $sourceEncoding)
     
    111109     * @param string $string UTF-8 string to be converted
    112110     * @param string $targetEncoding The encoding the string should be re-encoded into
     111     * @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
    113112     * @return string The converted string, encoded with the given encoding
    114      * @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
    115113     */
    116114    public function attemptConversionFromUTF8($string, $targetEncoding)
     
    126124     * @param string $sourceEncoding The encoding used to encode the source string
    127125     * @param string $targetEncoding The encoding the string should be re-encoded into
     126     * @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
    128127     * @return string The converted string, encoded with the given encoding
    129      * @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
    130128     */
    131129    protected function attemptConversion($string, $sourceEncoding, $targetEncoding)
     
    140138        if ($this->canUseIconv()) {
    141139            $convertedString = $this->globalFunctionsHelper->iconv($string, $sourceEncoding, $targetEncoding);
    142         } else if ($this->canUseMbString()) {
     140        } elseif ($this->canUseMbString()) {
    143141            $convertedString = $this->globalFunctionsHelper->mb_convert_encoding($string, $sourceEncoding, $targetEncoding);
    144142        } else {
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Common/Helper/FileSystemHelper.php

    r112446 r115670  
    99 * This class provides helper functions to help with the file system operations
    1010 * like files/folders creation & deletion
    11  *
    12  * @package Box\Spout\Common\Helper
    1311 */
    14 class FileSystemHelper
     12class FileSystemHelper implements FileSystemHelperInterface
    1513{
    1614    /** @var string Real path of the base folder where all the I/O can occur */
     
    3028     * @param string $parentFolderPath The parent folder path under which the folder is going to be created
    3129     * @param string $folderName The name of the folder to create
     30     * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or if the folder path is not inside of the base folder
    3231     * @return string Path of the created folder
    33      * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or if the folder path is not inside of the base folder
    3432     */
    3533    public function createFolder($parentFolderPath, $folderName)
     
    5452     * @param string $fileName The name of the file to create
    5553     * @param string $fileContents The contents of the file to create
     54     * @throws \Box\Spout\Common\Exception\IOException If unable to create the file or if the file path is not inside of the base folder
    5655     * @return string Path of the created file
    57      * @throws \Box\Spout\Common\Exception\IOException If unable to create the file or if the file path is not inside of the base folder
    5856     */
    5957    public function createFileWithContents($parentFolderPath, $fileName, $fileContents)
     
    7573     *
    7674     * @param string $filePath Path of the file to delete
     75     * @throws \Box\Spout\Common\Exception\IOException If the file path is not inside of the base folder
    7776     * @return void
    78      * @throws \Box\Spout\Common\Exception\IOException If the file path is not inside of the base folder
    7977     */
    8078    public function deleteFile($filePath)
     
    9189     *
    9290     * @param string $folderPath Path of the folder to delete
     91     * @throws \Box\Spout\Common\Exception\IOException If the folder path is not inside of the base folder
    9392     * @return void
    94      * @throws \Box\Spout\Common\Exception\IOException If the folder path is not inside of the base folder
    9593     */
    9694    public function deleteFolderRecursively($folderPath)
     
    120118     *
    121119     * @param string $operationFolderPath The path of the folder where the I/O operation should occur
     120     * @throws \Box\Spout\Common\Exception\IOException If the folder where the I/O operation should occur is not inside the base folder
    122121     * @return void
    123      * @throws \Box\Spout\Common\Exception\IOException If the folder where the I/O operation should occur is not inside the base folder
    124122     */
    125123    protected function throwIfOperationNotInBaseFolder($operationFolderPath)
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Common/Helper/GlobalFunctionsHelper.php

    r112446 r115670  
    88 *
    99 * @codeCoverageIgnore
    10  *
    11  * @package Box\Spout\Common\Helper
    1210 */
    1311class GlobalFunctionsHelper
     
    3129     *
    3230     * @param resource $handle
    33      * @param int|void $length
     31     * @param int|null $length
    3432     * @return string
    3533     */
     
    8280     *
    8381     * @param resource $handle
    84      * @param int|void $length
    85      * @param string|void $delimiter
    86      * @param string|void $enclosure
     82     * @param int|null $length
     83     * @param string|null $delimiter
     84     * @param string|null $enclosure
    8785     * @return array
    8886     */
    8987    public function fgetcsv($handle, $length = null, $delimiter = null, $enclosure = null)
    9088    {
    91         return fgetcsv($handle, $length, $delimiter, $enclosure);
     89        // PHP uses '\' as the default escape character. This is not RFC-4180 compliant...
     90        // To fix that, simply disable the escape character.
     91        // @see https://bugs.php.net/bug.php?id=43225
     92        // @see http://tools.ietf.org/html/rfc4180
     93        $escapeCharacter = "\0";
     94
     95        return fgetcsv($handle, $length, $delimiter, $enclosure, $escapeCharacter);
    9296    }
    9397
     
    98102     * @param resource $handle
    99103     * @param array $fields
    100      * @param string|void $delimiter
    101      * @param string|void $enclosure
     104     * @param string|null $delimiter
     105     * @param string|null $enclosure
    102106     * @return int
    103107     */
    104108    public function fputcsv($handle, array $fields, $delimiter = null, $enclosure = null)
    105109    {
    106         return fputcsv($handle, $fields, $delimiter, $enclosure);
     110        // PHP uses '\' as the default escape character. This is not RFC-4180 compliant...
     111        // To fix that, simply disable the escape character.
     112        // @see https://bugs.php.net/bug.php?id=43225
     113        // @see http://tools.ietf.org/html/rfc4180
     114        $escapeCharacter = "\0";
     115
     116        return fputcsv($handle, $fields, $delimiter, $enclosure, $escapeCharacter);
    107117    }
    108118
     
    166176    {
    167177        $realFilePath = $this->convertToUseRealPath($filePath);
     178
    168179        return file_get_contents($realFilePath);
    169180    }
     
    208219     * @see feof()
    209220     *
    210      * @param resource
     221     * @param resource $handle
    211222     * @return bool
    212223     */
     
    233244     *
    234245     * @param string $path
    235      * @param string|void $suffix
     246     * @param string|null $suffix
    236247     * @return string
    237248     */
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Common/Helper/StringHelper.php

    r112446 r115670  
    88 *
    99 * @codeCoverageIgnore
    10  *
    11  * @package Box\Spout\Common\Helper
    1210 */
    1311class StringHelper
     
    5149    {
    5250        $position = $this->hasMbstringSupport ? mb_strpos($string, $char) : strpos($string, $char);
     51
    5352        return ($position !== false) ? $position : -1;
    5453    }
     
    6766    {
    6867        $position = $this->hasMbstringSupport ? mb_strrpos($string, $char) : strrpos($string, $char);
     68
    6969        return ($position !== false) ? $position : -1;
    7070    }
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Common/Type.php

    r112446 r115670  
    66 * Class Type
    77 * This class references the supported types
    8  *
    9  * @api
    108 */
    119abstract class Type
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/CSV/Reader.php

    r112446 r115670  
    33namespace Box\Spout\Reader\CSV;
    44
    5 use Box\Spout\Reader\AbstractReader;
    65use Box\Spout\Common\Exception\IOException;
     6use Box\Spout\Reader\Common\Entity\Options;
     7use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
     8use Box\Spout\Reader\ReaderAbstract;
    79
    810/**
    911 * Class Reader
    1012 * This class provides support to read data from a CSV file.
    11  *
    12  * @package Box\Spout\Reader\CSV
    1313 */
    14 class Reader extends AbstractReader
     14class Reader extends ReaderAbstract
    1515{
    1616    /** @var resource Pointer to the file to be written */
     
    2424
    2525    /**
    26      * Returns the reader's current options
    27      *
    28      * @return ReaderOptions
    29      */
    30     protected function getOptions()
    31     {
    32         if (!isset($this->options)) {
    33             $this->options = new ReaderOptions();
    34         }
    35         return $this->options;
    36     }
    37 
    38     /**
    3926     * Sets the field delimiter for the CSV.
    4027     * Needs to be called before opening the reader.
     
    4532    public function setFieldDelimiter($fieldDelimiter)
    4633    {
    47         $this->getOptions()->setFieldDelimiter($fieldDelimiter);
     34        $this->optionsManager->setOption(Options::FIELD_DELIMITER, $fieldDelimiter);
     35
    4836        return $this;
    4937    }
     
    5846    public function setFieldEnclosure($fieldEnclosure)
    5947    {
    60         $this->getOptions()->setFieldEnclosure($fieldEnclosure);
     48        $this->optionsManager->setOption(Options::FIELD_ENCLOSURE, $fieldEnclosure);
     49
    6150        return $this;
    6251    }
     
    7160    public function setEncoding($encoding)
    7261    {
    73         $this->getOptions()->setEncoding($encoding);
    74         return $this;
    75     }
     62        $this->optionsManager->setOption(Options::ENCODING, $encoding);
    7663
    77     /**
    78      * Sets the EOL for the CSV.
    79      * Needs to be called before opening the reader.
    80      *
    81      * @param string $endOfLineCharacter used to properly get lines from the CSV file.
    82      * @return Reader
    83      */
    84     public function setEndOfLineCharacter($endOfLineCharacter)
    85     {
    86         $this->getOptions()->setEndOfLineCharacter($endOfLineCharacter);
    8764        return $this;
    8865    }
     
    10380     *
    10481     * @param  string $filePath Path of the CSV file to be read
     82     * @throws \Box\Spout\Common\Exception\IOException
    10583     * @return void
    106      * @throws \Box\Spout\Common\Exception\IOException
    10784     */
    10885    protected function openReader($filePath)
     
    11693        }
    11794
    118         $this->sheetIterator = new SheetIterator(
     95        /** @var InternalEntityFactory $entityFactory */
     96        $entityFactory = $this->entityFactory;
     97
     98        $this->sheetIterator = $entityFactory->createSheetIterator(
    11999            $this->filePointer,
    120             $this->getOptions(),
     100            $this->optionsManager,
    121101            $this->globalFunctionsHelper
    122102        );
     
    132112        return $this->sheetIterator;
    133113    }
    134 
    135114
    136115    /**
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/CSV/RowIterator.php

    r112446 r115670  
    33namespace Box\Spout\Reader\CSV;
    44
     5use Box\Spout\Common\Entity\Row;
     6use Box\Spout\Common\Helper\EncodingHelper;
     7use Box\Spout\Common\Helper\GlobalFunctionsHelper;
     8use Box\Spout\Common\Manager\OptionsManagerInterface;
     9use Box\Spout\Reader\Common\Entity\Options;
     10use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
    511use Box\Spout\Reader\IteratorInterface;
    6 use Box\Spout\Common\Helper\EncodingHelper;
    712
    813/**
    914 * Class RowIterator
    1015 * Iterate over CSV rows.
    11  *
    12  * @package Box\Spout\Reader\CSV
    1316 */
    1417class RowIterator implements IteratorInterface
     
    2528    protected $numReadRows = 0;
    2629
    27     /** @var array|null Buffer used to store the row data, while checking if there are more rows to read */
    28     protected $rowDataBuffer = null;
     30    /** @var Row|null Buffer used to store the current row, while checking if there are more rows to read */
     31    protected $rowBuffer;
    2932
    3033    /** @var bool Indicates whether all rows have been read */
     
    4043    protected $encoding;
    4144
    42     /** @var string End of line delimiter, given by the user as input. */
    43     protected $inputEOLDelimiter;
    44 
    4545    /** @var bool Whether empty rows should be returned or skipped */
    4646    protected $shouldPreserveEmptyRows;
    4747
     48    /** @var \Box\Spout\Common\Helper\EncodingHelper Helper to work with different encodings */
     49    protected $encodingHelper;
     50
     51    /** @var \Box\Spout\Reader\CSV\Creator\InternalEntityFactory Factory to create entities */
     52    protected $entityFactory;
     53
    4854    /** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */
    4955    protected $globalFunctionsHelper;
    5056
    51     /** @var \Box\Spout\Common\Helper\EncodingHelper Helper to work with different encodings */
    52     protected $encodingHelper;
    53 
    54     /** @var string End of line delimiter, encoded using the same encoding as the CSV */
    55     protected $encodedEOLDelimiter;
    56 
    5757    /**
    5858     * @param resource $filePointer Pointer to the CSV file to read
    59      * @param \Box\Spout\Reader\CSV\ReaderOptions $options
    60      * @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper
    61      */
    62     public function __construct($filePointer, $options, $globalFunctionsHelper)
    63     {
     59     * @param OptionsManagerInterface $optionsManager
     60     * @param EncodingHelper $encodingHelper
     61     * @param InternalEntityFactory $entityFactory
     62     * @param GlobalFunctionsHelper $globalFunctionsHelper
     63     */
     64    public function __construct(
     65        $filePointer,
     66        OptionsManagerInterface $optionsManager,
     67        EncodingHelper $encodingHelper,
     68        InternalEntityFactory $entityFactory,
     69        GlobalFunctionsHelper $globalFunctionsHelper
     70    ) {
    6471        $this->filePointer = $filePointer;
    65         $this->fieldDelimiter = $options->getFieldDelimiter();
    66         $this->fieldEnclosure = $options->getFieldEnclosure();
    67         $this->encoding = $options->getEncoding();
    68         $this->inputEOLDelimiter = $options->getEndOfLineCharacter();
    69         $this->shouldPreserveEmptyRows = $options->shouldPreserveEmptyRows();
     72        $this->fieldDelimiter = $optionsManager->getOption(Options::FIELD_DELIMITER);
     73        $this->fieldEnclosure = $optionsManager->getOption(Options::FIELD_ENCLOSURE);
     74        $this->encoding = $optionsManager->getOption(Options::ENCODING);
     75        $this->shouldPreserveEmptyRows = $optionsManager->getOption(Options::SHOULD_PRESERVE_EMPTY_ROWS);
     76        $this->encodingHelper = $encodingHelper;
     77        $this->entityFactory = $entityFactory;
    7078        $this->globalFunctionsHelper = $globalFunctionsHelper;
    71 
    72         $this->encodingHelper = new EncodingHelper($globalFunctionsHelper);
    7379    }
    7480
    7581    /**
    7682     * Rewind the Iterator to the first element
    77      * @link http://php.net/manual/en/iterator.rewind.php
     83     * @see http://php.net/manual/en/iterator.rewind.php
    7884     *
    7985     * @return void
     
    8490
    8591        $this->numReadRows = 0;
    86         $this->rowDataBuffer = null;
     92        $this->rowBuffer = null;
    8793
    8894        $this->next();
     
    105111    /**
    106112     * Checks if current position is valid
    107      * @link http://php.net/manual/en/iterator.valid.php
     113     * @see http://php.net/manual/en/iterator.valid.php
    108114     *
    109115     * @return bool
     
    116122    /**
    117123     * Move forward to next element. Reads data for the next unprocessed row.
    118      * @link http://php.net/manual/en/iterator.next.php
    119      *
    120      * @return void
     124     * @see http://php.net/manual/en/iterator.next.php
     125     *
    121126     * @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8
     127     * @return void
    122128     */
    123129    public function next()
     
    131137
    132138    /**
    133      * @return void
    134139     * @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8
     140     * @return void
    135141     */
    136142    protected function readDataForNextRow()
     
    142148        if ($rowData !== false) {
    143149            // str_replace will replace NULL values by empty strings
    144             $this->rowDataBuffer = str_replace(null, null, $rowData);
     150            $rowDataBufferAsArray = str_replace(null, null, $rowData);
     151            $this->rowBuffer = $this->entityFactory->createRowFromArray($rowDataBufferAsArray);
    145152            $this->numReadRows++;
    146153        } else {
     
    172179     * we remove manually whitespace with ltrim or rtrim (depending on the order of the bytes)
    173180     *
     181     * @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8
    174182     * @return array|false The row for the current file pointer, encoded in UTF-8 or FALSE if nothing to read
    175      * @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8
    176183     */
    177184    protected function getNextUTF8EncodedRow()
     
    183190
    184191        foreach ($encodedRowData as $cellIndex => $cellValue) {
    185             switch($this->encoding) {
     192            switch ($this->encoding) {
    186193                case EncodingHelper::ENCODING_UTF16_LE:
    187194                case EncodingHelper::ENCODING_UTF32_LE:
     
    204211
    205212    /**
    206      * Returns the end of line delimiter, encoded using the same encoding as the CSV.
    207      * The return value is cached.
    208      *
    209      * @return string
    210      */
    211     protected function getEncodedEOLDelimiter()
    212     {
    213         if (!isset($this->encodedEOLDelimiter)) {
    214             $this->encodedEOLDelimiter = $this->encodingHelper->attemptConversionFromUTF8($this->inputEOLDelimiter, $this->encoding);
    215         }
    216 
    217         return $this->encodedEOLDelimiter;
    218     }
    219 
    220     /**
    221213     * @param array|bool $lineData Array containing the cells value for the line
    222214     * @return bool Whether the given line is empty
     
    229221    /**
    230222     * Return the current element from the buffer
    231      * @link http://php.net/manual/en/iterator.current.php
    232      *
    233      * @return array|null
     223     * @see http://php.net/manual/en/iterator.current.php
     224     *
     225     * @return Row|null
    234226     */
    235227    public function current()
    236228    {
    237         return $this->rowDataBuffer;
     229        return $this->rowBuffer;
    238230    }
    239231
    240232    /**
    241233     * Return the key of the current element
    242      * @link http://php.net/manual/en/iterator.key.php
     234     * @see http://php.net/manual/en/iterator.key.php
    243235     *
    244236     * @return int
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/CSV/Sheet.php

    r112446 r115670  
    77/**
    88 * Class Sheet
    9  *
    10  * @package Box\Spout\Reader\CSV
    119 */
    1210class Sheet implements SheetInterface
     
    1614
    1715    /**
    18      * @param resource $filePointer Pointer to the CSV file to read
    19      * @param \Box\Spout\Reader\CSV\ReaderOptions $options
    20      * @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper
     16     * @param RowIterator $rowIterator Corresponding row iterator
    2117     */
    22     public function __construct($filePointer, $options, $globalFunctionsHelper)
     18    public function __construct(RowIterator $rowIterator)
    2319    {
    24         $this->rowIterator = new RowIterator($filePointer, $options, $globalFunctionsHelper);
     20        $this->rowIterator = $rowIterator;
    2521    }
    2622
    2723    /**
    28      * @api
    2924     * @return \Box\Spout\Reader\CSV\RowIterator
    3025     */
     
    3530
    3631    /**
    37      * @api
    3832     * @return int Index of the sheet
    3933     */
     
    4438
    4539    /**
    46      * @api
    4740     * @return string Name of the sheet - empty string since CSV does not support that
    4841     */
     
    5346
    5447    /**
    55      * @api
    5648     * @return bool Always TRUE as there is only one sheet
    5749     */
     
    6052        return true;
    6153    }
     54
     55    /**
     56     * @return bool Always TRUE as the only sheet is always visible
     57     */
     58    public function isVisible()
     59    {
     60        return true;
     61    }
    6262}
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/CSV/SheetIterator.php

    r112446 r115670  
    88 * Class SheetIterator
    99 * Iterate over CSV unique "sheet".
    10  *
    11  * @package Box\Spout\Reader\CSV
    1210 */
    1311class SheetIterator implements IteratorInterface
     
    2018
    2119    /**
    22      * @param resource $filePointer
    23      * @param \Box\Spout\Reader\CSV\ReaderOptions $options
    24      * @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper
     20     * @param Sheet $sheet Corresponding unique sheet
    2521     */
    26     public function __construct($filePointer, $options, $globalFunctionsHelper)
     22    public function __construct($sheet)
    2723    {
    28         $this->sheet = new Sheet($filePointer, $options, $globalFunctionsHelper);
     24        $this->sheet = $sheet;
    2925    }
    3026
    3127    /**
    3228     * Rewind the Iterator to the first element
    33      * @link http://php.net/manual/en/iterator.rewind.php
     29     * @see http://php.net/manual/en/iterator.rewind.php
    3430     *
    3531     * @return void
     
    4238    /**
    4339     * Checks if current position is valid
    44      * @link http://php.net/manual/en/iterator.valid.php
     40     * @see http://php.net/manual/en/iterator.valid.php
    4541     *
    4642     * @return bool
     
    5349    /**
    5450     * Move forward to next element
    55      * @link http://php.net/manual/en/iterator.next.php
     51     * @see http://php.net/manual/en/iterator.next.php
    5652     *
    5753     * @return void
     
    6460    /**
    6561     * Return the current element
    66      * @link http://php.net/manual/en/iterator.current.php
     62     * @see http://php.net/manual/en/iterator.current.php
    6763     *
    6864     * @return \Box\Spout\Reader\CSV\Sheet
     
    7571    /**
    7672     * Return the key of the current element
    77      * @link http://php.net/manual/en/iterator.key.php
     73     * @see http://php.net/manual/en/iterator.key.php
    7874     *
    7975     * @return int
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/Common/XMLProcessor.php

    r112446 r115670  
    88 * Class XMLProcessor
    99 * Helps process XML files
    10  *
    11  * @package Box\Spout\Reader\Common
    1210 */
    1311class XMLProcessor
     
    2523    const PROCESSING_STOP = 2;
    2624
    27 
    2825    /** @var \Box\Spout\Reader\Wrapper\XMLReader The XMLReader object that will help read sheet's XML data */
    2926    protected $xmlReader;
     
    3128    /** @var array Registered callbacks */
    3229    private $callbacks = [];
    33 
    3430
    3531    /**
     
    9187     * Stops whenever a callback indicates that reading should stop or at the end of the file.
    9288     *
     89     * @throws \Box\Spout\Reader\Exception\XMLProcessingException
    9390     * @return void
    94      * @throws \Box\Spout\Reader\Exception\XMLProcessingException
    9591     */
    9692    public function readUntilStopped()
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/Exception/IteratorNotRewindableException.php

    r112446 r115670  
    55/**
    66 * Class IteratorNotRewindableException
    7  *
    8  * @api
    9  * @package Box\Spout\Reader\Exception
    107 */
    118class IteratorNotRewindableException extends ReaderException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/Exception/NoSheetsFoundException.php

    r112446 r115670  
    55/**
    66 * Class NoSheetsFoundException
    7  *
    8  * @api
    9  * @package Box\Spout\Reader\Exception
    107 */
    118class NoSheetsFoundException extends ReaderException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/Exception/ReaderException.php

    r112446 r115670  
    88 * Class ReaderException
    99 *
    10  * @package Box\Spout\Reader\Exception
    1110 * @abstract
    1211 */
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/Exception/ReaderNotOpenedException.php

    r112446 r115670  
    55/**
    66 * Class ReaderNotOpenedException
    7  *
    8  * @api
    9  * @package Box\Spout\Reader\Exception
    107 */
    118class ReaderNotOpenedException extends ReaderException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/Exception/SharedStringNotFoundException.php

    r112446 r115670  
    55/**
    66 * Class SharedStringNotFoundException
    7  *
    8  * @api
    9  * @package Box\Spout\Reader\Exception
    107 */
    118class SharedStringNotFoundException extends ReaderException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/Exception/XMLProcessingException.php

    r112446 r115670  
    55/**
    66 * Class XMLProcessingException
    7  *
    8  * @package Box\Spout\Reader\Exception
    97 */
    108class XMLProcessingException extends ReaderException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/IteratorInterface.php

    r112446 r115670  
    55/**
    66 * Interface IteratorInterface
    7  *
    8  * @package Box\Spout\Reader
    97 */
    108interface IteratorInterface extends \Iterator
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/ODS/Helper/CellValueFormatter.php

    r112446 r115670  
    22
    33namespace Box\Spout\Reader\ODS\Helper;
     4
     5use Box\Spout\Reader\Exception\InvalidValueException;
    46
    57/**
    68 * Class CellValueFormatter
    79 * This class provides helper functions to format cell values
    8  *
    9  * @package Box\Spout\Reader\ODS\Helper
    1010 */
    1111class CellValueFormatter
     
    3939    protected $shouldFormatDates;
    4040
    41     /** @var \Box\Spout\Common\Escaper\ODS Used to unescape XML data */
     41    /** @var \Box\Spout\Common\Helper\Escaper\ODS Used to unescape XML data */
    4242    protected $escaper;
    4343
    4444    /**
    4545     * @param bool $shouldFormatDates Whether date/time values should be returned as PHP objects or be formatted as strings
    46      */
    47     public function __construct($shouldFormatDates)
     46     * @param \Box\Spout\Common\Helper\Escaper\ODS $escaper Used to unescape XML data
     47     */
     48    public function __construct($shouldFormatDates, $escaper)
    4849    {
    4950        $this->shouldFormatDates = $shouldFormatDates;
    50 
    51         /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
    52         $this->escaper = \Box\Spout\Common\Escaper\ODS::getInstance();
     51        $this->escaper = $escaper;
    5352    }
    5453
     
    5857     *
    5958     * @param \DOMNode $node
    60      * @return string|int|float|bool|\DateTime|\DateInterval|null The value associated with the cell, empty string if cell's type is void/undefined, null on error
     59     * @throws InvalidValueException If the node value is not valid
     60     * @return string|int|float|bool|\DateTime|\DateInterval The value associated with the cell, empty string if cell's type is void/undefined
    6161     */
    6262    public function extractAndFormatNodeValue($node)
     
    102102                if ($childNode instanceof \DOMText) {
    103103                    $currentPValue .= $childNode->nodeValue;
    104                 } else if ($childNode->nodeName === self::XML_NODE_S) {
     104                } elseif ($childNode->nodeName === self::XML_NODE_S) {
    105105                    $spaceAttribute = $childNode->getAttribute(self::XML_ATTRIBUTE_C);
    106                     $numSpaces = (!empty($spaceAttribute)) ? intval($spaceAttribute) : 1;
     106                    $numSpaces = (!empty($spaceAttribute)) ? (int) $spaceAttribute : 1;
    107107                    $currentPValue .= str_repeat(' ', $numSpaces);
    108                 } else if ($childNode->nodeName === self::XML_NODE_A || $childNode->nodeName === self::XML_NODE_SPAN) {
     108                } elseif ($childNode->nodeName === self::XML_NODE_A || $childNode->nodeName === self::XML_NODE_SPAN) {
    109109                    $currentPValue .= $childNode->nodeValue;
    110110                }
     
    116116        $escapedCellValue = implode("\n", $pNodeValues);
    117117        $cellValue = $this->escaper->unescape($escapedCellValue);
     118
    118119        return $cellValue;
    119120    }
     
    128129    {
    129130        $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_VALUE);
    130         $nodeIntValue = intval($nodeValue);
    131         // The "==" is intentionally not a "===" because only the value matters, not the type
    132         $cellValue = ($nodeIntValue == $nodeValue) ? $nodeIntValue : floatval($nodeValue);
     131
     132        $nodeIntValue = (int) $nodeValue;
     133        $nodeFloatValue = (float) $nodeValue;
     134        $cellValue = ((float) $nodeIntValue === $nodeFloatValue) ? $nodeIntValue : $nodeFloatValue;
     135
    133136        return $cellValue;
    134137    }
     
    143146    {
    144147        $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_BOOLEAN_VALUE);
    145         // !! is similar to boolval()
    146         $cellValue = !!$nodeValue;
    147         return $cellValue;
     148
     149        return (bool) $nodeValue;
    148150    }
    149151
     
    152154     *
    153155     * @param \DOMNode $node
    154      * @return \DateTime|string|null The value associated with the cell or NULL if invalid date value
     156     * @throws InvalidValueException If the value is not a valid date
     157     * @return \DateTime|string The value associated with the cell
    155158     */
    156159    protected function formatDateCellValue($node)
     
    164167            // The date is already formatted in the "p" tag
    165168            $nodeWithValueAlreadyFormatted = $node->getElementsByTagName(self::XML_NODE_P)->item(0);
    166             return $nodeWithValueAlreadyFormatted->nodeValue;
     169            $cellValue = $nodeWithValueAlreadyFormatted->nodeValue;
    167170        } else {
    168171            // otherwise, get it from the "date-value" attribute
     172            $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_DATE_VALUE);
    169173            try {
    170                 $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_DATE_VALUE);
    171                 return new \DateTime($nodeValue);
     174                $cellValue = new \DateTime($nodeValue);
    172175            } catch (\Exception $e) {
    173                 return null;
     176                throw new InvalidValueException($nodeValue);
    174177            }
    175178        }
     179
     180        return $cellValue;
    176181    }
    177182
     
    180185     *
    181186     * @param \DOMNode $node
    182      * @return \DateInterval|string|null The value associated with the cell or NULL if invalid time value
     187     * @throws InvalidValueException If the value is not a valid time
     188     * @return \DateInterval|string The value associated with the cell
    183189     */
    184190    protected function formatTimeCellValue($node)
     
    192198            // The date is already formatted in the "p" tag
    193199            $nodeWithValueAlreadyFormatted = $node->getElementsByTagName(self::XML_NODE_P)->item(0);
    194             return $nodeWithValueAlreadyFormatted->nodeValue;
     200            $cellValue = $nodeWithValueAlreadyFormatted->nodeValue;
    195201        } else {
    196202            // otherwise, get it from the "time-value" attribute
     203            $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_TIME_VALUE);
    197204            try {
    198                 $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_TIME_VALUE);
    199                 return new \DateInterval($nodeValue);
     205                $cellValue = new \DateInterval($nodeValue);
    200206            } catch (\Exception $e) {
    201                 return null;
     207                throw new InvalidValueException($nodeValue);
    202208            }
    203209        }
     210
     211        return $cellValue;
    204212    }
    205213
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/ODS/Helper/SettingsHelper.php

    r112446 r115670  
    44
    55use Box\Spout\Reader\Exception\XMLProcessingException;
    6 use Box\Spout\Reader\Wrapper\XMLReader;
     6use Box\Spout\Reader\ODS\Creator\InternalEntityFactory;
    77
    88/**
    99 * Class SettingsHelper
    1010 * This class provides helper functions to extract data from the "settings.xml" file.
    11  *
    12  * @package Box\Spout\Reader\ODS\Helper
    1311 */
    1412class SettingsHelper
     
    2119    const XML_ATTRIBUTE_VALUE_ACTIVE_TABLE = 'ActiveTable';
    2220
     21    /** @var InternalEntityFactory Factory to create entities */
     22    private $entityFactory;
     23
     24    /**
     25     * @param InternalEntityFactory $entityFactory Factory to create entities
     26     */
     27    public function __construct($entityFactory)
     28    {
     29        $this->entityFactory = $entityFactory;
     30    }
     31
    2332    /**
    2433     * @param string $filePath Path of the file to be read
     
    2736    public function getActiveSheetName($filePath)
    2837    {
    29         $xmlReader = new XMLReader();
     38        $xmlReader = $this->entityFactory->createXMLReader();
    3039        if ($xmlReader->openFileInZip($filePath, self::SETTINGS_XML_FILE_PATH) === false) {
    3140            return null;
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/ODS/Reader.php

    r112446 r115670  
    44
    55use Box\Spout\Common\Exception\IOException;
    6 use Box\Spout\Reader\AbstractReader;
     6use Box\Spout\Reader\ODS\Creator\InternalEntityFactory;
     7use Box\Spout\Reader\ReaderAbstract;
    78
    89/**
    910 * Class Reader
    1011 * This class provides support to read data from a ODS file
    11  *
    12  * @package Box\Spout\Reader\ODS
    1312 */
    14 class Reader extends AbstractReader
     13class Reader extends ReaderAbstract
    1514{
    1615    /** @var \ZipArchive */
     
    1918    /** @var SheetIterator To iterator over the ODS sheets */
    2019    protected $sheetIterator;
    21 
    22     /**
    23      * Returns the reader's current options
    24      *
    25      * @return ReaderOptions
    26      */
    27     protected function getOptions()
    28     {
    29         if (!isset($this->options)) {
    30             $this->options = new ReaderOptions();
    31         }
    32         return $this->options;
    33     }
    3420
    3521    /**
     
    4733     *
    4834     * @param  string $filePath Path of the file to be read
    49      * @return void
    5035     * @throws \Box\Spout\Common\Exception\IOException If the file at the given path or its content cannot be read
    5136     * @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file
     37     * @return void
    5238     */
    5339    protected function openReader($filePath)
    5440    {
    55         $this->zip = new \ZipArchive();
     41        /** @var InternalEntityFactory $entityFactory */
     42        $entityFactory = $this->entityFactory;
     43
     44        $this->zip = $entityFactory->createZipArchive();
    5645
    5746        if ($this->zip->open($filePath) === true) {
    58             $this->sheetIterator = new SheetIterator($filePath, $this->getOptions());
     47            /** @var InternalEntityFactory $entityFactory */
     48            $entityFactory = $this->entityFactory;
     49            $this->sheetIterator = $entityFactory->createSheetIterator($filePath, $this->optionsManager);
    5950        } else {
    6051            throw new IOException("Could not open $filePath for reading.");
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/ODS/RowIterator.php

    r112446 r115670  
    33namespace Box\Spout\Reader\ODS;
    44
     5use Box\Spout\Common\Entity\Cell;
     6use Box\Spout\Common\Entity\Row;
    57use Box\Spout\Common\Exception\IOException;
     8use Box\Spout\Common\Manager\OptionsManagerInterface;
     9use Box\Spout\Reader\Common\Entity\Options;
     10use Box\Spout\Reader\Common\Manager\RowManager;
     11use Box\Spout\Reader\Common\XMLProcessor;
     12use Box\Spout\Reader\Exception\InvalidValueException;
    613use Box\Spout\Reader\Exception\IteratorNotRewindableException;
    714use Box\Spout\Reader\Exception\XMLProcessingException;
    815use Box\Spout\Reader\IteratorInterface;
     16use Box\Spout\Reader\ODS\Creator\InternalEntityFactory;
    917use Box\Spout\Reader\ODS\Helper\CellValueFormatter;
    1018use Box\Spout\Reader\Wrapper\XMLReader;
    11 use Box\Spout\Reader\Common\XMLProcessor;
    1219
    1320/**
    1421 * Class RowIterator
    15  *
    16  * @package Box\Spout\Reader\ODS
    1722 */
    1823class RowIterator implements IteratorInterface
     
    4045    protected $cellValueFormatter;
    4146
     47    /** @var RowManager Manages rows */
     48    protected $rowManager;
     49
     50    /** @var InternalEntityFactory Factory to create entities */
     51    protected $entityFactory;
     52
    4253    /** @var bool Whether the iterator has already been rewound once */
    4354    protected $hasAlreadyBeenRewound = false;
    4455
    45     /** @var array Contains the data for the currently processed row (key = cell index, value = cell value) */
    46     protected $currentlyProcessedRowData = [];
    47 
    48     /** @var array|null Buffer used to store the row data, while checking if there are more rows to read */
    49     protected $rowDataBuffer = null;
     56    /** @var Row The currently processed row */
     57    protected $currentlyProcessedRow;
     58
     59    /** @var Row Buffer used to store the current row, while checking if there are more rows to read */
     60    protected $rowBuffer;
    5061
    5162    /** @var bool Indicates whether all rows have been read */
     
    5869    protected $nextRowIndexToBeProcessed = 1;
    5970
    60     /** @var mixed|null Value of the last processed cell (because when reading cell at column N+1, cell N is processed) */
    61     protected $lastProcessedCellValue = null;
     71    /** @var Cell Last processed cell (because when reading cell at column N+1, cell N is processed) */
     72    protected $lastProcessedCell;
    6273
    6374    /** @var int Number of times the last processed row should be repeated */
     
    7081    protected $hasAlreadyReadOneCellInCurrentRow = false;
    7182
    72 
    7383    /**
    7484     * @param XMLReader $xmlReader XML Reader, positioned on the "<table:table>" element
    75      * @param \Box\Spout\Reader\ODS\ReaderOptions $options Reader's current options
    76      */
    77     public function __construct($xmlReader, $options)
    78     {
     85     * @param OptionsManagerInterface $optionsManager Reader's options manager
     86     * @param CellValueFormatter $cellValueFormatter Helper to format cell values
     87     * @param XMLProcessor $xmlProcessor Helper to process XML files
     88     * @param RowManager $rowManager Manages rows
     89     * @param InternalEntityFactory $entityFactory Factory to create entities
     90     */
     91    public function __construct(
     92        XMLReader $xmlReader,
     93        OptionsManagerInterface $optionsManager,
     94        CellValueFormatter $cellValueFormatter,
     95        XMLProcessor $xmlProcessor,
     96        RowManager $rowManager,
     97        InternalEntityFactory $entityFactory
     98    ) {
    7999        $this->xmlReader = $xmlReader;
    80         $this->shouldPreserveEmptyRows = $options->shouldPreserveEmptyRows();
    81         $this->cellValueFormatter = new CellValueFormatter($options->shouldFormatDates());
     100        $this->shouldPreserveEmptyRows = $optionsManager->getOption(Options::SHOULD_PRESERVE_EMPTY_ROWS);
     101        $this->cellValueFormatter = $cellValueFormatter;
     102        $this->entityFactory = $entityFactory;
     103        $this->rowManager = $rowManager;
    82104
    83105        // Register all callbacks to process different nodes when reading the XML file
    84         $this->xmlProcessor = new XMLProcessor($this->xmlReader);
     106        $this->xmlProcessor = $xmlProcessor;
    85107        $this->xmlProcessor->registerCallback(self::XML_NODE_ROW, XMLProcessor::NODE_TYPE_START, [$this, 'processRowStartingNode']);
    86108        $this->xmlProcessor->registerCallback(self::XML_NODE_CELL, XMLProcessor::NODE_TYPE_START, [$this, 'processCellStartingNode']);
     
    92114     * Rewind the Iterator to the first element.
    93115     * NOTE: It can only be done once, as it is not possible to read an XML file backwards.
    94      * @link http://php.net/manual/en/iterator.rewind.php
    95      *
     116     * @see http://php.net/manual/en/iterator.rewind.php
     117     *
     118     * @throws \Box\Spout\Reader\Exception\IteratorNotRewindableException If the iterator is rewound more than once
    96119     * @return void
    97      * @throws \Box\Spout\Reader\Exception\IteratorNotRewindableException If the iterator is rewound more than once
    98120     */
    99121    public function rewind()
     
    109131        $this->lastRowIndexProcessed = 0;
    110132        $this->nextRowIndexToBeProcessed = 1;
    111         $this->rowDataBuffer = null;
     133        $this->rowBuffer = null;
    112134        $this->hasReachedEndOfFile = false;
    113135
     
    117139    /**
    118140     * Checks if current position is valid
    119      * @link http://php.net/manual/en/iterator.valid.php
     141     * @see http://php.net/manual/en/iterator.valid.php
    120142     *
    121143     * @return bool
     
    128150    /**
    129151     * Move forward to next element. Empty rows will be skipped.
    130      * @link http://php.net/manual/en/iterator.next.php
    131      *
    132      * @return void
     152     * @see http://php.net/manual/en/iterator.next.php
     153     *
    133154     * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If a shared string was not found
    134155     * @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML
     156     * @return void
    135157     */
    136158    public function next()
     
    163185
    164186    /**
    165      * @return void
    166187     * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If a shared string was not found
    167188     * @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML
     189     * @return void
    168190     */
    169191    protected function readDataForNextRow()
    170192    {
    171         $this->currentlyProcessedRowData = [];
     193        $this->currentlyProcessedRow = $this->entityFactory->createRow();
    172194
    173195        try {
     
    177199        }
    178200
    179         $this->rowDataBuffer = $this->currentlyProcessedRowData;
     201        $this->rowBuffer = $this->currentlyProcessedRow;
    180202    }
    181203
     
    188210        // Reset data from current row
    189211        $this->hasAlreadyReadOneCellInCurrentRow = false;
    190         $this->lastProcessedCellValue = null;
     212        $this->lastProcessedCell = null;
    191213        $this->numColumnsRepeated = 1;
    192214        $this->numRowsRepeated = $this->getNumRowsRepeatedForCurrentNode($xmlReader);
     
    205227        // NOTE: expand() will automatically decode all XML entities of the child nodes
    206228        $node = $xmlReader->expand();
    207         $currentCellValue = $this->getCellValue($node);
     229        $currentCell = $this->getCell($node);
    208230
    209231        // process cell N only after having read cell N+1 (see below why)
    210232        if ($this->hasAlreadyReadOneCellInCurrentRow) {
    211233            for ($i = 0; $i < $this->numColumnsRepeated; $i++) {
    212                 $this->currentlyProcessedRowData[] = $this->lastProcessedCellValue;
     234                $this->currentlyProcessedRow->addCell($this->lastProcessedCell);
    213235            }
    214236        }
    215237
    216238        $this->hasAlreadyReadOneCellInCurrentRow = true;
    217         $this->lastProcessedCellValue = $currentCellValue;
     239        $this->lastProcessedCell = $currentCell;
    218240        $this->numColumnsRepeated = $currentNumColumnsRepeated;
    219241
     
    226248    protected function processRowEndingNode()
    227249    {
    228         $isEmptyRow = $this->isEmptyRow($this->currentlyProcessedRowData, $this->lastProcessedCellValue);
     250        $isEmptyRow = $this->isEmptyRow($this->currentlyProcessedRow, $this->lastProcessedCell);
    229251
    230252        // if the fetched row is empty and we don't want to preserve it...
     
    236258        // if the row is empty, we don't want to return more than one cell
    237259        $actualNumColumnsRepeated = (!$isEmptyRow) ? $this->numColumnsRepeated : 1;
     260        $numCellsInCurrentlyProcessedRow = $this->currentlyProcessedRow->getNumCells();
    238261
    239262        // Only add the value if the last read cell is not a trailing empty cell repeater in Excel.
     
    243266        // In Excel, the number of supported columns is 16384, but we don't want to returns rows with
    244267        // always 16384 cells.
    245         if ((count($this->currentlyProcessedRowData) + $actualNumColumnsRepeated) !== self::MAX_COLUMNS_EXCEL) {
     268        if (($numCellsInCurrentlyProcessedRow + $actualNumColumnsRepeated) !== self::MAX_COLUMNS_EXCEL) {
    246269            for ($i = 0; $i < $actualNumColumnsRepeated; $i++) {
    247                 $this->currentlyProcessedRowData[] = $this->lastProcessedCellValue;
     270                $this->currentlyProcessedRow->addCell($this->lastProcessedCell);
    248271            }
    249272        }
     
    276299    {
    277300        $numRowsRepeated = $xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_ROWS_REPEATED);
    278         return ($numRowsRepeated !== null) ? intval($numRowsRepeated) : 1;
     301
     302        return ($numRowsRepeated !== null) ? (int) $numRowsRepeated : 1;
    279303    }
    280304
     
    286310    {
    287311        $numColumnsRepeated = $xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_COLUMNS_REPEATED);
    288         return ($numColumnsRepeated !== null) ? intval($numColumnsRepeated) : 1;
    289     }
    290 
    291     /**
    292      * Returns the (unescaped) correctly marshalled, cell value associated to the given XML node.
     312
     313        return ($numColumnsRepeated !== null) ? (int) $numColumnsRepeated : 1;
     314    }
     315
     316    /**
     317     * Returns the cell with (unescaped) correctly marshalled, cell value associated to the given XML node.
    293318     *
    294319     * @param \DOMNode $node
    295      * @return string|int|float|bool|\DateTime|\DateInterval|null The value associated with the cell, empty string if cell's type is void/undefined, null on error
    296      */
    297     protected function getCellValue($node)
    298     {
    299         return $this->cellValueFormatter->extractAndFormatNodeValue($node);
     320     * @return Cell The cell set with the associated with the cell
     321     */
     322    protected function getCell($node)
     323    {
     324        try {
     325            $cellValue = $this->cellValueFormatter->extractAndFormatNodeValue($node);
     326            $cell = $this->entityFactory->createCell($cellValue);
     327        } catch (InvalidValueException $exception) {
     328            $cell = $this->entityFactory->createCell($exception->getInvalidValue());
     329            $cell->setType(Cell::TYPE_ERROR);
     330        }
     331
     332        return $cell;
    300333    }
    301334
    302335    /**
    303336     * After finishing processing each cell, a row is considered empty if it contains
    304      * no cells or if the value of the last read cell is an empty string.
     337     * no cells or if the last read cell is empty.
    305338     * After finishing processing each cell, the last read cell is not part of the
    306339     * row data yet (as we still need to apply the "num-columns-repeated" attribute).
    307340     *
    308      * @param array $rowData
    309      * @param string|int|float|bool|\DateTime|\DateInterval|null The value of the last read cell
     341     * @param Row $currentRow
     342     * @param Cell $lastReadCell The last read cell
    310343     * @return bool Whether the row is empty
    311344     */
    312     protected function isEmptyRow($rowData, $lastReadCellValue)
     345    protected function isEmptyRow($currentRow, $lastReadCell)
    313346    {
    314347        return (
    315             count($rowData) === 0 &&
    316             (!isset($lastReadCellValue) || trim($lastReadCellValue) === '')
     348            $this->rowManager->isEmpty($currentRow) &&
     349            (!isset($lastReadCell) || $lastReadCell->isEmpty())
    317350        );
    318351    }
     
    320353    /**
    321354     * Return the current element, from the buffer.
    322      * @link http://php.net/manual/en/iterator.current.php
    323      *
    324      * @return array|null
     355     * @see http://php.net/manual/en/iterator.current.php
     356     *
     357     * @return Row
    325358     */
    326359    public function current()
    327360    {
    328         return $this->rowDataBuffer;
     361        return $this->rowBuffer;
    329362    }
    330363
    331364    /**
    332365     * Return the key of the current element
    333      * @link http://php.net/manual/en/iterator.key.php
     366     * @see http://php.net/manual/en/iterator.key.php
    334367     *
    335368     * @return int
     
    340373    }
    341374
    342 
    343375    /**
    344376     * Cleans up what was created to iterate over the object.
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/ODS/Sheet.php

    r112446 r115670  
    44
    55use Box\Spout\Reader\SheetInterface;
    6 use Box\Spout\Reader\Wrapper\XMLReader;
    76
    87/**
    98 * Class Sheet
    109 * Represents a sheet within a ODS file
    11  *
    12  * @package Box\Spout\Reader\ODS
    1310 */
    1411class Sheet implements SheetInterface
     
    2926    protected $isActive;
    3027
     28    /** @var bool Whether the sheet is visible */
     29    protected $isVisible;
     30
    3131    /**
    32      * @param XMLReader $xmlReader XML Reader, positioned on the "<table:table>" element
     32     * @param RowIterator $rowIterator The corresponding row iterator
    3333     * @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based)
    3434     * @param string $sheetName Name of the sheet
    3535     * @param bool $isSheetActive Whether the sheet was defined as active
    36      * @param \Box\Spout\Reader\ODS\ReaderOptions $options Reader's current options
     36     * @param bool $isSheetVisible Whether the sheet is visible
    3737     */
    38     public function __construct($xmlReader, $sheetIndex, $sheetName, $isSheetActive, $options)
     38    public function __construct($rowIterator, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible)
    3939    {
    40         $this->rowIterator = new RowIterator($xmlReader, $options);
     40        $this->rowIterator = $rowIterator;
    4141        $this->index = $sheetIndex;
    4242        $this->name = $sheetName;
    4343        $this->isActive = $isSheetActive;
     44        $this->isVisible = $isSheetVisible;
    4445    }
    4546
    4647    /**
    47      * @api
    4848     * @return \Box\Spout\Reader\ODS\RowIterator
    4949     */
     
    5454
    5555    /**
    56      * @api
    5756     * @return int Index of the sheet, based on order in the workbook (zero-based)
    5857     */
     
    6362
    6463    /**
    65      * @api
    6664     * @return string Name of the sheet
    6765     */
     
    7270
    7371    /**
    74      * @api
    7572     * @return bool Whether the sheet was defined as active
    7673     */
     
    7976        return $this->isActive;
    8077    }
     78
     79    /**
     80     * @return bool Whether the sheet is visible
     81     */
     82    public function isVisible()
     83    {
     84        return $this->isVisible;
     85    }
    8186}
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/ODS/SheetIterator.php

    r112446 r115670  
    66use Box\Spout\Reader\Exception\XMLProcessingException;
    77use Box\Spout\Reader\IteratorInterface;
     8use Box\Spout\Reader\ODS\Creator\InternalEntityFactory;
    89use Box\Spout\Reader\ODS\Helper\SettingsHelper;
    910use Box\Spout\Reader\Wrapper\XMLReader;
     
    1213 * Class SheetIterator
    1314 * Iterate over ODS sheet.
    14  *
    15  * @package Box\Spout\Reader\ODS
    1615 */
    1716class SheetIterator implements IteratorInterface
     
    1918    const CONTENT_XML_FILE_PATH = 'content.xml';
    2019
     20    const XML_STYLE_NAMESPACE = 'urn:oasis:names:tc:opendocument:xmlns:style:1.0';
     21
    2122    /** Definition of XML nodes name and attribute used to parse sheet data */
     23    const XML_NODE_AUTOMATIC_STYLES = 'office:automatic-styles';
     24    const XML_NODE_STYLE_TABLE_PROPERTIES = 'table-properties';
    2225    const XML_NODE_TABLE = 'table:table';
     26    const XML_ATTRIBUTE_STYLE_NAME = 'style:name';
    2327    const XML_ATTRIBUTE_TABLE_NAME = 'table:name';
     28    const XML_ATTRIBUTE_TABLE_STYLE_NAME = 'table:style-name';
     29    const XML_ATTRIBUTE_TABLE_DISPLAY = 'table:display';
    2430
    2531    /** @var string $filePath Path of the file to be read */
    2632    protected $filePath;
    2733
    28     /** @var \Box\Spout\Reader\ODS\ReaderOptions Reader's current options */
    29     protected $options;
     34    /** @var \Box\Spout\Common\Manager\OptionsManagerInterface Reader's options manager */
     35    protected $optionsManager;
     36
     37    /** @var InternalEntityFactory $entityFactory Factory to create entities */
     38    protected $entityFactory;
    3039
    3140    /** @var XMLReader The XMLReader object that will help read sheet's XML data */
    3241    protected $xmlReader;
    3342
    34     /** @var \Box\Spout\Common\Escaper\ODS Used to unescape XML data */
     43    /** @var \Box\Spout\Common\Helper\Escaper\ODS Used to unescape XML data */
    3544    protected $escaper;
    3645
     
    4453    protected $activeSheetName;
    4554
     55    /** @var array Associative array [STYLE_NAME] => [IS_SHEET_VISIBLE] */
     56    protected $sheetsVisibility;
     57
    4658    /**
    4759     * @param string $filePath Path of the file to be read
    48      * @param \Box\Spout\Reader\ODS\ReaderOptions $options Reader's current options
    49      * @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file
    50      */
    51     public function __construct($filePath, $options)
     60     * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager
     61     * @param \Box\Spout\Common\Helper\Escaper\ODS $escaper Used to unescape XML data
     62     * @param SettingsHelper $settingsHelper Helper to get data from "settings.xml"
     63     * @param InternalEntityFactory $entityFactory Factory to create entities
     64     */
     65    public function __construct($filePath, $optionsManager, $escaper, $settingsHelper, $entityFactory)
    5266    {
    5367        $this->filePath = $filePath;
    54         $this->options = $options;
    55         $this->xmlReader = new XMLReader();
    56 
    57         /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
    58         $this->escaper = \Box\Spout\Common\Escaper\ODS::getInstance();
    59 
    60         $settingsHelper = new SettingsHelper();
     68        $this->optionsManager = $optionsManager;
     69        $this->entityFactory = $entityFactory;
     70        $this->xmlReader = $entityFactory->createXMLReader();
     71        $this->escaper = $escaper;
    6172        $this->activeSheetName = $settingsHelper->getActiveSheetName($filePath);
    6273    }
     
    6475    /**
    6576     * Rewind the Iterator to the first element
    66      * @link http://php.net/manual/en/iterator.rewind.php
    67      *
     77     * @see http://php.net/manual/en/iterator.rewind.php
     78     *
     79     * @throws \Box\Spout\Common\Exception\IOException If unable to open the XML file containing sheets' data
    6880     * @return void
    69      * @throws \Box\Spout\Common\Exception\IOException If unable to open the XML file containing sheets' data
    7081     */
    7182    public function rewind()
     
    7990
    8091        try {
     92            $this->sheetsVisibility = $this->readSheetsVisibility();
    8193            $this->hasFoundSheet = $this->xmlReader->readUntilNodeFound(self::XML_NODE_TABLE);
    8294        } catch (XMLProcessingException $exception) {
    83            throw new IOException("The content.xml file is invalid and cannot be read. [{$exception->getMessage()}]");
    84        }
     95            throw new IOException("The content.xml file is invalid and cannot be read. [{$exception->getMessage()}]");
     96        }
    8597
    8698        $this->currentSheetIndex = 0;
     
    88100
    89101    /**
     102     * Extracts the visibility of the sheets
     103     *
     104     * @return array Associative array [STYLE_NAME] => [IS_SHEET_VISIBLE]
     105     */
     106    private function readSheetsVisibility()
     107    {
     108        $sheetsVisibility = [];
     109
     110        $this->xmlReader->readUntilNodeFound(self::XML_NODE_AUTOMATIC_STYLES);
     111        $automaticStylesNode = $this->xmlReader->expand();
     112
     113        $tableStyleNodes = $automaticStylesNode->getElementsByTagNameNS(self::XML_STYLE_NAMESPACE, self::XML_NODE_STYLE_TABLE_PROPERTIES);
     114
     115        /** @var \DOMElement $tableStyleNode */
     116        foreach ($tableStyleNodes as $tableStyleNode) {
     117            $isSheetVisible = ($tableStyleNode->getAttribute(self::XML_ATTRIBUTE_TABLE_DISPLAY) !== 'false');
     118
     119            $parentStyleNode = $tableStyleNode->parentNode;
     120            $styleName = $parentStyleNode->getAttribute(self::XML_ATTRIBUTE_STYLE_NAME);
     121
     122            $sheetsVisibility[$styleName] = $isSheetVisible;
     123        }
     124
     125        return $sheetsVisibility;
     126    }
     127
     128    /**
    90129     * Checks if current position is valid
    91      * @link http://php.net/manual/en/iterator.valid.php
     130     * @see http://php.net/manual/en/iterator.valid.php
    92131     *
    93132     * @return bool
     
    100139    /**
    101140     * Move forward to next element
    102      * @link http://php.net/manual/en/iterator.next.php
     141     * @see http://php.net/manual/en/iterator.next.php
    103142     *
    104143     * @return void
     
    115154    /**
    116155     * Return the current element
    117      * @link http://php.net/manual/en/iterator.current.php
     156     * @see http://php.net/manual/en/iterator.current.php
    118157     *
    119158     * @return \Box\Spout\Reader\ODS\Sheet
     
    123162        $escapedSheetName = $this->xmlReader->getAttribute(self::XML_ATTRIBUTE_TABLE_NAME);
    124163        $sheetName = $this->escaper->unescape($escapedSheetName);
    125         $isActiveSheet = $this->isActiveSheet($sheetName, $this->currentSheetIndex, $this->activeSheetName);
    126 
    127         return new Sheet($this->xmlReader, $this->currentSheetIndex, $sheetName, $isActiveSheet, $this->options);
     164
     165        $isSheetActive = $this->isSheetActive($sheetName, $this->currentSheetIndex, $this->activeSheetName);
     166
     167        $sheetStyleName = $this->xmlReader->getAttribute(self::XML_ATTRIBUTE_TABLE_STYLE_NAME);
     168        $isSheetVisible = $this->isSheetVisible($sheetStyleName);
     169
     170        return $this->entityFactory->createSheet(
     171            $this->xmlReader,
     172            $this->currentSheetIndex,
     173            $sheetName,
     174            $isSheetActive,
     175            $isSheetVisible,
     176            $this->optionsManager
     177        );
    128178    }
    129179
     
    133183     * @param string $sheetName Name of the current sheet
    134184     * @param int $sheetIndex Index of the current sheet
    135      * @param string|null Name of the sheet that was defined as active or NULL if none defined
     185     * @param string|null $activeSheetName Name of the sheet that was defined as active or NULL if none defined
    136186     * @return bool Whether the current sheet was defined as the active one
    137187     */
    138     private function isActiveSheet($sheetName, $sheetIndex, $activeSheetName)
     188    private function isSheetActive($sheetName, $sheetIndex, $activeSheetName)
    139189    {
    140190        // The given sheet is active if its name matches the defined active sheet's name
     
    147197
    148198    /**
     199     * Returns whether the current sheet is visible
     200     *
     201     * @param string $sheetStyleName Name of the sheet style
     202     * @return bool Whether the current sheet is visible
     203     */
     204    private function isSheetVisible($sheetStyleName)
     205    {
     206        return isset($this->sheetsVisibility[$sheetStyleName]) ?
     207            $this->sheetsVisibility[$sheetStyleName] :
     208            true;
     209    }
     210
     211    /**
    149212     * Return the key of the current element
    150      * @link http://php.net/manual/en/iterator.key.php
     213     * @see http://php.net/manual/en/iterator.key.php
    151214     *
    152215     * @return int
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/ReaderInterface.php

    r112446 r115670  
    55/**
    66 * Interface ReaderInterface
    7  *
    8  * @package Box\Spout\Reader
    97 */
    108interface ReaderInterface
     
    1513     *
    1614     * @param  string $filePath Path of the file to be read
     15     * @throws \Box\Spout\Common\Exception\IOException
    1716     * @return void
    18      * @throws \Box\Spout\Common\Exception\IOException
    1917     */
    2018    public function open($filePath);
     
    2321     * Returns an iterator to iterate over sheets.
    2422     *
     23     * @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException If called before opening the reader
    2524     * @return \Iterator To iterate over sheets
    26      * @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException If called before opening the reader
    2725     */
    2826    public function getSheetIterator();
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/SheetInterface.php

    r112446 r115670  
    55/**
    66 * Interface SheetInterface
    7  *
    8  * @package Box\Spout\Reader
    97 */
    108interface SheetInterface
    119{
    1210    /**
    13      * Returns an iterator to iterate over the sheet's rows.
    14      *
    15      * @return \Iterator
     11     * @return IteratorInterface Iterator to iterate over the sheet's rows.
    1612     */
    1713    public function getRowIterator();
     14
     15    /**
     16     * @return int Index of the sheet
     17     */
     18    public function getIndex();
     19
     20    /**
     21     * @return string Name of the sheet
     22     */
     23    public function getName();
     24
     25    /**
     26     * @return bool Whether the sheet was defined as active
     27     */
     28    public function isActive();
     29
     30    /**
     31     * @return bool Whether the sheet is visible
     32     */
     33    public function isVisible();
    1834}
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/Wrapper/XMLInternalErrorsHelper.php

    r112446 r115670  
    77/**
    88 * Trait XMLInternalErrorsHelper
    9  *
    10  * @package Box\Spout\Reader\Wrapper
    119 */
    1210trait XMLInternalErrorsHelper
     
    3129     * It also always resets the "libxml_use_internal_errors" setting back to its initial value.
    3230     *
     31     * @throws \Box\Spout\Reader\Exception\XMLProcessingException
    3332     * @return void
    34      * @throws \Box\Spout\Reader\Exception\XMLProcessingException
    3533     */
    3634    protected function resetXMLInternalErrorsSettingAndThrowIfXMLErrorOccured()
     
    5856     * @see libxml_get_last_error
    5957     *
    60      * @return String|null Last XML error message or null if no error
     58     * @return string|null Last XML error message or null if no error
    6159     */
    6260    private function getLastXMLErrorMessage()
     
    7977        libxml_use_internal_errors($this->initialUseInternalErrorsValue);
    8078    }
    81 
    8279}
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/Wrapper/XMLReader.php

    r112446 r115670  
    22
    33namespace Box\Spout\Reader\Wrapper;
    4 use DOMNode;
    5 
    64
    75/**
     
    97 * Wrapper around the built-in XMLReader
    108 * @see \XMLReader
    11  *
    12  * @package Box\Spout\Reader\Wrapper
    139 */
    1410class XMLReader extends \XMLReader
     
    5046    public function getRealPathURIForFileInZip($zipFilePath, $fileInsideZipPath)
    5147    {
    52         return (self::ZIP_WRAPPER . realpath($zipFilePath) . '#' . $fileInsideZipPath);
     48        // The file path should not start with a '/', otherwise it won't be found
     49        $fileInsideZipPathWithoutLeadingSlash = ltrim($fileInsideZipPath, '/');
     50
     51        return (self::ZIP_WRAPPER . realpath($zipFilePath) . '#' . $fileInsideZipPathWithoutLeadingSlash);
    5352    }
    5453
     
    8281     * @see \XMLReader::read
    8382     *
     83     * @throws \Box\Spout\Reader\Exception\XMLProcessingException If an error/warning occurred
    8484     * @return bool TRUE on success or FALSE on failure
    85      * @throws \Box\Spout\Reader\Exception\XMLProcessingException If an error/warning occurred
    8685     */
    8786    public function read()
     
    10099     *
    101100     * @param string $nodeName Name of the node to find
     101     * @throws \Box\Spout\Reader\Exception\XMLProcessingException If an error/warning occurred
    102102     * @return bool TRUE on success or FALSE on failure
    103      * @throws \Box\Spout\Reader\Exception\XMLProcessingException If an error/warning occurred
    104103     */
    105104    public function readUntilNodeFound($nodeName)
     
    117116     * @see \XMLReader::next
    118117     *
    119      * @param string|void $localName The name of the next node to move to
     118     * @param string|null $localName The name of the next node to move to
     119     * @throws \Box\Spout\Reader\Exception\XMLProcessingException If an error/warning occurred
    120120     * @return bool TRUE on success or FALSE on failure
    121      * @throws \Box\Spout\Reader\Exception\XMLProcessingException If an error/warning occurred
    122121     */
    123122    public function next($localName = null)
     
    138137    public function isPositionedOnStartingNode($nodeName)
    139138    {
    140         return $this->isPositionedOnNode($nodeName, XMLReader::ELEMENT);
     139        return $this->isPositionedOnNode($nodeName, self::ELEMENT);
    141140    }
    142141
     
    147146    public function isPositionedOnEndingNode($nodeName)
    148147    {
    149         return $this->isPositionedOnNode($nodeName, XMLReader::END_ELEMENT);
     148        return $this->isPositionedOnNode($nodeName, self::END_ELEMENT);
    150149    }
    151150
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/XLSX/Helper/CellHelper.php

    r112446 r115670  
    88 * Class CellHelper
    99 * This class provides helper functions when working with cells
    10  *
    11  * @package Box\Spout\Reader\XLSX\Helper
    1210 */
    1311class CellHelper
     
    2220
    2321    /**
    24      * Fills the missing indexes of an array with a given value.
    25      * For instance, $dataArray = []; $a[1] = 1; $a[3] = 3;
    26      * Calling fillMissingArrayIndexes($dataArray, 'FILL') will return this array: ['FILL', 1, 'FILL', 3]
    27      *
    28      * @param array $dataArray The array to fill
    29      * @param string|void $fillValue optional
    30      * @return array
    31      */
    32     public static function fillMissingArrayIndexes($dataArray, $fillValue = '')
    33     {
    34         if (empty($dataArray)) {
    35             return [];
    36         }
    37         $existingIndexes = array_keys($dataArray);
    38 
    39         $newIndexes = array_fill_keys(range(0, max($existingIndexes)), $fillValue);
    40         $dataArray += $newIndexes;
    41 
    42         ksort($dataArray);
    43 
    44         return $dataArray;
    45     }
    46 
    47     /**
    4822     * Returns the base 10 column index associated to the cell index (base 26).
    4923     * Excel uses A to Z letters for column indexing, where A is the 1st column,
     
    5226     *
    5327     * @param string $cellIndex The Excel cell index ('A1', 'BC13', ...)
     28     * @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid
    5429     * @return int
    55      * @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid
    5630     */
    5731    public static function getColumnIndexFromCellIndex($cellIndex)
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/XLSX/Helper/CellValueFormatter.php

    r112446 r115670  
    22
    33namespace Box\Spout\Reader\XLSX\Helper;
     4
     5use Box\Spout\Reader\Exception\InvalidValueException;
     6use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
     7use Box\Spout\Reader\XLSX\Manager\StyleManager;
    48
    59/**
    610 * Class CellValueFormatter
    711 * This class provides helper functions to format cell values
    8  *
    9  * @package Box\Spout\Reader\XLSX\Helper
    1012 */
    1113class CellValueFormatter
     
    3941    const ERRONEOUS_EXCEL_LEAP_YEAR_DAY = 60;
    4042
    41     /** @var SharedStringsHelper Helper to work with shared strings */
    42     protected $sharedStringsHelper;
    43 
    44     /** @var StyleHelper Helper to work with styles */
    45     protected $styleHelper;
     43    /** @var SharedStringsManager Manages shared strings */
     44    protected $sharedStringsManager;
     45
     46    /** @var StyleManager Manages styles */
     47    protected $styleManager;
    4648
    4749    /** @var bool Whether date/time values should be returned as PHP objects or be formatted as strings */
    4850    protected $shouldFormatDates;
    4951
    50     /** @var \Box\Spout\Common\Escaper\XLSX Used to unescape XML data */
     52    /** @var bool Whether date/time values should use a calendar starting in 1904 instead of 1900 */
     53    protected $shouldUse1904Dates;
     54
     55    /** @var \Box\Spout\Common\Helper\Escaper\XLSX Used to unescape XML data */
    5156    protected $escaper;
    5257
    5358    /**
    54      * @param SharedStringsHelper $sharedStringsHelper Helper to work with shared strings
    55      * @param StyleHelper $styleHelper Helper to work with styles
     59     * @param SharedStringsManager $sharedStringsManager Manages shared strings
     60     * @param StyleManager $styleManager Manages styles
    5661     * @param bool $shouldFormatDates Whether date/time values should be returned as PHP objects or be formatted as strings
    57      */
    58     public function __construct($sharedStringsHelper, $styleHelper, $shouldFormatDates)
    59     {
    60         $this->sharedStringsHelper = $sharedStringsHelper;
    61         $this->styleHelper = $styleHelper;
     62     * @param bool $shouldUse1904Dates Whether date/time values should use a calendar starting in 1904 instead of 1900
     63     * @param \Box\Spout\Common\Helper\Escaper\XLSX $escaper Used to unescape XML data
     64     */
     65    public function __construct($sharedStringsManager, $styleManager, $shouldFormatDates, $shouldUse1904Dates, $escaper)
     66    {
     67        $this->sharedStringsManager = $sharedStringsManager;
     68        $this->styleManager = $styleManager;
    6269        $this->shouldFormatDates = $shouldFormatDates;
    63 
    64         /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
    65         $this->escaper = \Box\Spout\Common\Escaper\XLSX::getInstance();
     70        $this->shouldUse1904Dates = $shouldUse1904Dates;
     71        $this->escaper = $escaper;
    6672    }
    6773
     
    7076     *
    7177     * @param \DOMNode $node
    72      * @return string|int|float|bool|\DateTime|null The value associated with the cell (null when the cell has an error)
     78     * @throws InvalidValueException If the value is not valid
     79     * @return string|int|float|bool|\DateTime The value associated with the cell
    7380     */
    7481    public function extractAndFormatNodeValue($node)
     
    7683        // Default cell type is "n"
    7784        $cellType = $node->getAttribute(self::XML_ATTRIBUTE_TYPE) ?: self::CELL_TYPE_NUMERIC;
    78         $cellStyleId = intval($node->getAttribute(self::XML_ATTRIBUTE_STYLE_ID));
     85        $cellStyleId = (int) $node->getAttribute(self::XML_ATTRIBUTE_STYLE_ID);
    7986        $vNodeValue = $this->getVNodeValue($node);
    8087
     
    97104                return $this->formatDateCellValue($vNodeValue);
    98105            default:
    99                 return null;
     106                throw new InvalidValueException($vNodeValue);
    100107        }
    101108    }
     
    112119        // if not, the returned value should be empty string.
    113120        $vNode = $node->getElementsByTagName(self::XML_NODE_VALUE)->item(0);
     121
    114122        return ($vNode !== null) ? $vNode->nodeValue : '';
    115123    }
     
    119127     *
    120128     * @param \DOMNode $node
    121      * @return string The value associated with the cell (null when the cell has an error)
     129     * @return string The value associated with the cell
    122130     */
    123131    protected function formatInlineStringCellValue($node)
     
    127135        $tNode = $node->getElementsByTagName(self::XML_NODE_INLINE_STRING_VALUE)->item(0);
    128136        $cellValue = $this->escaper->unescape($tNode->nodeValue);
     137
    129138        return $cellValue;
    130139    }
     
    134143     *
    135144     * @param string $nodeValue
    136      * @return string The value associated with the cell (null when the cell has an error)
     145     * @return string The value associated with the cell
    137146     */
    138147    protected function formatSharedStringCellValue($nodeValue)
     
    140149        // shared strings are formatted this way:
    141150        // <c r="A1" t="s"><v>[SHARED_STRING_INDEX]</v></c>
    142         $sharedStringIndex = intval($nodeValue);
    143         $escapedCellValue = $this->sharedStringsHelper->getStringAtIndex($sharedStringIndex);
     151        $sharedStringIndex = (int) $nodeValue;
     152        $escapedCellValue = $this->sharedStringsManager->getStringAtIndex($sharedStringIndex);
    144153        $cellValue = $this->escaper->unescape($escapedCellValue);
     154
    145155        return $cellValue;
    146156    }
     
    150160     *
    151161     * @param string $nodeValue
    152      * @return string The value associated with the cell (null when the cell has an error)
     162     * @return string The value associated with the cell
    153163     */
    154164    protected function formatStrCellValue($nodeValue)
     
    156166        $escapedCellValue = trim($nodeValue);
    157167        $cellValue = $this->escaper->unescape($escapedCellValue);
     168
    158169        return $cellValue;
    159170    }
     
    165176     * @param string $nodeValue
    166177     * @param int $cellStyleId 0 being the default style
    167      * @return int|float|\DateTime|null The value associated with the cell
     178     * @return int|float|\DateTime The value associated with the cell
    168179     */
    169180    protected function formatNumericCellValue($nodeValue, $cellStyleId)
     
    171182        // Numeric values can represent numbers as well as timestamps.
    172183        // We need to look at the style of the cell to determine whether it is one or the other.
    173         $shouldFormatAsDate = $this->styleHelper->shouldFormatNumericValueAsDate($cellStyleId);
     184        $shouldFormatAsDate = $this->styleManager->shouldFormatNumericValueAsDate($cellStyleId);
    174185
    175186        if ($shouldFormatAsDate) {
    176             return $this->formatExcelTimestampValue(floatval($nodeValue), $cellStyleId);
     187            $cellValue = $this->formatExcelTimestampValue((float) $nodeValue, $cellStyleId);
    177188        } else {
    178             $nodeIntValue = intval($nodeValue);
    179             return ($nodeIntValue == $nodeValue) ? $nodeIntValue : floatval($nodeValue);
    180         }
     189            $nodeIntValue = (int) $nodeValue;
     190            $nodeFloatValue = (float) $nodeValue;
     191            $cellValue = ((float) $nodeIntValue === $nodeFloatValue) ? $nodeIntValue : $nodeFloatValue;
     192        }
     193
     194        return $cellValue;
    181195    }
    182196
    183197    /**
    184198     * Returns a cell's PHP Date value, associated to the given timestamp.
    185      * NOTE: The timestamp is a float representing the number of days since January 1st, 1900.
     199     * NOTE: The timestamp is a float representing the number of days since the base Excel date:
     200     *       Dec 30th 1899, 1900 or Jan 1st, 1904, depending on the Workbook setting.
    186201     * NOTE: The timestamp can also represent a time, if it is a value between 0 and 1.
     202     *
     203     * @see ECMA-376 Part 1 - §18.17.4
    187204     *
    188205     * @param float $nodeValue
    189206     * @param int $cellStyleId 0 being the default style
    190      * @return \DateTime|null The value associated with the cell or NULL if invalid date value
     207     * @throws InvalidValueException If the value is not a valid timestamp
     208     * @return \DateTime The value associated with the cell
    191209     */
    192210    protected function formatExcelTimestampValue($nodeValue, $cellStyleId)
    193211    {
    194         // Fix for the erroneous leap year in Excel
    195         if (ceil($nodeValue) > self::ERRONEOUS_EXCEL_LEAP_YEAR_DAY) {
    196             --$nodeValue;
    197         }
    198 
    199         if ($nodeValue >= 1) {
    200             // Values greater than 1 represent "dates". The value 1.0 representing the "base" date: 1900-01-01.
    201             return $this->formatExcelTimestampValueAsDateValue($nodeValue, $cellStyleId);
    202         } else if ($nodeValue >= 0) {
    203             // Values between 0 and 1 represent "times".
    204             return $this->formatExcelTimestampValueAsTimeValue($nodeValue, $cellStyleId);
     212        if ($this->isValidTimestampValue($nodeValue)) {
     213            $cellValue = $this->formatExcelTimestampValueAsDateTimeValue($nodeValue, $cellStyleId);
    205214        } else {
    206             // invalid date
    207             return null;
    208         }
     215            throw new InvalidValueException($nodeValue);
     216        }
     217
     218        return $cellValue;
     219    }
     220
     221    /**
     222     * Returns whether the given timestamp is supported by SpreadsheetML
     223     * @see ECMA-376 Part 1 - §18.17.4 - this specifies the timestamp boundaries.
     224     *
     225     * @param float $timestampValue
     226     * @return bool
     227     */
     228    protected function isValidTimestampValue($timestampValue)
     229    {
     230        // @NOTE: some versions of Excel don't support negative dates (e.g. Excel for Mac 2011)
     231        return (
     232            $this->shouldUse1904Dates && $timestampValue >= -695055 && $timestampValue <= 2957003.9999884 ||
     233            !$this->shouldUse1904Dates && $timestampValue >= -693593 && $timestampValue <= 2958465.9999884
     234        );
    209235    }
    210236
    211237    /**
    212238     * Returns a cell's PHP DateTime value, associated to the given timestamp.
    213      * Only the time value matters. The date part is set to Jan 1st, 1900 (base Excel date).
     239     * Only the time value matters. The date part is set to the base Excel date:
     240     * Dec 30th 1899, 1900 or Jan 1st, 1904, depending on the Workbook setting.
    214241     *
    215242     * @param float $nodeValue
     
    217244     * @return \DateTime|string The value associated with the cell
    218245     */
    219     protected function formatExcelTimestampValueAsTimeValue($nodeValue, $cellStyleId)
    220     {
    221         $time = round($nodeValue * self::NUM_SECONDS_IN_ONE_DAY);
    222         $hours = floor($time / self::NUM_SECONDS_IN_ONE_HOUR);
    223         $minutes = floor($time / self::NUM_SECONDS_IN_ONE_MINUTE) - ($hours * self::NUM_SECONDS_IN_ONE_MINUTE);
    224         $seconds = $time - ($hours * self::NUM_SECONDS_IN_ONE_HOUR) - ($minutes * self::NUM_SECONDS_IN_ONE_MINUTE);
    225 
    226         // using the base Excel date (Jan 1st, 1900) - not relevant here
    227         $dateObj = new \DateTime('1900-01-01');
    228         $dateObj->setTime($hours, $minutes, $seconds);
     246    protected function formatExcelTimestampValueAsDateTimeValue($nodeValue, $cellStyleId)
     247    {
     248        $baseDate = $this->shouldUse1904Dates ? '1904-01-01' : '1899-12-30';
     249
     250        $daysSinceBaseDate = (int) $nodeValue;
     251        $timeRemainder = fmod($nodeValue, 1);
     252        $secondsRemainder = round($timeRemainder * self::NUM_SECONDS_IN_ONE_DAY, 0);
     253
     254        $dateObj = \DateTime::createFromFormat('|Y-m-d', $baseDate);
     255        $dateObj->modify('+' . $daysSinceBaseDate . 'days');
     256        $dateObj->modify('+' . $secondsRemainder . 'seconds');
    229257
    230258        if ($this->shouldFormatDates) {
    231             $styleNumberFormatCode = $this->styleHelper->getNumberFormatCode($cellStyleId);
     259            $styleNumberFormatCode = $this->styleManager->getNumberFormatCode($cellStyleId);
    232260            $phpDateFormat = DateFormatHelper::toPHPDateFormat($styleNumberFormatCode);
    233             return $dateObj->format($phpDateFormat);
     261            $cellValue = $dateObj->format($phpDateFormat);
    234262        } else {
    235             return $dateObj;
    236         }
    237     }
    238 
    239     /**
    240      * Returns a cell's PHP Date value, associated to the given timestamp.
    241      * NOTE: The timestamp is a float representing the number of days since January 1st, 1900.
    242      *
    243      * @param float $nodeValue
    244      * @param int $cellStyleId 0 being the default style
    245      * @return \DateTime|string|null The value associated with the cell or NULL if invalid date value
    246      */
    247     protected function formatExcelTimestampValueAsDateValue($nodeValue, $cellStyleId)
    248     {
    249         // Do not use any unix timestamps for calculation to prevent
    250         // issues with numbers exceeding 2^31.
    251         $secondsRemainder = fmod($nodeValue, 1) * self::NUM_SECONDS_IN_ONE_DAY;
    252         $secondsRemainder = round($secondsRemainder, 0);
    253 
    254         try {
    255             $dateObj = \DateTime::createFromFormat('|Y-m-d', '1899-12-31');
    256             $dateObj->modify('+' . intval($nodeValue) . 'days');
    257             $dateObj->modify('+' . $secondsRemainder . 'seconds');
    258 
    259             if ($this->shouldFormatDates) {
    260                 $styleNumberFormatCode = $this->styleHelper->getNumberFormatCode($cellStyleId);
    261                 $phpDateFormat = DateFormatHelper::toPHPDateFormat($styleNumberFormatCode);
    262                 return $dateObj->format($phpDateFormat);
    263             } else {
    264                 return $dateObj;
    265             }
    266         } catch (\Exception $e) {
    267             return null;
    268         }
     263            $cellValue = $dateObj;
     264        }
     265
     266        return $cellValue;
    269267    }
    270268
     
    277275    protected function formatBooleanCellValue($nodeValue)
    278276    {
    279         // !! is similar to boolval()
    280         $cellValue = !!$nodeValue;
    281         return $cellValue;
     277        return (bool) $nodeValue;
    282278    }
    283279
     
    287283     *
    288284     * @param string $nodeValue ISO 8601 Date string
    289      * @return \DateTime|string|null The value associated with the cell or NULL if invalid date value
     285     * @throws InvalidValueException If the value is not a valid date
     286     * @return \DateTime|string The value associated with the cell
    290287     */
    291288    protected function formatDateCellValue($nodeValue)
     
    293290        // Mitigate thrown Exception on invalid date-time format (http://php.net/manual/en/datetime.construct.php)
    294291        try {
    295             return ($this->shouldFormatDates) ? $nodeValue : new \DateTime($nodeValue);
     292            $cellValue = ($this->shouldFormatDates) ? $nodeValue : new \DateTime($nodeValue);
    296293        } catch (\Exception $e) {
    297             return null;
    298         }
     294            throw new InvalidValueException($nodeValue);
     295        }
     296
     297        return $cellValue;
    299298    }
    300299}
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/XLSX/Helper/DateFormatHelper.php

    r112446 r115670  
    66 * Class DateFormatHelper
    77 * This class provides helper functions to format Excel dates
    8  *
    9  * @package Box\Spout\Reader\XLSX\Helper
    108 */
    119class DateFormatHelper
     
    105103        // all characters that are inside double quotes (and double quotes must be removed).
    106104        // For instance, ["Day " dd] should become [\D\a\y\ dd]
    107         $phpDateFormat = preg_replace_callback('/"(.+?)"/', function($matches) {
     105        $phpDateFormat = preg_replace_callback('/"(.+?)"/', function ($matches) {
    108106            $stringToEscape = $matches[1];
    109107            $letters = preg_split('//u', $stringToEscape, -1, PREG_SPLIT_NO_EMPTY);
     108
    110109            return '\\' . implode('\\', $letters);
    111110        }, $phpDateFormat);
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/XLSX/Reader.php

    r112446 r115670  
    44
    55use Box\Spout\Common\Exception\IOException;
    6 use Box\Spout\Reader\AbstractReader;
    7 use Box\Spout\Reader\XLSX\Helper\SharedStringsHelper;
     6use Box\Spout\Common\Helper\GlobalFunctionsHelper;
     7use Box\Spout\Common\Manager\OptionsManagerInterface;
     8use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
     9use Box\Spout\Reader\Common\Entity\Options;
     10use Box\Spout\Reader\ReaderAbstract;
     11use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
     12use Box\Spout\Reader\XLSX\Creator\ManagerFactory;
    813
    914/**
    1015 * Class Reader
    1116 * This class provides support to read data from a XLSX file
    12  *
    13  * @package Box\Spout\Reader\XLSX
    1417 */
    15 class Reader extends AbstractReader
     18class Reader extends ReaderAbstract
    1619{
     20    /** @var ManagerFactory */
     21    protected $managerFactory;
     22
    1723    /** @var \ZipArchive */
    1824    protected $zip;
    1925
    20     /** @var \Box\Spout\Reader\XLSX\Helper\SharedStringsHelper Helper to work with shared strings */
    21     protected $sharedStringsHelper;
     26    /** @var \Box\Spout\Reader\XLSX\Manager\SharedStringsManager Manages shared strings */
     27    protected $sharedStringsManager;
    2228
    2329    /** @var SheetIterator To iterator over the XLSX sheets */
    2430    protected $sheetIterator;
    2531
    26 
    2732    /**
    28      * Returns the reader's current options
    29      *
    30      * @return ReaderOptions
     33     * @param OptionsManagerInterface $optionsManager
     34     * @param GlobalFunctionsHelper $globalFunctionsHelper
     35     * @param InternalEntityFactoryInterface $entityFactory
     36     * @param ManagerFactory $managerFactory
    3137     */
    32     protected function getOptions()
    33     {
    34         if (!isset($this->options)) {
    35             $this->options = new ReaderOptions();
    36         }
    37         return $this->options;
     38    public function __construct(
     39        OptionsManagerInterface $optionsManager,
     40        GlobalFunctionsHelper $globalFunctionsHelper,
     41        InternalEntityFactoryInterface $entityFactory,
     42        ManagerFactory $managerFactory
     43    ) {
     44        parent::__construct($optionsManager, $globalFunctionsHelper, $entityFactory);
     45        $this->managerFactory = $managerFactory;
    3846    }
    3947
     
    4452    public function setTempFolder($tempFolder)
    4553    {
    46         $this->getOptions()->setTempFolder($tempFolder);
     54        $this->optionsManager->setOption(Options::TEMP_FOLDER, $tempFolder);
     55
    4756        return $this;
    4857    }
     
    6473     *
    6574     * @param  string $filePath Path of the file to be read
    66      * @return void
    6775     * @throws \Box\Spout\Common\Exception\IOException If the file at the given path or its content cannot be read
    6876     * @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file
     77     * @return void
    6978     */
    7079    protected function openReader($filePath)
    7180    {
    72         $this->zip = new \ZipArchive();
     81        /** @var InternalEntityFactory $entityFactory */
     82        $entityFactory = $this->entityFactory;
     83
     84        $this->zip = $entityFactory->createZipArchive();
    7385
    7486        if ($this->zip->open($filePath) === true) {
    75             $this->sharedStringsHelper = new SharedStringsHelper($filePath, $this->getOptions()->getTempFolder());
     87            $tempFolder = $this->optionsManager->getOption(Options::TEMP_FOLDER);
     88            $this->sharedStringsManager = $this->managerFactory->createSharedStringsManager($filePath, $tempFolder, $entityFactory);
    7689
    77             if ($this->sharedStringsHelper->hasSharedStrings()) {
     90            if ($this->sharedStringsManager->hasSharedStrings()) {
    7891                // Extracts all the strings from the sheets for easy access in the future
    79                 $this->sharedStringsHelper->extractSharedStrings();
     92                $this->sharedStringsManager->extractSharedStrings();
    8093            }
    8194
    82             $this->sheetIterator = new SheetIterator($filePath, $this->getOptions(), $this->sharedStringsHelper, $this->globalFunctionsHelper);
     95            $this->sheetIterator = $entityFactory->createSheetIterator(
     96                $filePath,
     97                $this->optionsManager,
     98                $this->sharedStringsManager
     99            );
    83100        } else {
    84101            throw new IOException("Could not open $filePath for reading.");
     
    107124        }
    108125
    109         if ($this->sharedStringsHelper) {
    110             $this->sharedStringsHelper->cleanup();
     126        if ($this->sharedStringsManager) {
     127            $this->sharedStringsManager->cleanup();
    111128        }
    112129    }
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/XLSX/RowIterator.php

    r112446 r115670  
    33namespace Box\Spout\Reader\XLSX;
    44
     5use Box\Spout\Common\Entity\Cell;
     6use Box\Spout\Common\Entity\Row;
    57use Box\Spout\Common\Exception\IOException;
     8use Box\Spout\Reader\Common\Manager\RowManager;
     9use Box\Spout\Reader\Common\XMLProcessor;
     10use Box\Spout\Reader\Exception\InvalidValueException;
    611use Box\Spout\Reader\Exception\XMLProcessingException;
    712use Box\Spout\Reader\IteratorInterface;
    813use Box\Spout\Reader\Wrapper\XMLReader;
     14use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
    915use Box\Spout\Reader\XLSX\Helper\CellHelper;
    1016use Box\Spout\Reader\XLSX\Helper\CellValueFormatter;
    11 use Box\Spout\Reader\XLSX\Helper\StyleHelper;
    12 use Box\Spout\Reader\Common\XMLProcessor;
    1317
    1418/**
    1519 * Class RowIterator
    16  *
    17  * @package Box\Spout\Reader\XLSX
    1820 */
    1921class RowIterator implements IteratorInterface
     
    4648    protected $cellValueFormatter;
    4749
    48     /** @var Helper\StyleHelper $styleHelper Helper to work with styles */
    49     protected $styleHelper;
     50    /** @var \Box\Spout\Reader\Common\Manager\RowManager Manages rows */
     51    protected $rowManager;
     52
     53    /** @var \Box\Spout\Reader\XLSX\Creator\InternalEntityFactory Factory to create entities */
     54    protected $entityFactory;
    5055
    5156    /**
     
    5560    protected $numReadRows = 0;
    5661
    57     /** @var array Contains the data for the currently processed row (key = cell index, value = cell value) */
    58     protected $currentlyProcessedRowData = [];
    59 
    60     /** @var array|null Buffer used to store the row data, while checking if there are more rows to read */
    61     protected $rowDataBuffer = null;
     62    /** @var Row Contains the row currently processed */
     63    protected $currentlyProcessedRow;
     64
     65    /** @var Row|null Buffer used to store the current row, while checking if there are more rows to read */
     66    protected $rowBuffer;
    6267
    6368    /** @var bool Indicates whether all rows have been read */
     
    8287     * @param string $filePath Path of the XLSX file being read
    8388     * @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml
    84      * @param \Box\Spout\Reader\XLSX\ReaderOptions $options Reader's current options
    85      * @param Helper\SharedStringsHelper $sharedStringsHelper Helper to work with shared strings
    86      */
    87     public function __construct($filePath, $sheetDataXMLFilePath, $options, $sharedStringsHelper)
    88     {
     89     * @param bool $shouldPreserveEmptyRows Whether empty rows should be preserved
     90     * @param XMLReader $xmlReader XML Reader
     91     * @param XMLProcessor $xmlProcessor Helper to process XML files
     92     * @param CellValueFormatter $cellValueFormatter Helper to format cell values
     93     * @param RowManager $rowManager Manages rows
     94     * @param InternalEntityFactory $entityFactory Factory to create entities
     95     */
     96    public function __construct(
     97        $filePath,
     98        $sheetDataXMLFilePath,
     99        $shouldPreserveEmptyRows,
     100        $xmlReader,
     101        XMLProcessor $xmlProcessor,
     102        CellValueFormatter $cellValueFormatter,
     103        RowManager $rowManager,
     104        InternalEntityFactory $entityFactory
     105    ) {
    89106        $this->filePath = $filePath;
    90107        $this->sheetDataXMLFilePath = $this->normalizeSheetDataXMLFilePath($sheetDataXMLFilePath);
    91 
    92         $this->xmlReader = new XMLReader();
    93 
    94         $this->styleHelper = new StyleHelper($filePath);
    95         $this->cellValueFormatter = new CellValueFormatter($sharedStringsHelper, $this->styleHelper, $options->shouldFormatDates());
    96 
    97         $this->shouldPreserveEmptyRows = $options->shouldPreserveEmptyRows();
     108        $this->shouldPreserveEmptyRows = $shouldPreserveEmptyRows;
     109        $this->xmlReader = $xmlReader;
     110        $this->cellValueFormatter = $cellValueFormatter;
     111        $this->rowManager = $rowManager;
     112        $this->entityFactory = $entityFactory;
    98113
    99114        // Register all callbacks to process different nodes when reading the XML file
    100         $this->xmlProcessor = new XMLProcessor($this->xmlReader);
     115        $this->xmlProcessor = $xmlProcessor;
    101116        $this->xmlProcessor->registerCallback(self::XML_NODE_DIMENSION, XMLProcessor::NODE_TYPE_START, [$this, 'processDimensionStartingNode']);
    102117        $this->xmlProcessor->registerCallback(self::XML_NODE_ROW, XMLProcessor::NODE_TYPE_START, [$this, 'processRowStartingNode']);
     
    120135     * Initializes the XMLReader object that reads the associated sheet data.
    121136     * The XMLReader is configured to be safe from billion laughs attack.
    122      * @link http://php.net/manual/en/iterator.rewind.php
    123      *
     137     * @see http://php.net/manual/en/iterator.rewind.php
     138     *
     139     * @throws \Box\Spout\Common\Exception\IOException If the sheet data XML cannot be read
    124140     * @return void
    125      * @throws \Box\Spout\Common\Exception\IOException If the sheet data XML cannot be read
    126141     */
    127142    public function rewind()
     
    136151        $this->lastRowIndexProcessed = 0;
    137152        $this->nextRowIndexToBeProcessed = 0;
    138         $this->rowDataBuffer = null;
     153        $this->rowBuffer = null;
    139154        $this->hasReachedEndOfFile = false;
    140155        $this->numColumns = 0;
     
    145160    /**
    146161     * Checks if current position is valid
    147      * @link http://php.net/manual/en/iterator.valid.php
     162     * @see http://php.net/manual/en/iterator.valid.php
    148163     *
    149164     * @return bool
     
    156171    /**
    157172     * Move forward to next element. Reads data describing the next unprocessed row.
    158      * @link http://php.net/manual/en/iterator.next.php
    159      *
    160      * @return void
     173     * @see http://php.net/manual/en/iterator.next.php
     174     *
    161175     * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If a shared string was not found
    162176     * @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML
     177     * @return void
    163178     */
    164179    public function next()
     
    195210
    196211    /**
    197      * @return void
    198212     * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If a shared string was not found
    199213     * @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML
     214     * @return void
    200215     */
    201216    protected function readDataForNextRow()
    202217    {
    203         $this->currentlyProcessedRowData = [];
     218        $this->currentlyProcessedRow = $this->entityFactory->createRow();
    204219
    205220        try {
     
    209224        }
    210225
    211         $this->rowDataBuffer = $this->currentlyProcessedRowData;
     226        $this->rowBuffer = $this->currentlyProcessedRow;
    212227    }
    213228
     
    244259        if ($spans) {
    245260            list(, $numberOfColumnsForRow) = explode(':', $spans);
    246             $numberOfColumnsForRow = intval($numberOfColumnsForRow);
    247         }
    248 
    249         $this->currentlyProcessedRowData = ($numberOfColumnsForRow !== 0) ? array_fill(0, $numberOfColumnsForRow, '') : [];
     261            $numberOfColumnsForRow = (int) $numberOfColumnsForRow;
     262        }
     263
     264        $cells = array_fill(0, $numberOfColumnsForRow, $this->entityFactory->createCell(''));
     265        $this->currentlyProcessedRow->setCells($cells);
    250266
    251267        return XMLProcessor::PROCESSING_CONTINUE;
     
    262278        // NOTE: expand() will automatically decode all XML entities of the child nodes
    263279        $node = $xmlReader->expand();
    264         $this->currentlyProcessedRowData[$currentColumnIndex] = $this->getCellValue($node);
     280        $cell = $this->getCell($node);
     281
     282        $this->currentlyProcessedRow->setCellAtIndex($cell, $currentColumnIndex);
    265283        $this->lastColumnIndexProcessed = $currentColumnIndex;
    266284
     
    274292    {
    275293        // if the fetched row is empty and we don't want to preserve it..,
    276         if (!$this->shouldPreserveEmptyRows && $this->isEmptyRow($this->currentlyProcessedRowData)) {
     294        if (!$this->shouldPreserveEmptyRows && $this->rowManager->isEmpty($this->currentlyProcessedRow)) {
    277295            // ... skip it
    278296            return XMLProcessor::PROCESSING_CONTINUE;
     
    283301        // If needed, we fill the empty cells
    284302        if ($this->numColumns === 0) {
    285             $this->currentlyProcessedRowData = CellHelper::fillMissingArrayIndexes($this->currentlyProcessedRowData);
     303            $this->currentlyProcessedRow = $this->rowManager->fillMissingIndexesWithEmptyCells($this->currentlyProcessedRow);
    286304        }
    287305
     
    304322    /**
    305323     * @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader object, positioned on a "<row>" node
     324     * @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid
    306325     * @return int Row index
    307      * @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid
    308326     */
    309327    protected function getRowIndex($xmlReader)
     
    313331
    314332        return ($currentRowIndex !== null) ?
    315                 intval($currentRowIndex) :
     333                (int) $currentRowIndex :
    316334                $this->lastRowIndexProcessed + 1;
    317335    }
     
    319337    /**
    320338     * @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader object, positioned on a "<c>" node
     339     * @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid
    321340     * @return int Column index
    322      * @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid
    323341     */
    324342    protected function getColumnIndex($xmlReader)
     
    333351
    334352    /**
    335      * Returns the (unescaped) correctly marshalled, cell value associated to the given XML node.
     353     * Returns the cell with (unescaped) correctly marshalled, cell value associated to the given XML node.
    336354     *
    337355     * @param \DOMNode $node
    338      * @return string|int|float|bool|\DateTime|null The value associated with the cell (null when the cell has an error)
    339      */
    340     protected function getCellValue($node)
    341     {
    342         return $this->cellValueFormatter->extractAndFormatNodeValue($node);
    343     }
    344 
    345     /**
    346      * @param array $rowData
    347      * @return bool Whether the given row is empty
    348      */
    349     protected function isEmptyRow($rowData)
    350     {
    351         return (count($rowData) === 1 && key($rowData) === '');
     356     * @return Cell The cell set with the associated with the cell
     357     */
     358    protected function getCell($node)
     359    {
     360        try {
     361            $cellValue = $this->cellValueFormatter->extractAndFormatNodeValue($node);
     362            $cell = $this->entityFactory->createCell($cellValue);
     363        } catch (InvalidValueException $exception) {
     364            $cell = $this->entityFactory->createCell($exception->getInvalidValue());
     365            $cell->setType(Cell::TYPE_ERROR);
     366        }
     367
     368        return $cell;
    352369    }
    353370
    354371    /**
    355372     * Return the current element, either an empty row or from the buffer.
    356      * @link http://php.net/manual/en/iterator.current.php
    357      *
    358      * @return array|null
     373     * @see http://php.net/manual/en/iterator.current.php
     374     *
     375     * @return Row|null
    359376     */
    360377    public function current()
    361378    {
    362         $rowDataForRowToBeProcessed = $this->rowDataBuffer;
     379        $rowToBeProcessed = $this->rowBuffer;
    363380
    364381        if ($this->shouldPreserveEmptyRows) {
     
    370387                // return empty row if mismatch between last processed row
    371388                // and the row that needs to be returned
    372                 $rowDataForRowToBeProcessed = [''];
     389                $rowToBeProcessed = $this->entityFactory->createRow();
    373390            }
    374391        }
    375392
    376         return $rowDataForRowToBeProcessed;
     393        return $rowToBeProcessed;
    377394    }
    378395
    379396    /**
    380397     * Return the key of the current element. Here, the row index.
    381      * @link http://php.net/manual/en/iterator.key.php
     398     * @see http://php.net/manual/en/iterator.key.php
    382399     *
    383400     * @return int
     
    393410    }
    394411
    395 
    396412    /**
    397413     * Cleans up what was created to iterate over the object.
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/XLSX/Sheet.php

    r112446 r115670  
    88 * Class Sheet
    99 * Represents a sheet within a XLSX file
    10  *
    11  * @package Box\Spout\Reader\XLSX
    1210 */
    1311class Sheet implements SheetInterface
     
    2523    protected $isActive;
    2624
     25    /** @var bool Whether the sheet is visible */
     26    protected $isVisible;
     27
    2728    /**
    28      * @param string $filePath Path of the XLSX file being read
    29      * @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml
     29     * @param RowIterator $rowIterator The corresponding row iterator
    3030     * @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based)
    3131     * @param string $sheetName Name of the sheet
    3232     * @param bool $isSheetActive Whether the sheet was defined as active
    33      * @param \Box\Spout\Reader\XLSX\ReaderOptions $options Reader's current options
    34      * @param Helper\SharedStringsHelper Helper to work with shared strings
     33     * @param bool $isSheetVisible Whether the sheet is visible
    3534     */
    36     public function __construct($filePath, $sheetDataXMLFilePath, $sheetIndex, $sheetName, $isSheetActive, $options, $sharedStringsHelper)
     35    public function __construct($rowIterator, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible)
    3736    {
    38         $this->rowIterator = new RowIterator($filePath, $sheetDataXMLFilePath, $options, $sharedStringsHelper);
     37        $this->rowIterator = $rowIterator;
    3938        $this->index = $sheetIndex;
    4039        $this->name = $sheetName;
    4140        $this->isActive = $isSheetActive;
     41        $this->isVisible = $isSheetVisible;
    4242    }
    4343
    4444    /**
    45      * @api
    4645     * @return \Box\Spout\Reader\XLSX\RowIterator
    4746     */
     
    5251
    5352    /**
    54      * @api
    5553     * @return int Index of the sheet, based on order in the workbook (zero-based)
    5654     */
     
    6159
    6260    /**
    63      * @api
    6461     * @return string Name of the sheet
    6562     */
     
    7067
    7168    /**
    72      * @api
    7369     * @return bool Whether the sheet was defined as active
    7470     */
     
    7773        return $this->isActive;
    7874    }
     75
     76    /**
     77     * @return bool Whether the sheet is visible
     78     */
     79    public function isVisible()
     80    {
     81        return $this->isVisible;
     82    }
    7983}
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Reader/XLSX/SheetIterator.php

    r112446 r115670  
    33namespace Box\Spout\Reader\XLSX;
    44
     5use Box\Spout\Reader\Exception\NoSheetsFoundException;
    56use Box\Spout\Reader\IteratorInterface;
    6 use Box\Spout\Reader\XLSX\Helper\SheetHelper;
    7 use Box\Spout\Reader\Exception\NoSheetsFoundException;
     7use Box\Spout\Reader\XLSX\Manager\SheetManager;
    88
    99/**
    1010 * Class SheetIterator
    1111 * Iterate over XLSX sheet.
    12  *
    13  * @package Box\Spout\Reader\XLSX
    1412 */
    1513class SheetIterator implements IteratorInterface
     
    2220
    2321    /**
    24      * @param string $filePath Path of the file to be read
    25      * @param \Box\Spout\Reader\XLSX\ReaderOptions $options Reader's current options
    26      * @param \Box\Spout\Reader\XLSX\Helper\SharedStringsHelper $sharedStringsHelper
    27      * @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper
     22     * @param SheetManager $sheetManager Manages sheets
    2823     * @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file
    2924     */
    30     public function __construct($filePath, $options, $sharedStringsHelper, $globalFunctionsHelper)
     25    public function __construct($sheetManager)
    3126    {
    3227        // Fetch all available sheets
    33         $sheetHelper = new SheetHelper($filePath, $options, $sharedStringsHelper, $globalFunctionsHelper);
    34         $this->sheets = $sheetHelper->getSheets();
     28        $this->sheets = $sheetManager->getSheets();
    3529
    3630        if (count($this->sheets) === 0) {
     
    4135    /**
    4236     * Rewind the Iterator to the first element
    43      * @link http://php.net/manual/en/iterator.rewind.php
     37     * @see http://php.net/manual/en/iterator.rewind.php
    4438     *
    4539     * @return void
     
    5246    /**
    5347     * Checks if current position is valid
    54      * @link http://php.net/manual/en/iterator.valid.php
     48     * @see http://php.net/manual/en/iterator.valid.php
    5549     *
    5650     * @return bool
     
    6357    /**
    6458     * Move forward to next element
    65      * @link http://php.net/manual/en/iterator.next.php
     59     * @see http://php.net/manual/en/iterator.next.php
    6660     *
    6761     * @return void
     
    8074    /**
    8175     * Return the current element
    82      * @link http://php.net/manual/en/iterator.current.php
     76     * @see http://php.net/manual/en/iterator.current.php
    8377     *
    8478     * @return \Box\Spout\Reader\XLSX\Sheet
     
    9185    /**
    9286     * Return the key of the current element
    93      * @link http://php.net/manual/en/iterator.key.php
     87     * @see http://php.net/manual/en/iterator.key.php
    9488     *
    9589     * @return int
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/CSV/Writer.php

    r112446 r115670  
    33namespace Box\Spout\Writer\CSV;
    44
    5 use Box\Spout\Writer\AbstractWriter;
     5use Box\Spout\Common\Entity\Row;
    66use Box\Spout\Common\Exception\IOException;
    77use Box\Spout\Common\Helper\EncodingHelper;
     8use Box\Spout\Writer\Common\Entity\Options;
     9use Box\Spout\Writer\WriterAbstract;
    810
    911/**
    1012 * Class Writer
    1113 * This class provides support to write data to CSV files
    12  *
    13  * @package Box\Spout\Writer\CSV
    1414 */
    15 class Writer extends AbstractWriter
     15class Writer extends WriterAbstract
    1616{
    1717    /** Number of rows to write before flushing */
     
    2121    protected static $headerContentType = 'text/csv; charset=UTF-8';
    2222
    23     /** @var string Defines the character used to delimit fields (one character only) */
    24     protected $fieldDelimiter = ',';
    25 
    26     /** @var string Defines the character used to enclose fields (one character only) */
    27     protected $fieldEnclosure = '"';
    28 
    2923    /** @var int */
    3024    protected $lastWrittenRowIndex = 0;
    31 
    32     /** @var bool */
    33     protected $shouldAddBOM = true;
    3425
    3526    /**
    3627     * Sets the field delimiter for the CSV
    3728     *
    38      * @api
    3929     * @param string $fieldDelimiter Character that delimits fields
    4030     * @return Writer
     
    4232    public function setFieldDelimiter($fieldDelimiter)
    4333    {
    44         $this->fieldDelimiter = $fieldDelimiter;
     34        $this->optionsManager->setOption(Options::FIELD_DELIMITER, $fieldDelimiter);
     35
    4536        return $this;
    4637    }
     
    4940     * Sets the field enclosure for the CSV
    5041     *
    51      * @api
    5242     * @param string $fieldEnclosure Character that enclose fields
    5343     * @return Writer
     
    5545    public function setFieldEnclosure($fieldEnclosure)
    5646    {
    57         $this->fieldEnclosure = $fieldEnclosure;
     47        $this->optionsManager->setOption(Options::FIELD_ENCLOSURE, $fieldEnclosure);
     48
    5849        return $this;
    5950    }
     
    6758    public function setShouldAddBOM($shouldAddBOM)
    6859    {
    69         $this->shouldAddBOM = (bool) $shouldAddBOM;
     60        $this->optionsManager->setOption(Options::SHOULD_ADD_BOM, (bool) $shouldAddBOM);
     61
    7062        return $this;
    7163    }
     
    7870    protected function openWriter()
    7971    {
    80         if ($this->shouldAddBOM) {
     72        if ($this->optionsManager->getOption(Options::SHOULD_ADD_BOM)) {
    8173            // Adds UTF-8 BOM for Unicode compatibility
    8274            $this->globalFunctionsHelper->fputs($this->filePointer, EncodingHelper::BOM_UTF8);
     
    8577
    8678    /**
    87      * Adds data to the currently opened writer.
     79     * Adds a row to the currently opened writer.
    8880     *
    89      * @param  array $dataRow Array containing data to be written.
    90      *          Example $dataRow = ['data1', 1234, null, '', 'data5'];
    91      * @param \Box\Spout\Writer\Style\Style $style Ignored here since CSV does not support styling.
     81     * @param Row $row The row containing cells and styles
     82     * @throws IOException If unable to write data
    9283     * @return void
    93      * @throws \Box\Spout\Common\Exception\IOException If unable to write data
    9484     */
    95     protected function addRowToWriter(array $dataRow, $style)
     85    protected function addRowToWriter(Row $row)
    9686    {
    97         $wasWriteSuccessful = $this->globalFunctionsHelper->fputcsv($this->filePointer, $dataRow, $this->fieldDelimiter, $this->fieldEnclosure);
     87        $fieldDelimiter = $this->optionsManager->getOption(Options::FIELD_DELIMITER);
     88        $fieldEnclosure = $this->optionsManager->getOption(Options::FIELD_ENCLOSURE);
     89
     90        $wasWriteSuccessful = $this->globalFunctionsHelper->fputcsv($this->filePointer, $row->getCells(), $fieldDelimiter, $fieldEnclosure);
    9891        if ($wasWriteSuccessful === false) {
    9992            throw new IOException('Unable to write data');
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/Common/Helper/CellHelper.php

    r112446 r115670  
    66 * Class CellHelper
    77 * This class provides helper functions when working with cells
    8  *
    9  * @package Box\Spout\Writer\Common\Helper
    108 */
    119class CellHelper
     
    3735
    3836                // substracting 1 because it's zero-based
    39                 $columnIndex = intval($columnIndex / 26) - 1;
    40 
     37                $columnIndex = (int) ($columnIndex / 26) - 1;
    4138            } while ($columnIndex >= 0);
    4239
     
    4643        return self::$columnIndexToCellIndexCache[$originalColumnIndex];
    4744    }
    48 
    49     /**
    50      * @param $value
    51      * @return bool Whether the given value is considered "empty"
    52      */
    53     public static function isEmpty($value)
    54     {
    55         return ($value === null || $value === '');
    56     }
    57 
    58     /**
    59      * @param $value
    60      * @return bool Whether the given value is a non empty string
    61      */
    62     public static function isNonEmptyString($value)
    63     {
    64         return (gettype($value) === 'string' && $value !== '');
    65     }
    66 
    67     /**
    68      * Returns whether the given value is numeric.
    69      * A numeric value is from type "integer" or "double" ("float" is not returned by gettype).
    70      *
    71      * @param $value
    72      * @return bool Whether the given value is numeric
    73      */
    74     public static function isNumeric($value)
    75     {
    76         $valueType = gettype($value);
    77         return ($valueType === 'integer' || $valueType === 'double');
    78     }
    79 
    80     /**
    81      * Returns whether the given value is boolean.
    82      * "true"/"false" and 0/1 are not booleans.
    83      *
    84      * @param $value
    85      * @return bool Whether the given value is boolean
    86      */
    87     public static function isBoolean($value)
    88     {
    89         return gettype($value) === 'boolean';
    90     }
    9145}
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/Common/Helper/ZipHelper.php

    r112446 r115670  
    22
    33namespace Box\Spout\Writer\Common\Helper;
     4
     5use Box\Spout\Writer\Common\Creator\InternalEntityFactory;
    46
    57/**
    68 * Class ZipHelper
    79 * This class provides helper functions to create zip files
    8  *
    9  * @package Box\Spout\Writer\Common\Helper
    1010 */
    1111class ZipHelper
     
    1717    const EXISTING_FILES_OVERWRITE = 'overwrite';
    1818
    19     /** @var string Path of the folder where the zip file will be created */
    20     protected $tmpFolderPath;
    21 
    22     /** @var \ZipArchive The ZipArchive instance */
    23     protected $zip;
    24 
    25     /**
     19    /** @var InternalEntityFactory Factory to create entities */
     20    private $entityFactory;
     21
     22    /**
     23     * @param InternalEntityFactory $entityFactory Factory to create entities
     24     */
     25    public function __construct($entityFactory)
     26    {
     27        $this->entityFactory = $entityFactory;
     28    }
     29
     30    /**
     31     * Returns a new ZipArchive instance pointing at the given path.
     32     *
    2633     * @param string $tmpFolderPath Path of the temp folder where the zip file will be created
    27      */
    28     public function __construct($tmpFolderPath)
    29     {
    30         $this->tmpFolderPath = $tmpFolderPath;
    31     }
    32 
    33     /**
    34      * Returns the already created ZipArchive instance or
    35      * creates one if none exists.
    36      *
    3734     * @return \ZipArchive
    3835     */
    39     protected function createOrGetZip()
    40     {
    41         if (!isset($this->zip)) {
    42             $this->zip = new \ZipArchive();
    43             $zipFilePath = $this->getZipFilePath();
    44 
    45             $this->zip->open($zipFilePath, \ZipArchive::CREATE|\ZipArchive::OVERWRITE);
    46         }
    47 
    48         return $this->zip;
    49     }
    50 
    51     /**
     36    public function createZip($tmpFolderPath)
     37    {
     38        $zip = $this->entityFactory->createZipArchive();
     39        $zipFilePath = $tmpFolderPath . self::ZIP_EXTENSION;
     40
     41        $zip->open($zipFilePath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
     42
     43        return $zip;
     44    }
     45
     46    /**
     47     * @param \ZipArchive $zip An opened zip archive object
    5248     * @return string Path where the zip file of the given folder will be created
    5349     */
    54     public function getZipFilePath()
    55     {
    56         return $this->tmpFolderPath . self::ZIP_EXTENSION;
     50    public function getZipFilePath(\ZipArchive $zip)
     51    {
     52        return $zip->filename;
    5753    }
    5854
     
    6258     *
    6359     * Example of use:
    64      *   addFileToArchive('/tmp/xlsx/foo', 'bar/baz.xml');
     60     *   addFileToArchive($zip, '/tmp/xlsx/foo', 'bar/baz.xml');
    6561     *   => will add the file located at '/tmp/xlsx/foo/bar/baz.xml' in the archive, but only as 'bar/baz.xml'
    6662     *
     63     * @param \ZipArchive $zip An opened zip archive object
    6764     * @param string $rootFolderPath Path of the root folder that will be ignored in the archive tree.
    6865     * @param string $localFilePath Path of the file to be added, under the root folder
    69      * @param string|void $existingFileMode Controls what to do when trying to add an existing file
    70      * @return void
    71      */
    72     public function addFileToArchive($rootFolderPath, $localFilePath, $existingFileMode = self::EXISTING_FILES_OVERWRITE)
     66     * @param string $existingFileMode Controls what to do when trying to add an existing file
     67     * @return void
     68     */
     69    public function addFileToArchive($zip, $rootFolderPath, $localFilePath, $existingFileMode = self::EXISTING_FILES_OVERWRITE)
    7370    {
    7471        $this->addFileToArchiveWithCompressionMethod(
     72            $zip,
    7573            $rootFolderPath,
    7674            $localFilePath,
     
    8583     *
    8684     * Example of use:
    87      *   addUncompressedFileToArchive('/tmp/xlsx/foo', 'bar/baz.xml');
     85     *   addUncompressedFileToArchive($zip, '/tmp/xlsx/foo', 'bar/baz.xml');
    8886     *   => will add the file located at '/tmp/xlsx/foo/bar/baz.xml' in the archive, but only as 'bar/baz.xml'
    8987     *
     88     * @param \ZipArchive $zip An opened zip archive object
    9089     * @param string $rootFolderPath Path of the root folder that will be ignored in the archive tree.
    9190     * @param string $localFilePath Path of the file to be added, under the root folder
    92      * @param string|void $existingFileMode Controls what to do when trying to add an existing file
    93      * @return void
    94      */
    95     public function addUncompressedFileToArchive($rootFolderPath, $localFilePath, $existingFileMode = self::EXISTING_FILES_OVERWRITE)
     91     * @param string $existingFileMode Controls what to do when trying to add an existing file
     92     * @return void
     93     */
     94    public function addUncompressedFileToArchive($zip, $rootFolderPath, $localFilePath, $existingFileMode = self::EXISTING_FILES_OVERWRITE)
    9695    {
    9796        $this->addFileToArchiveWithCompressionMethod(
     97            $zip,
    9898            $rootFolderPath,
    9999            $localFilePath,
     
    108108     *
    109109     * Example of use:
    110      *   addUncompressedFileToArchive('/tmp/xlsx/foo', 'bar/baz.xml');
     110     *   addUncompressedFileToArchive($zip, '/tmp/xlsx/foo', 'bar/baz.xml');
    111111     *   => will add the file located at '/tmp/xlsx/foo/bar/baz.xml' in the archive, but only as 'bar/baz.xml'
    112112     *
     113     * @param \ZipArchive $zip An opened zip archive object
    113114     * @param string $rootFolderPath Path of the root folder that will be ignored in the archive tree.
    114115     * @param string $localFilePath Path of the file to be added, under the root folder
     
    117118     * @return void
    118119     */
    119     protected function addFileToArchiveWithCompressionMethod($rootFolderPath, $localFilePath, $existingFileMode, $compressionMethod)
    120     {
    121         $zip = $this->createOrGetZip();
    122 
     120    protected function addFileToArchiveWithCompressionMethod($zip, $rootFolderPath, $localFilePath, $existingFileMode, $compressionMethod)
     121    {
    123122        if (!$this->shouldSkipFile($zip, $localFilePath, $existingFileMode)) {
    124123            $normalizedFullFilePath = $this->getNormalizedRealPath($rootFolderPath . '/' . $localFilePath);
     
    141140
    142141    /**
     142     * @param \ZipArchive $zip An opened zip archive object
    143143     * @param string $folderPath Path to the folder to be zipped
    144      * @param string|void $existingFileMode Controls what to do when trying to add an existing file
    145      * @return void
    146      */
    147     public function addFolderToArchive($folderPath, $existingFileMode = self::EXISTING_FILES_OVERWRITE)
    148     {
    149         $zip = $this->createOrGetZip();
    150 
     144     * @param string $existingFileMode Controls what to do when trying to add an existing file
     145     * @return void
     146     */
     147    public function addFolderToArchive($zip, $folderPath, $existingFileMode = self::EXISTING_FILES_OVERWRITE)
     148    {
    151149        $folderRealPath = $this->getNormalizedRealPath($folderPath) . '/';
    152150        $itemIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($folderPath, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
     
    185183    {
    186184        $realPath = realpath($path);
     185
    187186        return str_replace(DIRECTORY_SEPARATOR, '/', $realPath);
    188187    }
     
    191190     * Closes the archive and copies it into the given stream
    192191     *
     192     * @param \ZipArchive $zip An opened zip archive object
    193193     * @param resource $streamPointer Pointer to the stream to copy the zip
    194194     * @return void
    195195     */
    196     public function closeArchiveAndCopyToStream($streamPointer)
    197     {
    198         $zip = $this->createOrGetZip();
     196    public function closeArchiveAndCopyToStream($zip, $streamPointer)
     197    {
     198        $zipFilePath = $zip->filename;
    199199        $zip->close();
    200         unset($this->zip);
    201 
    202         $this->copyZipToStream($streamPointer);
     200
     201        $this->copyZipToStream($zipFilePath, $streamPointer);
    203202    }
    204203
     
    206205     * Streams the contents of the zip file into the given stream
    207206     *
     207     * @param string $zipFilePath Path of the zip file
    208208     * @param resource $pointer Pointer to the stream to copy the zip
    209209     * @return void
    210210     */
    211     protected function copyZipToStream($pointer)
    212     {
    213         $zipFilePointer = fopen($this->getZipFilePath(), 'r');
     211    protected function copyZipToStream($zipFilePath, $pointer)
     212    {
     213        $zipFilePointer = fopen($zipFilePath, 'r');
    214214        stream_copy_to_stream($zipFilePointer, $pointer);
    215215        fclose($zipFilePointer);
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/Exception/Border/InvalidNameException.php

    r112446 r115670  
    33namespace Box\Spout\Writer\Exception\Border;
    44
     5use Box\Spout\Common\Entity\Style\BorderPart;
    56use Box\Spout\Writer\Exception\WriterException;
    6 use Box\Spout\Writer\Style\BorderPart;
    77
    88class InvalidNameException extends WriterException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/Exception/Border/InvalidStyleException.php

    r112446 r115670  
    33namespace Box\Spout\Writer\Exception\Border;
    44
     5use Box\Spout\Common\Entity\Style\BorderPart;
    56use Box\Spout\Writer\Exception\WriterException;
    6 use Box\Spout\Writer\Style\BorderPart;
    77
    88class InvalidStyleException extends WriterException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/Exception/Border/InvalidWidthException.php

    r112446 r115670  
    33namespace Box\Spout\Writer\Exception\Border;
    44
     5use Box\Spout\Common\Entity\Style\BorderPart;
    56use Box\Spout\Writer\Exception\WriterException;
    6 use Box\Spout\Writer\Style\BorderPart;
    77
    88class InvalidWidthException extends WriterException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/Exception/InvalidSheetNameException.php

    r112446 r115670  
    55/**
    66 * Class InvalidSheetNameException
    7  *
    8  * @api
    9  * @package Box\Spout\Writer\Exception
    107 */
    118class InvalidSheetNameException extends WriterException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/Exception/SheetNotFoundException.php

    r112446 r115670  
    55/**
    66 * Class SheetNotFoundException
    7  *
    8  * @api
    9  * @package Box\Spout\Writer\Exception
    107 */
    118class SheetNotFoundException extends WriterException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/Exception/WriterAlreadyOpenedException.php

    r112446 r115670  
    55/**
    66 * Class WriterAlreadyOpenedException
    7  *
    8  * @api
    9  * @package Box\Spout\Writer\Exception
    107 */
    118class WriterAlreadyOpenedException extends WriterException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/Exception/WriterException.php

    r112446 r115670  
    88 * Class WriterException
    99 *
    10  * @package Box\Spout\Writer\Exception
    1110 * @abstract
    1211 */
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/Exception/WriterNotOpenedException.php

    r112446 r115670  
    55/**
    66 * Class WriterNotOpenedException
    7  *
    8  * @api
    9  * @package Box\Spout\Writer\Exception
    107 */
    118class WriterNotOpenedException extends WriterException
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/ODS/Helper/BorderHelper.php

    r112446 r115670  
    33namespace Box\Spout\Writer\ODS\Helper;
    44
    5 use Box\Spout\Writer\Style\BorderPart;
    6 use Box\Spout\Writer\Style\Border;
     5use Box\Spout\Common\Entity\Style\Border;
     6use Box\Spout\Common\Entity\Style\BorderPart;
    77
    88/**
     
    2828     */
    2929    protected static $widthMap = [
    30         Border::WIDTH_THIN => '0.75pt',
     30        Border::WIDTH_THIN   => '0.75pt',
    3131        Border::WIDTH_MEDIUM => '1.75pt',
    32         Border::WIDTH_THICK => '2.5pt',
     32        Border::WIDTH_THICK  => '2.5pt',
    3333    ];
    3434
     
    3939     */
    4040    protected static $styleMap = [
    41         Border::STYLE_SOLID => 'solid',
     41        Border::STYLE_SOLID  => 'solid',
    4242        Border::STYLE_DASHED => 'dashed',
    4343        Border::STYLE_DOTTED => 'dotted',
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/ODS/Helper/FileSystemHelper.php

    r112446 r115670  
    33namespace Box\Spout\Writer\ODS\Helper;
    44
     5use Box\Spout\Writer\Common\Entity\Worksheet;
     6use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface;
    57use Box\Spout\Writer\Common\Helper\ZipHelper;
    6 use Box\Spout\Writer\ODS\Internal\Worksheet;
     8use Box\Spout\Writer\ODS\Manager\Style\StyleManager;
     9use Box\Spout\Writer\ODS\Manager\WorksheetManager;
    710
    811/**
     
    1013 * This class provides helper functions to help with the file system operations
    1114 * like files/folders creation & deletion for ODS files
    12  *
    13  * @package Box\Spout\Writer\ODS\Helper
    1415 */
    15 class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper
     16class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper implements FileSystemWithRootFolderHelperInterface
    1617{
    1718    const APP_NAME = 'Spout';
     
    2728    const STYLES_XML_FILE_NAME = 'styles.xml';
    2829
     30    /** @var ZipHelper Helper to perform tasks with Zip archive */
     31    private $zipHelper;
     32
    2933    /** @var string Path to the root folder inside the temp folder where the files to create the ODS will be stored */
    3034    protected $rootFolder;
     
    3741
    3842    /**
     43     * @param string $baseFolderPath The path of the base folder where all the I/O can occur
     44     * @param ZipHelper $zipHelper Helper to perform tasks with Zip archive
     45     */
     46    public function __construct($baseFolderPath, $zipHelper)
     47    {
     48        parent::__construct($baseFolderPath);
     49        $this->zipHelper = $zipHelper;
     50    }
     51
     52    /**
    3953     * @return string
    4054     */
     
    5569     * Creates all the folders needed to create a ODS file, as well as the files that won't change.
    5670     *
     71     * @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the base folders
    5772     * @return void
    58      * @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the base folders
    5973     */
    6074    public function createBaseFilesAndFolders()
     
    7185     * Creates the folder that will be used as root
    7286     *
    73      * @return FileSystemHelper
    7487     * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
     88     * @return FileSystemHelper
    7589     */
    7690    protected function createRootFolder()
    7791    {
    7892        $this->rootFolder = $this->createFolder($this->baseFolderRealPath, uniqid('ods'));
     93
    7994        return $this;
    8095    }
     
    8398     * Creates the "META-INF" folder under the root folder as well as the "manifest.xml" file in it
    8499     *
    85      * @return FileSystemHelper
    86100     * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or the "manifest.xml" file
     101     * @return FileSystemHelper
    87102     */
    88103    protected function createMetaInfoFolderAndFile()
     
    98113     * Creates the "manifest.xml" file under the "META-INF" folder (under root)
    99114     *
    100      * @return FileSystemHelper
    101115     * @throws \Box\Spout\Common\Exception\IOException If unable to create the file
     116     * @return FileSystemHelper
    102117     */
    103118    protected function createManifestFile()
    104119    {
    105         $manifestXmlFileContents = <<<EOD
     120        $manifestXmlFileContents = <<<'EOD'
    106121<?xml version="1.0" encoding="UTF-8"?>
    107122<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">
     
    122137     * This folder is not part of the final ODS file and is only used to be able to jump between sheets.
    123138     *
    124      * @return FileSystemHelper
    125139     * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
     140     * @return FileSystemHelper
    126141     */
    127142    protected function createSheetsContentTempFolder()
    128143    {
    129144        $this->sheetsContentTempFolder = $this->createFolder($this->rootFolder, self::SHEETS_CONTENT_TEMP_FOLDER_NAME);
     145
    130146        return $this;
    131147    }
     
    134150     * Creates the "meta.xml" file under the root folder
    135151     *
    136      * @return FileSystemHelper
    137152     * @throws \Box\Spout\Common\Exception\IOException If unable to create the file
     153     * @return FileSystemHelper
    138154     */
    139155    protected function createMetaFile()
     
    161177     * Creates the "mimetype" file under the root folder
    162178     *
    163      * @return FileSystemHelper
    164179     * @throws \Box\Spout\Common\Exception\IOException If unable to create the file
     180     * @return FileSystemHelper
    165181     */
    166182    protected function createMimetypeFile()
    167183    {
    168184        $this->createFileWithContents($this->rootFolder, self::MIMETYPE_FILE_NAME, self::MIMETYPE);
     185
    169186        return $this;
    170187    }
     
    173190     * Creates the "content.xml" file under the root folder
    174191     *
     192     * @param WorksheetManager $worksheetManager
     193     * @param StyleManager $styleManager
    175194     * @param Worksheet[] $worksheets
    176      * @param StyleHelper $styleHelper
    177      * @return FileSystemHelper
    178      */
    179     public function createContentFile($worksheets, $styleHelper)
    180     {
    181         $contentXmlFileContents = <<<EOD
     195     * @return FileSystemHelper
     196     */
     197    public function createContentFile($worksheetManager, $styleManager, $worksheets)
     198    {
     199        $contentXmlFileContents = <<<'EOD'
    182200<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    183201<office:document-content office:version="1.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:msoxl="http://schemas.microsoft.com/office/excel/formula" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xlink="http://www.w3.org/1999/xlink">
    184202EOD;
    185203
    186         $contentXmlFileContents .= $styleHelper->getContentXmlFontFaceSectionContent();
    187         $contentXmlFileContents .= $styleHelper->getContentXmlAutomaticStylesSectionContent(count($worksheets));
     204        $contentXmlFileContents .= $styleManager->getContentXmlFontFaceSectionContent();
     205        $contentXmlFileContents .= $styleManager->getContentXmlAutomaticStylesSectionContent($worksheets);
    188206
    189207        $contentXmlFileContents .= '<office:body><office:spreadsheet>';
     
    197215        foreach ($worksheets as $worksheet) {
    198216            // write the "<table:table>" node, with the final sheet's name
    199             fwrite($contentXmlHandle, $worksheet->getTableElementStartAsString());
    200 
    201             $worksheetFilePath = $worksheet->getWorksheetFilePath();
     217            fwrite($contentXmlHandle, $worksheetManager->getTableElementStartAsString($worksheet));
     218
     219            $worksheetFilePath = $worksheet->getFilePath();
    202220            $this->copyFileContentsToTarget($worksheetFilePath, $contentXmlHandle);
    203221
     
    237255    {
    238256        $this->deleteFolderRecursively($this->sheetsContentTempFolder);
    239         return $this;
    240     }
    241 
     257
     258        return $this;
     259    }
    242260
    243261    /**
    244262     * Creates the "styles.xml" file under the root folder
    245263     *
    246      * @param StyleHelper $styleHelper
     264     * @param StyleManager $styleManager
    247265     * @param int $numWorksheets Number of created worksheets
    248266     * @return FileSystemHelper
    249267     */
    250     public function createStylesFile($styleHelper, $numWorksheets)
    251     {
    252         $stylesXmlFileContents = $styleHelper->getStylesXMLFileContent($numWorksheets);
     268    public function createStylesFile($styleManager, $numWorksheets)
     269    {
     270        $stylesXmlFileContents = $styleManager->getStylesXMLFileContent($numWorksheets);
    253271        $this->createFileWithContents($this->rootFolder, self::STYLES_XML_FILE_NAME, $stylesXmlFileContents);
    254272
     
    264282    public function zipRootFolderAndCopyToStream($streamPointer)
    265283    {
    266         $zipHelper = new ZipHelper($this->rootFolder);
     284        $zip = $this->zipHelper->createZip($this->rootFolder);
     285
     286        $zipFilePath = $this->zipHelper->getZipFilePath($zip);
    267287
    268288        // In order to have the file's mime type detected properly, files need to be added
    269289        // to the zip file in a particular order.
    270290        // @see http://www.jejik.com/articles/2010/03/how_to_correctly_create_odf_documents_using_zip/
    271         $zipHelper->addUncompressedFileToArchive($this->rootFolder, self::MIMETYPE_FILE_NAME);
    272 
    273         $zipHelper->addFolderToArchive($this->rootFolder, ZipHelper::EXISTING_FILES_SKIP);
    274         $zipHelper->closeArchiveAndCopyToStream($streamPointer);
     291        $this->zipHelper->addUncompressedFileToArchive($zip, $this->rootFolder, self::MIMETYPE_FILE_NAME);
     292
     293        $this->zipHelper->addFolderToArchive($zip, $this->rootFolder, ZipHelper::EXISTING_FILES_SKIP);
     294        $this->zipHelper->closeArchiveAndCopyToStream($zip, $streamPointer);
    275295
    276296        // once the zip is copied, remove it
    277         $this->deleteFile($zipHelper->getZipFilePath());
     297        $this->deleteFile($zipFilePath);
    278298    }
    279299}
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/ODS/Writer.php

    r112446 r115670  
    33namespace Box\Spout\Writer\ODS;
    44
    5 use Box\Spout\Writer\AbstractMultiSheetsWriter;
    6 use Box\Spout\Writer\Common;
    7 use Box\Spout\Writer\ODS\Internal\Workbook;
     5use Box\Spout\Writer\Common\Entity\Options;
     6use Box\Spout\Writer\WriterMultiSheetsAbstract;
    87
    98/**
    109 * Class Writer
    1110 * This class provides base support to write data to ODS files
    12  *
    13  * @package Box\Spout\Writer\ODS
    1411 */
    15 class Writer extends AbstractMultiSheetsWriter
     12class Writer extends WriterMultiSheetsAbstract
    1613{
    1714    /** @var string Content-Type value for the header */
    1815    protected static $headerContentType = 'application/vnd.oasis.opendocument.spreadsheet';
    19 
    20     /** @var string Temporary folder where the files to create the ODS will be stored */
    21     protected $tempFolder;
    22 
    23     /** @var Internal\Workbook The workbook for the ODS file */
    24     protected $book;
    2516
    2617    /**
     
    2819     * This must be set before opening the writer.
    2920     *
    30      * @api
    3121     * @param string $tempFolder Temporary folder where the files to create the ODS will be stored
     22     * @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened
    3223     * @return Writer
    33      * @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened
    3424     */
    3525    public function setTempFolder($tempFolder)
     
    3727        $this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.');
    3828
    39         $this->tempFolder = $tempFolder;
     29        $this->optionsManager->setOption(Options::TEMP_FOLDER, $tempFolder);
     30
    4031        return $this;
    4132    }
    42 
    43     /**
    44      * Configures the write and sets the current sheet pointer to a new sheet.
    45      *
    46      * @return void
    47      * @throws \Box\Spout\Common\Exception\IOException If unable to open the file for writing
    48      */
    49     protected function openWriter()
    50     {
    51         $tempFolder = ($this->tempFolder) ? : sys_get_temp_dir();
    52         $this->book = new Workbook($tempFolder, $this->shouldCreateNewSheetsAutomatically, $this->defaultRowStyle);
    53         $this->book->addNewSheetAndMakeItCurrent();
    54     }
    55 
    56     /**
    57      * @return Internal\Workbook The workbook representing the file to be written
    58      */
    59     protected function getWorkbook()
    60     {
    61         return $this->book;
    62     }
    63 
    64     /**
    65      * Adds data to the currently opened writer.
    66      * If shouldCreateNewSheetsAutomatically option is set to true, it will handle pagination
    67      * with the creation of new worksheets if one worksheet has reached its maximum capicity.
    68      *
    69      * @param array $dataRow Array containing data to be written.
    70      *          Example $dataRow = ['data1', 1234, null, '', 'data5'];
    71      * @param \Box\Spout\Writer\Style\Style $style Style to be applied to the row.
    72      * @return void
    73      * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the book is not created yet
    74      * @throws \Box\Spout\Common\Exception\IOException If unable to write data
    75      */
    76     protected function addRowToWriter(array $dataRow, $style)
    77     {
    78         $this->throwIfBookIsNotAvailable();
    79         $this->book->addRowToCurrentWorksheet($dataRow, $style);
    80     }
    81 
    82     /**
    83      * Closes the writer, preventing any additional writing.
    84      *
    85      * @return void
    86      */
    87     protected function closeWriter()
    88     {
    89         if ($this->book) {
    90             $this->book->close($this->filePointer);
    91         }
    92     }
    9333}
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/WriterInterface.php

    r112446 r115670  
    33namespace Box\Spout\Writer;
    44
     5use Box\Spout\Common\Entity\Row;
     6use Box\Spout\Common\Entity\Style\Style;
     7
    58/**
    69 * Interface WriterInterface
    7  *
    8  * @package Box\Spout\Writer
    910 */
    1011interface WriterInterface
    1112{
    1213    /**
    13      * Inits the writer and opens it to accept data.
     14     * Initializes the writer and opens it to accept data.
    1415     * By using this method, the data will be written to a file.
    1516     *
    1617     * @param  string $outputFilePath Path of the output file that will contain the data
     18     * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable
    1719     * @return WriterInterface
    18      * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable
    1920     */
    2021    public function openToFile($outputFilePath);
    2122
    2223    /**
    23      * Inits the writer and opens it to accept data.
     24     * Initializes the writer and opens it to accept data.
    2425     * By using this method, the data will be outputted directly to the browser.
    2526     *
    2627     * @param  string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept
     28     * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened
    2729     * @return WriterInterface
    28      * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened
    2930     */
    3031    public function openToBrowser($outputFileName);
    3132
    3233    /**
    33      * Write given data to the output. New data will be appended to end of stream.
     34     * Sets the default styles for all rows added with "addRow".
     35     * Overriding the default style instead of using "addRowWithStyle" improves performance by 20%.
     36     * @see https://github.com/box/spout/issues/272
    3437     *
    35      * @param  array $dataRow Array containing data to be streamed.
    36      *          Example $dataRow = ['data1', 1234, null, '', 'data5'];
     38     * @param Style $defaultStyle
    3739     * @return WriterInterface
     40     */
     41    public function setDefaultRowStyle(Style $defaultStyle);
     42
     43    /**
     44     * Appends a row to the end of the stream.
     45     *
     46     * @param Row $row The row to be appended to the stream
    3847     * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yet
    3948     * @throws \Box\Spout\Common\Exception\IOException If unable to write data
     49     * @return WriterInterface
    4050     */
    41     public function addRow(array $dataRow);
     51    public function addRow(Row $row);
    4252
    4353    /**
    44      * Write given data to the output and apply the given style.
    45      * @see addRow
     54     * Appends the rows to the end of the stream.
    4655     *
    47      * @param array $dataRow Array of array containing data to be streamed.
    48      * @param Style\Style $style Style to be applied to the row.
    49      * @return WriterInterface
    50      * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
    51      * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer
    52      * @throws \Box\Spout\Common\Exception\IOException If unable to write data
    53      */
    54     public function addRowWithStyle(array $dataRow, $style);
    55 
    56     /**
    57      * Write given data to the output. New data will be appended to end of stream.
    58      *
    59      * @param  array $dataRows Array of array containing data to be streamed.
    60      *          Example $dataRow = [
    61      *              ['data11', 12, , '', 'data13'],
    62      *              ['data21', 'data22', null],
    63      *          ];
    64      * @return WriterInterface
     56     * @param Row[] $rows The rows to be appended to the stream
    6557     * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
    6658     * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yet
    6759     * @throws \Box\Spout\Common\Exception\IOException If unable to write data
     60     * @return WriterInterface
    6861     */
    69     public function addRows(array $dataRows);
    70 
    71     /**
    72      * Write given data to the output and apply the given style.
    73      * @see addRows
    74      *
    75      * @param array $dataRows Array of array containing data to be streamed.
    76      * @param Style\Style $style Style to be applied to the rows.
    77      * @return WriterInterface
    78      * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
    79      * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer
    80      * @throws \Box\Spout\Common\Exception\IOException If unable to write data
    81      */
    82     public function addRowsWithStyle(array $dataRows, $style);
     62    public function addRows(array $rows);
    8363
    8464    /**
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/XLSX/Helper/BorderHelper.php

    r112446 r115670  
    33namespace Box\Spout\Writer\XLSX\Helper;
    44
    5 use Box\Spout\Writer\Style\Border;
    6 use Box\Spout\Writer\Style\BorderPart;
     5use Box\Spout\Common\Entity\Style\Border;
     6use Box\Spout\Common\Entity\Style\BorderPart;
    77
    88class BorderHelper
     
    1010    public static $xlsxStyleMap = [
    1111        Border::STYLE_SOLID => [
    12             Border::WIDTH_THIN => 'thin',
     12            Border::WIDTH_THIN   => 'thin',
    1313            Border::WIDTH_MEDIUM => 'medium',
    14             Border::WIDTH_THICK => 'thick'
     14            Border::WIDTH_THICK  => 'thick',
    1515        ],
    1616        Border::STYLE_DOTTED => [
    17             Border::WIDTH_THIN => 'dotted',
     17            Border::WIDTH_THIN   => 'dotted',
    1818            Border::WIDTH_MEDIUM => 'dotted',
    19             Border::WIDTH_THICK => 'dotted',
     19            Border::WIDTH_THICK  => 'dotted',
    2020        ],
    2121        Border::STYLE_DASHED => [
    22             Border::WIDTH_THIN => 'dashed',
     22            Border::WIDTH_THIN   => 'dashed',
    2323            Border::WIDTH_MEDIUM => 'mediumDashed',
    24             Border::WIDTH_THICK => 'mediumDashed',
     24            Border::WIDTH_THICK  => 'mediumDashed',
    2525        ],
    2626        Border::STYLE_DOUBLE => [
    27             Border::WIDTH_THIN => 'double',
     27            Border::WIDTH_THIN   => 'double',
    2828            Border::WIDTH_MEDIUM => 'double',
    29             Border::WIDTH_THICK => 'double',
     29            Border::WIDTH_THICK  => 'double',
    3030        ],
    3131        Border::STYLE_NONE => [
    32             Border::WIDTH_THIN => 'none',
     32            Border::WIDTH_THIN   => 'none',
    3333            Border::WIDTH_MEDIUM => 'none',
    34             Border::WIDTH_THICK => 'none',
     34            Border::WIDTH_THICK  => 'none',
    3535        ],
    3636    ];
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/XLSX/Helper/FileSystemHelper.php

    r112446 r115670  
    33namespace Box\Spout\Writer\XLSX\Helper;
    44
     5use Box\Spout\Writer\Common\Entity\Worksheet;
     6use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface;
    57use Box\Spout\Writer\Common\Helper\ZipHelper;
    6 use Box\Spout\Writer\XLSX\Internal\Worksheet;
     8use Box\Spout\Writer\XLSX\Manager\Style\StyleManager;
    79
    810/**
     
    1012 * This class provides helper functions to help with the file system operations
    1113 * like files/folders creation & deletion for XLSX files
    12  *
    13  * @package Box\Spout\Writer\XLSX\Helper
    1414 */
    15 class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper
     15class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper implements FileSystemWithRootFolderHelperInterface
    1616{
    1717    const APP_NAME = 'Spout';
     
    3030    const STYLES_XML_FILE_NAME = 'styles.xml';
    3131
     32    /** @var ZipHelper Helper to perform tasks with Zip archive */
     33    private $zipHelper;
     34
     35    /** @var \Box\Spout\Common\Helper\Escaper\XLSX Used to escape XML data */
     36    private $escaper;
     37
    3238    /** @var string Path to the root folder inside the temp folder where the files to create the XLSX will be stored */
    33     protected $rootFolder;
     39    private $rootFolder;
    3440
    3541    /** @var string Path to the "_rels" folder inside the root folder */
    36     protected $relsFolder;
     42    private $relsFolder;
    3743
    3844    /** @var string Path to the "docProps" folder inside the root folder */
    39     protected $docPropsFolder;
     45    private $docPropsFolder;
    4046
    4147    /** @var string Path to the "xl" folder inside the root folder */
    42     protected $xlFolder;
     48    private $xlFolder;
    4349
    4450    /** @var string Path to the "_rels" folder inside the "xl" folder */
    45     protected $xlRelsFolder;
     51    private $xlRelsFolder;
    4652
    4753    /** @var string Path to the "worksheets" folder inside the "xl" folder */
    48     protected $xlWorksheetsFolder;
     54    private $xlWorksheetsFolder;
     55
     56    /**
     57     * @param string $baseFolderPath The path of the base folder where all the I/O can occur
     58     * @param ZipHelper $zipHelper Helper to perform tasks with Zip archive
     59     * @param \Box\Spout\Common\Helper\Escaper\XLSX $escaper Used to escape XML data
     60     */
     61    public function __construct($baseFolderPath, $zipHelper, $escaper)
     62    {
     63        parent::__construct($baseFolderPath);
     64        $this->zipHelper = $zipHelper;
     65        $this->escaper = $escaper;
     66    }
    4967
    5068    /**
     
    7593     * Creates all the folders needed to create a XLSX file, as well as the files that won't change.
    7694     *
     95     * @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the base folders
    7796     * @return void
    78      * @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the base folders
    7997     */
    8098    public function createBaseFilesAndFolders()
     
    90108     * Creates the folder that will be used as root
    91109     *
    92      * @return FileSystemHelper
    93110     * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
    94      */
    95     protected function createRootFolder()
     111     * @return FileSystemHelper
     112     */
     113    private function createRootFolder()
    96114    {
    97115        $this->rootFolder = $this->createFolder($this->baseFolderRealPath, uniqid('xlsx', true));
     116
    98117        return $this;
    99118    }
     
    102121     * Creates the "_rels" folder under the root folder as well as the ".rels" file in it
    103122     *
    104      * @return FileSystemHelper
    105123     * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or the ".rels" file
    106      */
    107     protected function createRelsFolderAndFile()
     124     * @return FileSystemHelper
     125     */
     126    private function createRelsFolderAndFile()
    108127    {
    109128        $this->relsFolder = $this->createFolder($this->rootFolder, self::RELS_FOLDER_NAME);
     
    117136     * Creates the ".rels" file under the "_rels" folder (under root)
    118137     *
    119      * @return FileSystemHelper
    120138     * @throws \Box\Spout\Common\Exception\IOException If unable to create the file
    121      */
    122     protected function createRelsFile()
    123     {
    124         $relsFileContents = <<<EOD
     139     * @return FileSystemHelper
     140     */
     141    private function createRelsFile()
     142    {
     143        $relsFileContents = <<<'EOD'
    125144<?xml version="1.0" encoding="UTF-8"?>
    126145<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
     
    139158     * Creates the "docProps" folder under the root folder as well as the "app.xml" and "core.xml" files in it
    140159     *
    141      * @return FileSystemHelper
    142160     * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or one of the files
    143      */
    144     protected function createDocPropsFolderAndFiles()
     161     * @return FileSystemHelper
     162     */
     163    private function createDocPropsFolderAndFiles()
    145164    {
    146165        $this->docPropsFolder = $this->createFolder($this->rootFolder, self::DOC_PROPS_FOLDER_NAME);
     
    155174     * Creates the "app.xml" file under the "docProps" folder
    156175     *
    157      * @return FileSystemHelper
    158176     * @throws \Box\Spout\Common\Exception\IOException If unable to create the file
    159      */
    160     protected function createAppXmlFile()
     177     * @return FileSystemHelper
     178     */
     179    private function createAppXmlFile()
    161180    {
    162181        $appName = self::APP_NAME;
     
    177196     * Creates the "core.xml" file under the "docProps" folder
    178197     *
    179      * @return FileSystemHelper
    180198     * @throws \Box\Spout\Common\Exception\IOException If unable to create the file
    181      */
    182     protected function createCoreXmlFile()
     199     * @return FileSystemHelper
     200     */
     201    private function createCoreXmlFile()
    183202    {
    184203        $createdDate = (new \DateTime())->format(\DateTime::W3C);
     
    200219     * Creates the "xl" folder under the root folder as well as its subfolders
    201220     *
    202      * @return FileSystemHelper
    203221     * @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the folders
    204      */
    205     protected function createXlFolderAndSubFolders()
     222     * @return FileSystemHelper
     223     */
     224    private function createXlFolderAndSubFolders()
    206225    {
    207226        $this->xlFolder = $this->createFolder($this->rootFolder, self::XL_FOLDER_NAME);
     
    215234     * Creates the "_rels" folder under the "xl" folder
    216235     *
    217      * @return FileSystemHelper
    218236     * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
    219      */
    220     protected function createXlRelsFolder()
     237     * @return FileSystemHelper
     238     */
     239    private function createXlRelsFolder()
    221240    {
    222241        $this->xlRelsFolder = $this->createFolder($this->xlFolder, self::RELS_FOLDER_NAME);
     242
    223243        return $this;
    224244    }
     
    227247     * Creates the "worksheets" folder under the "xl" folder
    228248     *
    229      * @return FileSystemHelper
    230249     * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
    231      */
    232     protected function createXlWorksheetsFolder()
     250     * @return FileSystemHelper
     251     */
     252    private function createXlWorksheetsFolder()
    233253    {
    234254        $this->xlWorksheetsFolder = $this->createFolder($this->xlFolder, self::WORKSHEETS_FOLDER_NAME);
     255
    235256        return $this;
    236257    }
     
    244265    public function createContentTypesFile($worksheets)
    245266    {
    246         $contentTypesXmlFileContents = <<<EOD
     267        $contentTypesXmlFileContents = <<<'EOD'
    247268<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    248269<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
     
    252273EOD;
    253274
    254     /** @var Worksheet $worksheet */
    255     foreach ($worksheets as $worksheet) {
    256         $contentTypesXmlFileContents .= '<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" PartName="/xl/worksheets/sheet' . $worksheet->getId() . '.xml"/>';
    257     }
    258 
    259     $contentTypesXmlFileContents .= <<<EOD
     275        /** @var Worksheet $worksheet */
     276        foreach ($worksheets as $worksheet) {
     277            $contentTypesXmlFileContents .= '<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" PartName="/xl/worksheets/sheet' . $worksheet->getId() . '.xml"/>';
     278        }
     279
     280        $contentTypesXmlFileContents .= <<<'EOD'
    260281    <Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml" PartName="/xl/styles.xml"/>
    261282    <Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml" PartName="/xl/sharedStrings.xml"/>
     
    278299    public function createWorkbookFile($worksheets)
    279300    {
    280         $workbookXmlFileContents = <<<EOD
     301        $workbookXmlFileContents = <<<'EOD'
    281302<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    282303<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
     
    284305EOD;
    285306
    286         /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
    287         $escaper = \Box\Spout\Common\Escaper\XLSX::getInstance();
    288 
    289307        /** @var Worksheet $worksheet */
    290308        foreach ($worksheets as $worksheet) {
    291309            $worksheetName = $worksheet->getExternalSheet()->getName();
     310            $worksheetVisibility = $worksheet->getExternalSheet()->isVisible() ? 'visible' : 'hidden';
    292311            $worksheetId = $worksheet->getId();
    293             $workbookXmlFileContents .= '<sheet name="' . $escaper->escape($worksheetName) . '" sheetId="' . $worksheetId . '" r:id="rIdSheet' . $worksheetId . '"/>';
     312            $workbookXmlFileContents .= '<sheet name="' . $this->escaper->escape($worksheetName) . '" sheetId="' . $worksheetId . '" r:id="rIdSheet' . $worksheetId . '" state="' . $worksheetVisibility . '"/>';
    294313        }
    295314
    296         $workbookXmlFileContents .= <<<EOD
     315        $workbookXmlFileContents .= <<<'EOD'
    297316    </sheets>
    298317</workbook>
     
    312331    public function createWorkbookRelsFile($worksheets)
    313332    {
    314         $workbookRelsXmlFileContents = <<<EOD
     333        $workbookRelsXmlFileContents = <<<'EOD'
    315334<?xml version="1.0" encoding="UTF-8"?>
    316335<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
     
    335354     * Creates the "styles.xml" file under the "xl" folder
    336355     *
    337      * @param StyleHelper $styleHelper
    338      * @return FileSystemHelper
    339      */
    340     public function createStylesFile($styleHelper)
    341     {
    342         $stylesXmlFileContents = $styleHelper->getStylesXMLFileContent();
     356     * @param StyleManager $styleManager
     357     * @return FileSystemHelper
     358     */
     359    public function createStylesFile($styleManager)
     360    {
     361        $stylesXmlFileContents = $styleManager->getStylesXMLFileContent();
    343362        $this->createFileWithContents($this->xlFolder, self::STYLES_XML_FILE_NAME, $stylesXmlFileContents);
    344363
     
    354373    public function zipRootFolderAndCopyToStream($streamPointer)
    355374    {
    356         $zipHelper = new ZipHelper($this->rootFolder);
     375        $zip = $this->zipHelper->createZip($this->rootFolder);
     376
     377        $zipFilePath = $this->zipHelper->getZipFilePath($zip);
    357378
    358379        // In order to have the file's mime type detected properly, files need to be added
    359380        // to the zip file in a particular order.
    360381        // "[Content_Types].xml" then at least 2 files located in "xl" folder should be zipped first.
    361         $zipHelper->addFileToArchive($this->rootFolder, self::CONTENT_TYPES_XML_FILE_NAME);
    362         $zipHelper->addFileToArchive($this->rootFolder, self::XL_FOLDER_NAME . '/' . self::WORKBOOK_XML_FILE_NAME);
    363         $zipHelper->addFileToArchive($this->rootFolder, self::XL_FOLDER_NAME . '/' . self::STYLES_XML_FILE_NAME);
    364 
    365         $zipHelper->addFolderToArchive($this->rootFolder, ZipHelper::EXISTING_FILES_SKIP);
    366         $zipHelper->closeArchiveAndCopyToStream($streamPointer);
     382        $this->zipHelper->addFileToArchive($zip, $this->rootFolder, self::CONTENT_TYPES_XML_FILE_NAME);
     383        $this->zipHelper->addFileToArchive($zip, $this->rootFolder, self::XL_FOLDER_NAME . '/' . self::WORKBOOK_XML_FILE_NAME);
     384        $this->zipHelper->addFileToArchive($zip, $this->rootFolder, self::XL_FOLDER_NAME . '/' . self::STYLES_XML_FILE_NAME);
     385
     386        $this->zipHelper->addFolderToArchive($zip, $this->rootFolder, ZipHelper::EXISTING_FILES_SKIP);
     387        $this->zipHelper->closeArchiveAndCopyToStream($zip, $streamPointer);
    367388
    368389        // once the zip is copied, remove it
    369         $this->deleteFile($zipHelper->getZipFilePath());
     390        $this->deleteFile($zipFilePath);
    370391    }
    371392}
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/Writer/XLSX/Writer.php

    r112446 r115670  
    33namespace Box\Spout\Writer\XLSX;
    44
    5 use Box\Spout\Writer\AbstractMultiSheetsWriter;
    6 use Box\Spout\Writer\Style\StyleBuilder;
    7 use Box\Spout\Writer\XLSX\Internal\Workbook;
     5use Box\Spout\Writer\Common\Entity\Options;
     6use Box\Spout\Writer\WriterMultiSheetsAbstract;
    87
    98/**
    109 * Class Writer
    1110 * This class provides base support to write data to XLSX files
    12  *
    13  * @package Box\Spout\Writer\XLSX
    1411 */
    15 class Writer extends AbstractMultiSheetsWriter
     12class Writer extends WriterMultiSheetsAbstract
    1613{
    17     /** Default style font values */
    18     const DEFAULT_FONT_SIZE = 12;
    19     const DEFAULT_FONT_NAME = 'Calibri';
    20 
    2114    /** @var string Content-Type value for the header */
    2215    protected static $headerContentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
    23 
    24     /** @var string Temporary folder where the files to create the XLSX will be stored */
    25     protected $tempFolder;
    26 
    27     /** @var bool Whether inline or shared strings should be used - inline string is more memory efficient */
    28     protected $shouldUseInlineStrings = true;
    29 
    30     /** @var Internal\Workbook The workbook for the XLSX file */
    31     protected $book;
    3216
    3317    /**
     
    3519     * This must be set before opening the writer.
    3620     *
    37      * @api
    3821     * @param string $tempFolder Temporary folder where the files to create the XLSX will be stored
     22     * @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened
    3923     * @return Writer
    40      * @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened
    4124     */
    4225    public function setTempFolder($tempFolder)
     
    4427        $this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.');
    4528
    46         $this->tempFolder = $tempFolder;
     29        $this->optionsManager->setOption(Options::TEMP_FOLDER, $tempFolder);
     30
    4731        return $this;
    4832    }
     
    5236     * This must be set before opening the writer.
    5337     *
    54      * @api
    5538     * @param bool $shouldUseInlineStrings Whether inline or shared strings should be used
     39     * @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened
    5640     * @return Writer
    57      * @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened
    5841     */
    5942    public function setShouldUseInlineStrings($shouldUseInlineStrings)
     
    6144        $this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.');
    6245
    63         $this->shouldUseInlineStrings = $shouldUseInlineStrings;
     46        $this->optionsManager->setOption(Options::SHOULD_USE_INLINE_STRINGS, $shouldUseInlineStrings);
     47
    6448        return $this;
    6549    }
    66 
    67     /**
    68      * Configures the write and sets the current sheet pointer to a new sheet.
    69      *
    70      * @return void
    71      * @throws \Box\Spout\Common\Exception\IOException If unable to open the file for writing
    72      */
    73     protected function openWriter()
    74     {
    75         if (!$this->book) {
    76             $tempFolder = ($this->tempFolder) ? : sys_get_temp_dir();
    77             $this->book = new Workbook($tempFolder, $this->shouldUseInlineStrings, $this->shouldCreateNewSheetsAutomatically, $this->defaultRowStyle);
    78             $this->book->addNewSheetAndMakeItCurrent();
    79         }
    80     }
    81 
    82     /**
    83      * @return Internal\Workbook The workbook representing the file to be written
    84      */
    85     protected function getWorkbook()
    86     {
    87         return $this->book;
    88     }
    89 
    90     /**
    91      * Adds data to the currently opened writer.
    92      * If shouldCreateNewSheetsAutomatically option is set to true, it will handle pagination
    93      * with the creation of new worksheets if one worksheet has reached its maximum capicity.
    94      *
    95      * @param array $dataRow Array containing data to be written.
    96      *          Example $dataRow = ['data1', 1234, null, '', 'data5'];
    97      * @param \Box\Spout\Writer\Style\Style $style Style to be applied to the row.
    98      * @return void
    99      * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the book is not created yet
    100      * @throws \Box\Spout\Common\Exception\IOException If unable to write data
    101      */
    102     protected function addRowToWriter(array $dataRow, $style)
    103     {
    104         $this->throwIfBookIsNotAvailable();
    105         $this->book->addRowToCurrentWorksheet($dataRow, $style);
    106     }
    107 
    108     /**
    109      * Returns the default style to be applied to rows.
    110      *
    111      * @return \Box\Spout\Writer\Style\Style
    112      */
    113     protected function getDefaultRowStyle()
    114     {
    115         return (new StyleBuilder())
    116             ->setFontSize(self::DEFAULT_FONT_SIZE)
    117             ->setFontName(self::DEFAULT_FONT_NAME)
    118             ->build();
    119     }
    120 
    121     /**
    122      * Closes the writer, preventing any additional writing.
    123      *
    124      * @return void
    125      */
    126     protected function closeWriter()
    127     {
    128         if ($this->book) {
    129             $this->book->close($this->filePointer);
    130         }
    131     }
    13250}
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/lib/Spout/version.txt

    r112446 r115670  
    22Download : https://github.com/box/spout/releases
    33
    4 Version 2.73
     4Version 3.0.1
  • _squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/paquet.xml

    r115533 r115670  
    22        prefix="soyezcreateurs"
    33        categorie="squelette"
    4         version="5.0.57"
     4        version="5.0.58"
    55        etat="stable"
    66        compatibilite="[3.1.8;3.2.*]"
Note: See TracChangeset for help on using the changeset viewer.