Skip to content

Commit c33815a

Browse files
authored
Merge pull request #48 from yajra/laravel10
feat: support laravel 10
2 parents 8073cd2 + 9ad3887 commit c33815a

File tree

6 files changed

+50
-56
lines changed

6 files changed

+50
-56
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: true
1616
matrix:
17-
php: [7.4, 8.0, 8.1]
17+
php: [8.1, 8.2]
1818
stability: [prefer-stable]
1919

2020
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
@@ -42,4 +42,4 @@ jobs:
4242
command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
4343

4444
- name: Execute tests
45-
run: vendor/bin/phpunit --verbose
45+
run: vendor/bin/phpunit

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ jobs:
5151
command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
5252

5353
- name: "Run a static analysis with phpstan/phpstan"
54-
run: "vendor/bin/phpstan --error-format=checkstyle"
54+
run: "vendor/bin/phpstan --error-format=github"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/coverage
33
composer.phar
44
composer.lock
5+
/.phpunit.cache

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=7.4|8.*",
21-
"yajra/laravel-datatables-buttons": "4.*|9.*",
22-
"livewire/livewire": "2.*|3.*",
23-
"openspout/openspout": "^3",
24-
"ext-json": "*"
20+
"php": "^8.1",
21+
"ext-json": "*",
22+
"livewire/livewire": "^2.11.2",
23+
"openspout/openspout": "^4.12.1",
24+
"phpoffice/phpspreadsheet": "^1.27",
25+
"yajra/laravel-datatables": "^10.0"
2526
},
2627
"require-dev": {
27-
"maatwebsite/excel": "^3.1.40",
28-
"nunomaduro/larastan": "^1.0|^2.2",
29-
"orchestra/testbench": "6.*|^7.3"
28+
"nunomaduro/larastan": "^2.4.1",
29+
"orchestra/testbench": "^8.0.1"
3030
},
3131
"autoload": {
3232
"psr-4": {
@@ -45,7 +45,7 @@
4545
},
4646
"extra": {
4747
"branch-alias": {
48-
"dev-master": "1.0-dev"
48+
"dev-master": "10.0-dev"
4949
},
5050
"laravel": {
5151
"providers": [

phpunit.xml.dist

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
>
12-
<testsuites>
13-
<testsuite name="Package Test Suite">
14-
<directory suffix=".php">./tests/</directory>
15-
<exclude>./tests/views/</exclude>
16-
</testsuite>
17-
</testsuites>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="Package Test Suite">
5+
<directory suffix="Test.php">./tests/</directory>
6+
</testsuite>
7+
</testsuites>
188
</phpunit>

src/Jobs/DataTableExportJob.php

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Yajra\DataTables\Jobs;
44

55
use Carbon\Carbon;
6+
use DateTimeInterface;
67
use Illuminate\Auth\Events\Login;
78
use Illuminate\Bus\Batchable;
89
use Illuminate\Bus\Queueable;
@@ -20,12 +21,12 @@
2021
use Illuminate\Support\Facades\Mail;
2122
use Illuminate\Support\Facades\Storage;
2223
use Illuminate\Support\Str;
23-
use OpenSpout\Common\Helper\CellTypeHelper;
24-
use OpenSpout\Common\Type;
25-
use OpenSpout\Writer\Common\Creator\Style\StyleBuilder;
26-
use OpenSpout\Writer\Common\Creator\WriterEntityFactory;
24+
use OpenSpout\Common\Entity\Cell;
25+
use OpenSpout\Common\Entity\Row;
26+
use OpenSpout\Common\Entity\Style\Style;
27+
use OpenSpout\Writer\Common\Creator\WriterFactory;
28+
use OpenSpout\Writer\XLSX\Helper\DateHelper;
2729
use OpenSpout\Writer\XLSX\Writer as XLSXWriter;
28-
use PhpOffice\PhpSpreadsheet\Shared\Date;
2930
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
3031
use Yajra\DataTables\Html\Column;
3132
use Yajra\DataTables\Services\DataTable;
@@ -95,14 +96,14 @@ public function handle()
9596
$dataTable = app()->call([$oTable, 'dataTable'], compact('query'));
9697
$dataTable->skipPaging();
9798

98-
$exportType = strval(request('exportType'));
99+
$exportType = strtolower(strval(request('exportType')));
99100

100-
$type = Str::startsWith($exportType, Type::CSV) ? Type::CSV : Type::XLSX;
101+
$type = Str::startsWith($exportType, 'csv') ? 'csv' : 'xlsx';
101102
$filename = $this->batchId.'.'.$type;
102103

103104
$path = Storage::disk($this->getDisk())->path($filename);
104105

105-
$writer = WriterEntityFactory::createWriter($type);
106+
$writer = WriterFactory::createFromFile($filename);
106107
$writer->openToFile($path);
107108

108109
if ($writer instanceof XLSXWriter) {
@@ -112,11 +113,13 @@ public function handle()
112113
}
113114

114115
$columns = $this->getExportableColumns($oTable);
115-
$writer->addRow(
116-
WriterEntityFactory::createRowFromArray(
117-
$columns->map(fn (Column $column) => strip_tags($column->title))->toArray()
118-
)
119-
);
116+
$headers = [];
117+
118+
$columns->each(function (Column $column) use (&$headers) {
119+
$headers[] = strip_tags($column->title);
120+
});
121+
122+
$writer->addRow(Row::fromValues($headers));
120123

121124
if ($this->usesLazyMethod()) {
122125
$chunkSize = intval(config('datatables-export.chunk', 1000));
@@ -144,7 +147,7 @@ public function handle()
144147
$property = $property['_'] ?? $column->name;
145148
}
146149

147-
/** @var array|bool|int|string|null $value */
150+
/** @var array|bool|int|string|null|DateTimeInterface $value */
148151
$value = $row[$property] ?? '';
149152

150153
if (is_array($value)) {
@@ -157,14 +160,14 @@ public function handle()
157160
$format = $column->exportFormat ?? '@';
158161
break;
159162
case $this->wantsDateFormat($column):
160-
$cellValue = $value ? Date::dateTimeToExcel(Carbon::parse(strval($value))) : '';
163+
$cellValue = $value ? DateHelper::toExcel(Carbon::parse(strval($value))) : '';
161164
$format = $column->exportFormat ?? $defaultDateFormat;
162165
break;
163166
case $this->wantsNumeric($column):
164167
$cellValue = floatval($value);
165168
$format = $column->exportFormat;
166169
break;
167-
case CellTypeHelper::isDateTimeOrDateInterval($value):
170+
case $value instanceof DateTimeInterface:
168171
$cellValue = $value;
169172
$format = $column->exportFormat ?? $defaultDateFormat;
170173
break;
@@ -173,10 +176,10 @@ public function handle()
173176
$format = $column->exportFormat ?? NumberFormat::FORMAT_GENERAL;
174177
}
175178

176-
$cells[] = WriterEntityFactory::createCell($cellValue, (new StyleBuilder)->setFormat($format)->build());
179+
$cells[] = Cell::fromValue($cellValue, (new Style)->setFormat($format));
177180
});
178181

179-
$writer->addRow(WriterEntityFactory::createRow($cells));
182+
$writer->addRow(new Row($cells));
180183
}
181184

182185
$writer->close();
@@ -199,14 +202,6 @@ protected function getDisk(): string
199202
return strval(config('datatables-export.disk', 'local'));
200203
}
201204

202-
/**
203-
* @return string
204-
*/
205-
protected function getS3Disk(): string
206-
{
207-
return strval(config('datatables-export.s3_disk', ''));
208-
}
209-
210205
/**
211206
* @param \Yajra\DataTables\Services\DataTable $dataTable
212207
* @return \Illuminate\Support\Collection<array-key, Column>
@@ -279,15 +274,23 @@ protected function isNumeric($value): bool
279274
}
280275

281276
/**
282-
* @param array $data
277+
* @return string
278+
*/
279+
protected function getS3Disk(): string
280+
{
281+
return strval(config('datatables-export.s3_disk', ''));
282+
}
283+
284+
/**
285+
* @param array $data
283286
* @return void
284287
*/
285288
public function sendResults(array $data): void
286289
{
287290
Mail::send('datatables-export::export-email', $data, function ($message) use ($data) {
288291
$message->attach($data['path']);
289292
$message->to($data['email'])
290-
->subject('Export Report');
293+
->subject('Export Report');
291294
$message->from(config('datatables-export.mail_from'));
292295
});
293296
}

0 commit comments

Comments
 (0)