modifs.mineures sans commentaires
This commit is contained in:
parent
b71cd8beb8
commit
907aba4590
|
@ -1,16 +1,3 @@
|
|||
/.idea/**/workspace.xml
|
||||
/.idea/**/tasks.xml
|
||||
/.idea/**/usage.statistics.xml
|
||||
/.idea/**/dictionaries
|
||||
/.idea/**/shelf
|
||||
/.idea/**/contentModel.xml
|
||||
/.idea/**/dataSources/
|
||||
/.idea/**/dataSources.ids
|
||||
/.idea/**/dataSources.local.xml
|
||||
/.idea/**/sqlDataSources.xml
|
||||
/.idea/**/dynamic.xml
|
||||
/.idea/**/uiDesigner.xml
|
||||
/.idea/**/dbnavigator.xml
|
||||
/.phpunit.result.cache
|
||||
|
||||
.~lock*#
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
<path value="$PROJECT_DIR$/vendor/psr/http-message" />
|
||||
<path value="$PROJECT_DIR$/vendor/maennchen/zipstream-php" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
|
||||
<path value="$PROJECT_DIR$/vendor/lib/spout" />
|
||||
</include_path>
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.4" />
|
||||
|
|
|
@ -11,6 +11,12 @@
|
|||
<PhpSpecSuiteConfiguration>
|
||||
<option name="myPath" value="$PROJECT_DIR$" />
|
||||
</PhpSpecSuiteConfiguration>
|
||||
<PhpSpecSuiteConfiguration>
|
||||
<option name="myPath" value="$PROJECT_DIR$" />
|
||||
</PhpSpecSuiteConfiguration>
|
||||
<PhpSpecSuiteConfiguration>
|
||||
<option name="myPath" value="$PROJECT_DIR$" />
|
||||
</PhpSpecSuiteConfiguration>
|
||||
</suites>
|
||||
</component>
|
||||
</project>
|
|
@ -3,6 +3,10 @@
|
|||
"type": "library",
|
||||
"description": "espace de maturation pour les librairies",
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "../lib-spout"
|
||||
},
|
||||
{
|
||||
"type": "composer",
|
||||
"url": "https://repos.univ-reunion.fr/composer"
|
||||
|
@ -14,6 +18,7 @@
|
|||
},
|
||||
"require-dev": {
|
||||
"nulib/tests": "7.4",
|
||||
"lib/spout": "dev-master",
|
||||
"phpoffice/phpspreadsheet": "^1.0",
|
||||
"ext-posix": "*",
|
||||
"ext-pcntl": "*",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "c951b0cf9bd2f2bab34a46242331eb88",
|
||||
"content-hash": "35dddc6d357654919ddf2728176ac22f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "symfony/deprecation-contracts",
|
||||
|
@ -360,6 +360,83 @@
|
|||
},
|
||||
"time": "2023-11-17T15:01:25+00:00"
|
||||
},
|
||||
{
|
||||
"name": "lib/spout",
|
||||
"version": "dev-master",
|
||||
"dist": {
|
||||
"type": "path",
|
||||
"url": "../lib-spout",
|
||||
"reference": "0fd23b5cd9312c9236e435687f2dbdf2d63c8d83"
|
||||
},
|
||||
"require": {
|
||||
"ext-dom": "*",
|
||||
"ext-filter": "*",
|
||||
"ext-libxml": "*",
|
||||
"ext-xmlreader": "*",
|
||||
"ext-zip": "*",
|
||||
"php": "~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0"
|
||||
},
|
||||
"replace": {
|
||||
"openspout/openspout": "v3.7.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-zlib": "*",
|
||||
"friendsofphp/php-cs-fixer": "^3.4",
|
||||
"phpstan/phpstan": "^1.4",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
"phpunit/phpunit": "^9.5"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-iconv": "To handle non UTF-8 CSV files (if \"php-intl\" is not already installed or is too limited)",
|
||||
"ext-intl": "To handle non UTF-8 CSV files (if \"iconv\" is not already installed)"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"OpenSpout\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"classmap": [
|
||||
"tests/"
|
||||
]
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jephte Clain",
|
||||
"email": "Jephte.Clain@univ-reunion.fr"
|
||||
},
|
||||
{
|
||||
"name": "Adrien Loison",
|
||||
"email": "adrien@box.com"
|
||||
}
|
||||
],
|
||||
"description": "PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way",
|
||||
"homepage": "https://github.com/openspout/openspout",
|
||||
"keywords": [
|
||||
"csv",
|
||||
"excel",
|
||||
"memory",
|
||||
"odf",
|
||||
"ods",
|
||||
"office",
|
||||
"ooxml",
|
||||
"open",
|
||||
"php",
|
||||
"read",
|
||||
"scale",
|
||||
"spreadsheet",
|
||||
"stream",
|
||||
"write",
|
||||
"xlsx"
|
||||
],
|
||||
"transport-options": {
|
||||
"relative": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "maennchen/zipstream-php",
|
||||
"version": "2.2.6",
|
||||
|
@ -2710,7 +2787,9 @@
|
|||
],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"stability-flags": {
|
||||
"lib/spout": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
|
|
|
@ -10,7 +10,6 @@ use PhpOffice\PhpSpreadsheet\Cell\StringValueBinder;
|
|||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Ods;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xls;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
/**
|
||||
|
@ -92,9 +91,6 @@ class SsBuilder extends AbstractBuilder {
|
|||
case ".ods":
|
||||
$contentType = "application/vnd.oasis.opendocument.spreadsheet";
|
||||
break;
|
||||
case ".xls":
|
||||
$contentType = "application/vnd.ms-excel";
|
||||
break;
|
||||
case ".xlsx":
|
||||
default:
|
||||
$contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
|
@ -108,9 +104,6 @@ class SsBuilder extends AbstractBuilder {
|
|||
case ".ods":
|
||||
$writer = new Ods($this->ss);
|
||||
break;
|
||||
case ".xls":
|
||||
$writer = new Xls($this->ss);
|
||||
break;
|
||||
case ".xlsx":
|
||||
default:
|
||||
$writer = new Xlsx($this->ss);
|
||||
|
|
|
@ -165,7 +165,7 @@ class Stream extends AbstractIterator implements IReader, IWriter {
|
|||
/** @var array paramètres pour la lecture et l'écriture de flux au format CSV */
|
||||
protected $csvFlavour;
|
||||
|
||||
function setCsvFlavour(string $flavour): void {
|
||||
function setCsvFlavour(?string $flavour): void {
|
||||
$this->csvFlavour = csv_flavours::verifix($flavour);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use nur\sery\php\func;
|
|||
use nur\sery\php\time\DateTime;
|
||||
use nur\sery\web\http;
|
||||
|
||||
abstract class AbstractBuilder extends TempStream {
|
||||
abstract class AbstractBuilder extends TempStream implements IBuilder {
|
||||
/** @var ?array schéma des données à écrire */
|
||||
const SCHEMA = null;
|
||||
|
||||
|
|
|
@ -6,8 +6,16 @@ use nur\sery\file\FileReader;
|
|||
class CsvReader extends AbstractReader {
|
||||
use TAbstractReader;
|
||||
|
||||
function __construct($input, ?array $params=null) {
|
||||
parent::__construct($input, $params);
|
||||
$this->csvFlavour = $params["csv_flavour"] ?? null;
|
||||
}
|
||||
|
||||
protected ?string $csvFlavour;
|
||||
|
||||
function getIterator() {
|
||||
$reader = new FileReader($this->input);
|
||||
$reader->setCsvFlavour($this->csvFlavour);
|
||||
while (($row = $reader->fgetcsv()) !== null) {
|
||||
foreach ($row as &$col) {
|
||||
$this->verifixCol($col);
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
namespace nur\sery\file\csv;
|
||||
|
||||
interface IBuilder {
|
||||
function writeHeaders(?array $headers=null): void;
|
||||
|
||||
function write(?array $row): void;
|
||||
|
||||
function writeAll(?iterable $rows=null): void;
|
||||
|
||||
function sendHeaders(): void;
|
||||
|
||||
function sendFile(?iterable $rows=null): int;
|
||||
}
|
|
@ -7,7 +7,7 @@ use nur\sery\ValueException;
|
|||
|
||||
trait TAbstractBuilder {
|
||||
/** @param Upload|string|array $builder */
|
||||
static function with($builder): self {
|
||||
static function with($builder): IBuilder {
|
||||
if ($builder instanceof self) return $builder;
|
||||
$class = null;
|
||||
if ($builder instanceof Upload) {
|
||||
|
|
|
@ -1,29 +1,35 @@
|
|||
<?php
|
||||
namespace nur\sery\file\csv;
|
||||
|
||||
use nur\sery\cl;
|
||||
use nur\sery\file\web\Upload;
|
||||
use nur\sery\os\path;
|
||||
use nur\sery\ValueException;
|
||||
|
||||
trait TAbstractReader {
|
||||
/** @param Upload|string|array $reader */
|
||||
static function with($reader): self {
|
||||
static function with($reader, ?array $params=null): IReader {
|
||||
if ($reader instanceof self) return $reader;
|
||||
$class = null;
|
||||
if ($reader instanceof Upload) {
|
||||
if ($reader->isExt(".csv")) $class = CsvReader::class;
|
||||
else $class = static::class;
|
||||
return new $class($reader->tmpName);
|
||||
return new $class($reader->tmpName, $params);
|
||||
}
|
||||
if (is_string($reader)) $reader = ["input" => $reader];
|
||||
if (!is_array($reader)) {
|
||||
|
||||
if (is_string($reader)) {
|
||||
$params["input"] = $reader;
|
||||
} elseif (is_array($reader)) {
|
||||
$params = cl::merge($reader, $params);
|
||||
} elseif ($reader !== null) {
|
||||
throw ValueException::invalid_type($reader, self::class);
|
||||
}
|
||||
$input = $reader["input"] ?? null;
|
||||
|
||||
$input = $params["input"] ?? null;
|
||||
if (is_string($input) && path::ext($input) === ".csv") {
|
||||
$class = CsvReader::class;
|
||||
}
|
||||
if ($class === null) $class = static::class;
|
||||
return new $class(null, $reader);
|
||||
return new $class(null, $params);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue