Skip to content

Commit

Permalink
Composer: remove box/spout, require openspout/openspout, update p…
Browse files Browse the repository at this point in the history
…hp version

Add OpenSpout3 library
Run test workflow: do not exclude `prefer-lowest` on `php 8.0`, add `php 8.1`
Add upgrade guide to `README.md`
  • Loading branch information
fab120 committed Oct 11, 2022
1 parent 4065041 commit 9fbcb7d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 131 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.0, 7.4]
php: [8.1, 8.0, 7.4]
stability: [prefer-lowest, prefer-stable]
exclude:
- php: 8.0
stability: prefer-lowest

name: P${{ matrix.php }} - ${{ matrix.stability }}

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
All notable changes to `excel-reader` will be documented in this file.

## v2.0.0 - 2022-10-11
- Composer: remove `box/spout`, require `openspout/openspout`, update php version
- Add OpenSpout3 library
- Run test workflow: do not exclude `prefer-lowest` on `php 8.0`, add `php 8.1`
- Add upgrade guide to `README.md`

## v1.3.0 - 2021-10-22
- Add `skip` method to define how many rows should be skipped
- Add `preserveEmptyRows` method to define if empty rows should be preserved or not (compatible only with box/spout:^3.0)
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ $excel = \Webnuvola\ExcelReader\ExcelReader::createFromString($content, 'xlsx')
composer test
```

## Upgrade Guide

### From `v1` to `v2`
Library `box/spout` is replaced with `openspout/openspout`, there are no breaking changes.

## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Expand Down
16 changes: 5 additions & 11 deletions src/ExcelReaderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace Webnuvola\ExcelReader;

use Box\Spout\Reader\Common\Creator\ReaderFactory as BoxSpout3ReaderFactory;
use Box\Spout\Reader\ReaderFactory as BoxSpout2ReaderFactory;
use OpenSpout\Reader\Common\Creator\ReaderFactory as OpenSpout3ReaderFactory;
use Webnuvola\ExcelReader\Exceptions\LibraryNotFoundException;
use Webnuvola\ExcelReader\Libraries\BoxSpout2Library;
use Webnuvola\ExcelReader\Libraries\BoxSpout3Library;
use Webnuvola\ExcelReader\Libraries\OpenSpout3Library;
use Webnuvola\ExcelReader\Libraries\LibraryInterface;

class ExcelReaderManager
Expand All @@ -20,14 +18,10 @@ class ExcelReaderManager
*/
public static function resolve(): LibraryInterface
{
if (class_exists(BoxSpout3ReaderFactory::class)) {
return new BoxSpout3Library();
if (class_exists(OpenSpout3ReaderFactory::class)) {
return new OpenSpout3Library();
}

if (class_exists(BoxSpout2ReaderFactory::class)) {
return new BoxSpout2Library();
}

throw new LibraryNotFoundException('Libray box/spout not found');
throw new LibraryNotFoundException('Libray openspout/openspout not found');
}
}
102 changes: 0 additions & 102 deletions src/Libraries/BoxSpout2Library.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Webnuvola\ExcelReader\Libraries;

use Box\Spout\Common\Entity\Cell;
use Box\Spout\Reader\Common\Creator\ReaderFactory;
use OpenSpout\Common\Entity\Cell;
use OpenSpout\Reader\Common\Creator\ReaderFactory;
use Cocur\Slugify\Slugify;

class BoxSpout3Library extends Library implements LibraryInterface
class OpenSpout3Library extends Library implements LibraryInterface
{
/**
* Read the file and return data from selected sheet.
Expand All @@ -16,9 +16,9 @@ class BoxSpout3Library extends Library implements LibraryInterface
* @param int|string $sheetId
* @return array
*
* @throws \Box\Spout\Common\Exception\IOException
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException
* @throws \OpenSpout\Common\Exception\IOException
* @throws \OpenSpout\Common\Exception\UnsupportedTypeException
* @throws \OpenSpout\Reader\Exception\ReaderNotOpenedException
*/
public function read(string $path, bool $hasHeaders, $sheetId): array
{
Expand All @@ -42,7 +42,7 @@ public function read(string $path, bool $hasHeaders, $sheetId): array
continue;
}

/** @var \Box\Spout\Common\Entity\Row $row */
/** @var \OpenSpout\Common\Entity\Row $row */
foreach ($sheet->getRowIterator() as $row) {
if ($skipped < $this->skip) {
$skipped++;
Expand Down
9 changes: 3 additions & 6 deletions tests/Unit/ExcelReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
use Exception;
use Webnuvola\ExcelReader\ExcelReader;
use Webnuvola\ExcelReader\ExcelReaderManager;
use Webnuvola\ExcelReader\Libraries\BoxSpout2Library;
use Webnuvola\ExcelReader\Libraries\BoxSpout3Library;
use Webnuvola\ExcelReader\Libraries\OpenSpout3Library;
use Webnuvola\ExcelReader\Tests\TestCase;

class ExcelReaderTest extends TestCase
Expand All @@ -20,10 +19,8 @@ public function library()
{
$library = ExcelReaderManager::resolve();

if ($library instanceof BoxSpout3Library) {
$this->setName('Library box/spout:^3.0');
} elseif ($library instanceof BoxSpout2Library) {
$this->setName('Library box/spout:^2.7');
if ($library instanceof OpenSpout3Library) {
$this->setName('Library openspout/openspout:^3.4');
} else {
$this->setName('Library not found');
$this->markTestIncomplete('Library not found');
Expand Down

0 comments on commit 9fbcb7d

Please sign in to comment.