Skip to content

Commit

Permalink
Merge pull request #7 from ARCANEDEV/update-laravel_5.5_support
Browse files Browse the repository at this point in the history
Adding laravel 5.5 support
  • Loading branch information
arcanedev-maroc committed Feb 16, 2018
2 parents 56bd525 + fa6792e commit cf94f23
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 42 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ language: php
sudo: false

php:
- 5.6
- 7.0
- 7.1
- 7.2
- nightly

matrix:
allow_failures:
- php: 7.2
- php: nightly

before_script:
Expand All @@ -24,5 +22,5 @@ script:
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- if [ "$TRAVIS_PHP_VERSION" != "7.2" ] && [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "7.2" ] && [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ This package allows you to export a array/Laravel Collection as an excel/csv fil
* Easy setup & configuration.
* Well documented & IDE Friendly.
* Well tested with maximum code quality.
* Laravel `5.1 | 5.2 | 5.3 | 5.4` are supported.
* Laravel `5.1 | 5.2 | 5.3 | 5.4 | 5.5` are supported.
* Made with :heart: & :coffee:.

## Table of contents

1. [Requirements](_docs/1.Requirements.md)
2. [Installation and Setup](_docs/2.Installation-and-Setup.md)
3. [Configuration](_docs/3.Configuration.md)
4. [Usage](_docs/4.Usage.md)
1. [Installation and Setup](_docs/1-Installation-and-Setup.md)
2. [Configuration](_docs/2-Configuration.md)
3. [Usage](_docs/3-Usage.md)

## TODOS

Expand All @@ -48,7 +47,7 @@ If you discover any security related issues, please email arcanedev.maroc@gmail.
- [ARCANEDEV][link-author]
- [All Contributors][link-contributors]

[badge_laravel]: https://img.shields.io/badge/For%20Laravel-5.1%20to%205.4-orange.svg?style=flat-square
[badge_laravel]: https://img.shields.io/badge/For%20Laravel-5.1%20to%205.5-orange.svg?style=flat-square
[badge_license]: https://img.shields.io/packagist/l/arcanedev/laravel-excel.svg?style=flat-square
[badge_build]: https://img.shields.io/travis/ARCANEDEV/LaravelExcel.svg?style=flat-square
[badge_coverage]: https://img.shields.io/scrutinizer/coverage/g/ARCANEDEV/LaravelExcel.svg?style=flat-square
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file removed _docs/4.Usage.md
Empty file.
22 changes: 17 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
}
],
"require": {
"php": ">=5.6",
"php": ">=7.0",
"box/spout": "~2.7",
"arcanedev/support": "~4.1.0"
"arcanedev/support": "~4.2.0"
},
"require-dev": {
"orchestra/testbench": "~3.4.0",
"phpunit/phpcov": "~3.0",
"phpunit/phpunit": "~5.0"
"orchestra/testbench": "~3.5.0",
"phpunit/phpcov": "~4.0",
"phpunit/phpunit": "~6.0"
},
"autoload": {
"psr-4": {
Expand All @@ -33,5 +33,17 @@
"psr-4": {
"Arcanedev\\LaravelExcel\\Tests\\": "tests/"
}
},
"config": {
"platform": {
"php": "7.0.0"
}
},
"extra": {
"laravel": {
"providers": [
"Arcanedev\\LaravelExcel\\LaravelExcelServiceProvider"
]
}
}
}
10 changes: 8 additions & 2 deletions config/excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

