Skip to content

Commit c52bec6

Browse files
authored
Merge pull request #12 from mohammedjammeh/feature/upgrade-to-laravel-6
This package and its dependencies has been upgraded to use laravel 6.
2 parents d9f8d70 + 7b74781 commit c52bec6

File tree

12 files changed

+101
-54
lines changed

12 files changed

+101
-54
lines changed

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=5.4.0",
16-
"box/spout": "^2.4",
17-
"illuminate/database": "4.*|5.*",
18-
"illuminate/support": "4.*|5.*"
15+
"php": "^7.2.5",
16+
"box/spout": "^3.1",
17+
"illuminate/database": "^6.0.0",
18+
"illuminate/support": "^6.0.0"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "~4.0",
22-
"phpspec/phpspec": "~2.1",
23-
"laravel/laravel": "~5.3"
21+
"phpunit/phpunit": "^7.0",
22+
"phpspec/phpspec": "^6.1.1",
23+
"laravel/laravel": "^6.0.0"
2424
},
2525
"autoload": {
2626
"psr-4": {

phpunit.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
>
12+
<php>
13+
<ini name="display_errors" value="On" />
14+
<ini name="display_startup_errors" value="On" />
15+
</php>
1316
<testsuites>
1417
<testsuite name="Package Test Suite">
1518
<directory suffix=".php">./tests/</directory>

src/Exporter/AbstractSpreadsheet.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace Cyberduck\LaravelExcel\Exporter;
33

44
use Illuminate\Support\Collection;
5-
use Box\Spout\Writer\WriterFactory;
5+
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
66
use Illuminate\Database\Query\Builder;
77
use Cyberduck\LaravelExcel\Serialiser\BasicSerialiser;
88
use Cyberduck\LaravelExcel\Contract\SerialiserInterface;
@@ -56,6 +56,8 @@ public function setSerialiser(SerialiserInterface $serialiser)
5656

5757
abstract public function getType();
5858

59+
abstract public function createWriter();
60+
5961
public function save($filename)
6062
{
6163
$writer = $this->create();
@@ -74,7 +76,7 @@ public function stream($filename)
7476

7577
protected function create()
7678
{
77-
$writer = WriterFactory::create($this->type);
79+
$writer = $this->createWriter();
7880
$this->callbacks->each(function ($elem) use (&$writer) {
7981
call_user_func_array(array($writer, $elem[0]), $elem[1]);
8082
});
@@ -85,22 +87,27 @@ protected function makeRows($writer)
8587
{
8688
$headerRow = $this->serialiser->getHeaderRow();
8789
if (!empty($headerRow)) {
88-
$writer->addRow($headerRow);
90+
$row = WriterEntityFactory::createRowFromArray($headerRow);
91+
$writer->addRow($row);
8992
}
9093
if ($this->data instanceof Builder) {
9194
if (isset($this->chuncksize)) {
9295
$this->data->chunk($this->chuncksize);
9396
} else {
94-
$data = $this->data->get();
95-
foreach ($data as $record) {
96-
$writer->addRow($this->serialiser->getData($record));
97-
}
97+
$this->addRowsDataToWriter($this->data->get(), $writer);
9898
}
9999
} else {
100-
foreach ($this->data as $record) {
101-
$writer->addRow($this->serialiser->getData($record));
102-
}
100+
$this->addRowsDataToWriter($this->data, $writer);
103101
}
104102
return $writer;
105103
}
104+
105+
public function addRowsDataToWriter($data, $writer)
106+
{
107+
foreach ($data as $record) {
108+
$recordData = $this->serialiser->getData($record);
109+
$row = WriterEntityFactory::createRowFromArray($recordData);
110+
$writer->addRow($row);
111+
}
112+
}
106113
}

src/Exporter/Csv.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
namespace Cyberduck\LaravelExcel\Exporter;
33

44
use Box\Spout\Common\Type;
5+
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
56

67
class Csv extends AbstractSpreadsheet
78
{
89
public function getType()
910
{
1011
return Type::CSV;
1112
}
13+
14+
public function createWriter()
15+
{
16+
return WriterEntityFactory::createCSVWriter();
17+
}
1218
}

src/Exporter/Excel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
namespace Cyberduck\LaravelExcel\Exporter;
33

44
use Box\Spout\Common\Type;
5+
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
56

67
class Excel extends AbstractSpreadsheet
78
{
89
public function getType()
910
{
1011
return Type::XLSX;
1112
}
13+
14+
public function createWriter()
15+
{
16+
return WriterEntityFactory::createXLSXWriter();
17+
}
1218
}

src/Exporter/OpenOffice.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
namespace Cyberduck\LaravelExcel\Exporter;
33

44
use Box\Spout\Common\Type;
5+
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
56

67
class OpenOffice extends AbstractSpreadsheet
78
{
89
public function getType()
910
{
1011
return Type::ODS;
1112
}
13+
14+
public function createWriter()
15+
{
16+
return WriterEntityFactory::createODSWriter();
17+
}
1218
}

src/Importer/AbstractSpreadsheet.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
namespace Cyberduck\LaravelExcel\Importer;
33

4-
use Box\Spout\Reader\ReaderFactory;
54
use Illuminate\Database\Eloquent\Model;
65
use Cyberduck\LaravelExcel\Parser\BasicParser;
76
use Cyberduck\LaravelExcel\Contract\ParserInterface;
@@ -65,6 +64,8 @@ public function setModel(Model $model)
6564

6665
abstract public function getType();
6766

67+
abstract public function createReader();
68+
6869
public function getCollection()
6970
{
7071
$headers = false;
@@ -80,9 +81,9 @@ public function getCollection()
8081

8182
foreach ($sheet->getRowIterator() as $rowindex => $row) {
8283
if ($rowindex == 1 && $this->hasHeaderRow) {
83-
$headers = $row;
84+
$headers = $row->toArray();
8485
} else {
85-
$data = $this->parser->transform($row, $headers);
86+
$data = $this->parser->transform($row->toArray(), $headers);
8687

8788
if ($data !== false) {
8889
if ($this->model) {
@@ -119,9 +120,9 @@ public function save($updateIfEquals = [])
119120

120121
foreach ($sheet->getRowIterator() as $rowindex => $row) {
121122
if ($rowindex == 1 && $this->hasHeaderRow) {
122-
$headers = $row;
123+
$headers = $row->toArray();
123124
} else {
124-
$data = $this->parser->transform($row, $headers);
125+
$data = $this->parser->transform($row->toArray(), $headers);
125126
if ($data !== false) {
126127
$relationships = [];
127128
$when = array_intersect_key($data, $updateIfEquals);
@@ -160,7 +161,7 @@ public function save($updateIfEquals = [])
160161

161162
protected function open()
162163
{
163-
$reader= ReaderFactory::create($this->type);
164+
$reader = $this->createReader();
164165
$reader->open($this->path);
165166
$this->callbacks->each(function ($elem) use (&$writer) {
166167
call_user_func_array(array($writer, $elem[0]), $elem[1]);

src/Importer/Csv.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
namespace Cyberduck\LaravelExcel\Importer;
33

44
use Box\Spout\Common\Type;
5+
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
56

67
class Csv extends AbstractSpreadsheet
78
{
89
public function getType()
910
{
1011
return Type::CSV;
1112
}
13+
14+
public function createReader()
15+
{
16+
return ReaderEntityFactory::createCSVReader();
17+
}
1218
}

src/Importer/Excel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
namespace Cyberduck\LaravelExcel\Importer;
33

44
use Box\Spout\Common\Type;
5+
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
56

67
class Excel extends AbstractSpreadsheet
78
{
89
public function getType()
910
{
1011
return Type::XLSX;
1112
}
13+
14+
public function createReader()
15+
{
16+
return ReaderEntityFactory::createXLSXReader();
17+
}
1218
}

src/Importer/OpenOffice.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
namespace Cyberduck\LaravelExcel\Importer;
33

44
use Box\Spout\Common\Type;
5+
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
56

67
class OpenOffice extends AbstractSpreadsheet
78
{
89
public function getType()
910
{
1011
return Type::ODS;
1112
}
13+
14+
public function createReader()
15+
{
16+
return ReaderEntityFactory::createODSReader();
17+
}
1218
}

0 commit comments

Comments
 (0)