'drivers' => [
'excel' => [
'importer' => Arcanedev\LaravelExcel\Importers\ExcelImporter::class,
'exporter' => Arcanedev\LaravelExcel\Exporters\ExcelExporter::class,
'options' => [
'format-dates' => false,
'preserve-empty-rows' => false,
],
],

'csv' => [
'options' => [
'importer' => Arcanedev\LaravelExcel\Importers\CsvImporter::class,
'exporter' => Arcanedev\LaravelExcel\Exporters\CsvExporter::class,
'options' => [
'field-delimiter' => ',',
'field-enclosure' => '"',
'encoding' => 'UTF-8',
Expand All @@ -33,7 +37,9 @@
],

'ods' => [
'options' => [
'importer' => Arcanedev\LaravelExcel\Importers\OpenOfficeImporter::class,
'exporter' => Arcanedev\LaravelExcel\Exporters\OpenOfficeExporter::class,
'options' => [
'format-dates' => false,
'preserve-empty-rows' => false,
],
Expand Down
38 changes: 36 additions & 2 deletions src/AbstractManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,55 @@ abstract class AbstractManager extends Manager
| -----------------------------------------------------------------
*/

/**
* Get the config repository.
*
* @return \Illuminate\Contracts\Config\Repository
*/
protected function config()
{
return $this->app['config'];
}

/**
* Get the default driver name.
*
* @return string
*/
public function getDefaultDriver()
{
return $this->app['config']->get('excel.default');
return $this->config()->get('excel.default');
}

/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
*/

/**
* Get the driver's exporter class.
*
* @param string $driver
*
* @return string
*/
protected function getDriverExporter($driver)
{
return $this->config()->get("excel.drivers.$driver.exporter");
}

/**
* Get the driver's importer class.
*
* @param string $driver
*
* @return string
*/
protected function getDriverImporter($driver)
{
return $this->config()->get("excel.drivers.$driver.importer");
}

/**
* Get the driver options.
*
Expand All @@ -39,6 +73,6 @@ public function getDefaultDriver()
*/
protected function getDriverOptions($driver)
{
return $this->app['config']->get("excel.drivers.$driver.options", []);
return $this->config()->get("excel.drivers.$driver.options", []);
}
}
30 changes: 22 additions & 8 deletions src/ExporterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public function make($driver)
*/
public function createExcelDriver()
{
return new Exporters\ExcelExporter(
$this->getDriverOptions('excel')
);
return $this->buildExporter('excel');
}

/**
Expand All @@ -46,9 +44,7 @@ public function createExcelDriver()
*/
public function createCsvDriver()
{
return new Exporters\CsvExporter(
$this->getDriverOptions('csv')
);
return $this->buildExporter('csv');
}

/**
Expand All @@ -58,8 +54,26 @@ public function createCsvDriver()
*/
public function createOpenOfficeDriver()
{
return new Exporters\OpenOfficeExporter(
$this->getDriverOptions('ods')
return $this->buildExporter('ods');
}

/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
*/

/**
* Build the exporter.
*
* @param string $driver
*
* @return \Arcanedev\LaravelExcel\Contracts\Exporter
*/
protected function buildExporter($driver)
{
return $this->app->makeWith(
$this->getDriverExporter($driver),
$this->getDriverOptions($driver)
);
}
}
2 changes: 1 addition & 1 deletion src/Exporters/ExcelExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExcelExporter extends AbstractExporter
protected $type = Type::XLSX;

/* -----------------------------------------------------------------
| Other Methods
| Other Met
| -----------------------------------------------------------------
*/

Expand Down
36 changes: 25 additions & 11 deletions src/ImporterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,50 @@ public function make($driver)
/**
* Get the Excel driver instance.
*
* @return \Arcanedev\LaravelExcel\Importers\ExcelImporter
* @return \Arcanedev\LaravelExcel\Contracts\Importer
*/
public function createExcelDriver()
{
return new Importers\ExcelImporter(
$this->getDriverOptions('excel')
);
return $this->buildImporter('excel');
}

/**
* Get the CSV driver instance.
*
* @return \Arcanedev\LaravelExcel\Importers\CsvImporter
* @return \Arcanedev\LaravelExcel\Contracts\Importer
*/
public function createCsvDriver()
{
return new Importers\CsvImporter(
$this->getDriverOptions('csv')
);
return $this->buildImporter('csv');
}

/**
* Get the Open office driver instance.
*
* @return \Arcanedev\LaravelExcel\Importers\OpenOfficeImporter
* @return \Arcanedev\LaravelExcel\Contracts\Importer
*/
public function createOpenOfficeDriver()
{
return new Importers\OpenOfficeImporter(
$this->getDriverOptions('ods')
return $this->buildImporter('ods');
}

/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
*/

/**
* Build the importer.
*
* @param string $driver
*
* @return \Arcanedev\LaravelExcel\Contracts\Importer
*/
protected function buildImporter($driver)
{
return $this->app->makeWith(
$this->getDriverImporter($driver),
$this->getDriverOptions($driver)
);
}
}
7 changes: 4 additions & 3 deletions tests/Exporters/ExcelExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Arcanedev\LaravelExcel\Importers\ExcelImporter;
use Arcanedev\LaravelExcel\Tests\TestCase;
use Box\Spout\Common\Type;
use Illuminate\Support\Collection;

/**
* Class ExcelExporterTest
Expand Down Expand Up @@ -72,13 +73,13 @@ public function it_can_save()
['s1 - A5', 's1 - B5', 's1 - C5', 's1 - D5', 's1 - E5'],
];

$data = collect($expected)->transform(function ($row) {
return collect($row);
$data = Collection::make($expected)->transform(function ($row) {
return new Collection($row);
});

$this->exporter->load($data);
$this->exporter->save(
$path = $this->getExportsFolder() . '/xlsx/one_sheet_with_inline_strings.xlsx'
$path = $this->getExportsFolder().'/xlsx/one_sheet_with_inline_strings.xlsx'
);

$sheets = $this->getAllRowsFromFile('xlsx/one_sheet_with_inline_strings.xlsx');
Expand Down

0 comments on commit cf94f23

Please sign in to comment.