Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
[ci skip] [skip ci]
  • Loading branch information
patrickbrouwers committed Feb 26, 2019
1 parent 8db62fb commit d806052
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 128 deletions.
53 changes: 31 additions & 22 deletions config/excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,6 @@
use Maatwebsite\Excel\Excel;

return [
/*
|--------------------------------------------------------------------------
| Temporary path
|--------------------------------------------------------------------------
|
| When exporting files, we use a temporary file, before storing
| or downloading. Here you can customize that path.
|
*/
'temp_path' => storage_path('framework/laravel-excel'),

/*
|--------------------------------------------------------------------------
| Remote temporary disk
|--------------------------------------------------------------------------
|
| If not null, then temporary files for queued imports and exports will be stored
| at and retrieved from the specified filesystem disk, in addition to
| the configured temp_path on the local server.
|
*/
'remote_temp_disk' => null,

'exports' => [

Expand Down Expand Up @@ -138,4 +116,35 @@
*/
'pdf' => Excel::DOMPDF,
],

'temporary_files' => [

/*
|--------------------------------------------------------------------------
| Local Temporary Path
|--------------------------------------------------------------------------
|
| When exporting and importing files, we use a temporary file, before
| storing reading or downloading. Here you can customize that path.
|
*/
'local_path' => sys_get_temp_dir(),

/*
|--------------------------------------------------------------------------
| Remote Temporary Disk
|--------------------------------------------------------------------------
|
| When dealing with a multi server setup with queues in which you
| cannot rely on having a shared local temporary path, you might
| want to store the temporary file on a shared disk. During the
| queue executing, we'll retrieve the temporary file from that
| location instead. When left to null, it will always use
| the local path. This setting only has effect when using
| in conjunction with queued imports and exports.
|
*/
'remote_disk' => null,

],
];
2 changes: 0 additions & 2 deletions src/ChunkReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Jobs\ReadChunk;
use Maatwebsite\Excel\Jobs\QueueImport;
use Illuminate\Contracts\Bus\Dispatcher;
use Maatwebsite\Excel\Concerns\WithLimit;
use Maatwebsite\Excel\Files\TemporaryFile;
use Illuminate\Contracts\Queue\ShouldQueue;
use PhpOffice\PhpSpreadsheet\Reader\IReader;
use Maatwebsite\Excel\Helpers\FilePathHelper;
use Maatwebsite\Excel\Concerns\WithProgressBar;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
Expand Down
11 changes: 8 additions & 3 deletions src/Excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Files\Filesystem;
use Maatwebsite\Excel\Files\TemporaryFile;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\PendingDispatch;
use Maatwebsite\Excel\Files\TemporaryFile;
use Maatwebsite\Excel\Helpers\FileTypeDetector;

class Excel implements Exporter, Importer
Expand Down Expand Up @@ -121,9 +121,14 @@ public function queue($export, string $filePath, string $diskName = null, string
/**
* {@inheritdoc}
*/
public function raw($export, string $fileName, string $writerType = null)
public function raw($export, string $writerType)
{
return $this->export($export, $fileName, $writerType)->contents();
$temporaryFile = $this->writer->export($export, $writerType);

$contents = $temporaryFile->contents();
$temporaryFile->delete();

return $contents;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/ExcelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Support\Collection;
use Illuminate\Support\ServiceProvider;
use Maatwebsite\Excel\Files\Filesystem;
use Maatwebsite\Excel\Helpers\FilePathHelper;
use Maatwebsite\Excel\Mixins\StoreCollection;
use Maatwebsite\Excel\Console\ExportMakeCommand;
use Maatwebsite\Excel\Console\ImportMakeCommand;
Expand Down Expand Up @@ -44,8 +43,8 @@ public function register()
$this->app->bind(TemporaryFileFactory::class, function () {
return new TemporaryFileFactory(
$this->app->make(Filesystem::class),
config('excel.temp_path', config('excel.exports.temp_path', storage_path('framework/laravel-excel'))),
config('excel.remote_temp_disk')
config('excel.temporary_files.local_path', config('excel.exports.temp_path', storage_path('framework/laravel-excel'))),
config('excel.temporary_files.remote_disk')

);
});
Expand Down
5 changes: 1 addition & 4 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ public function queue($export, string $filePath, string $disk = null, string $wr

/**
* @param object $export
* @param string $filePath
* @param string $writerType
*
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @return string
*/
public function raw($export, string $filePath, string $writerType = null);
public function raw($export, string $writerType);
}
10 changes: 5 additions & 5 deletions src/Factories/ReaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Maatwebsite\Excel\Factories;

use Maatwebsite\Excel\Concerns\MapsCsvSettings;
use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;
use Maatwebsite\Excel\Exceptions\NoTypeDetectedException;
use Maatwebsite\Excel\Files\TemporaryFile;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Exception;
use Maatwebsite\Excel\Files\TemporaryFile;
use PhpOffice\PhpSpreadsheet\Reader\IReader;
use PhpOffice\PhpSpreadsheet\Reader\Exception;
use Maatwebsite\Excel\Concerns\MapsCsvSettings;
use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;
use Maatwebsite\Excel\Exceptions\NoTypeDetectedException;

class ReaderFactory
{
Expand Down
10 changes: 5 additions & 5 deletions src/Factories/WriterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Maatwebsite\Excel\Factories;

use Maatwebsite\Excel\Concerns\MapsCsvSettings;
use Maatwebsite\Excel\Concerns\WithCharts;
use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;
use Maatwebsite\Excel\Concerns\WithPreCalculateFormulas;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Csv;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use Maatwebsite\Excel\Concerns\WithCharts;
use PhpOffice\PhpSpreadsheet\Writer\IWriter;
use Maatwebsite\Excel\Concerns\MapsCsvSettings;
use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;
use Maatwebsite\Excel\Concerns\WithPreCalculateFormulas;

class WriterFactory
{
Expand Down
7 changes: 2 additions & 5 deletions src/Fakes/ExcelFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,13 @@ public function handle()

/**
* @param object $export
* @param string $filePath
* @param string $writerType
*
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @return string
*/
public function raw($export, string $filePath, string $writerType = null)
public function raw($export, string $writerType)
{
return '';
return 'RAW-CONTENTS';
}

/**
Expand Down
53 changes: 11 additions & 42 deletions src/Files/Disk.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public function __construct(Filesystem $disk, string $name = null, array $diskOp
$this->diskOptions = $diskOptions;
}

/**
* @param string $name
* @param array $arguments
*
* @return mixed
*/
public function __call($name, $arguments)
{
return $this->disk->{$name}(...$arguments);
}

/**
* @param string $destination
* @param string|resource $contents
Expand Down Expand Up @@ -73,53 +84,11 @@ public function copy(TemporaryFile $source, string $destination): bool
return $success;
}

/**
* @param string $fileName
*
* @return LocalTemporaryFile
*/
public function copyToLocalTempFolder(string $fileName): LocalTemporaryFile
{
$temporaryFile = $this->getTemporaryFileFactory()->makeLocal(
$fileName
);

$tmpStream = fopen($temporaryFile->getLocalPath(), 'wb+');

stream_copy_to_stream(
$this->disk->readStream($fileName),
$tmpStream
);

fclose($tmpStream);

return $temporaryFile;
}

/**
* @param string $filename
*/
public function touch(string $filename)
{
$this->disk->put($filename, '', $this->diskOptions);
}

/**
* @return TemporaryFileFactory
*/
private function getTemporaryFileFactory(): TemporaryFileFactory
{
return app(TemporaryFileFactory::class);
}

/**
* @param string $name
* @param array $arguments
*
* @return mixed
*/
public function __call($name, $arguments)
{
return $this->disk->{$name}(...$arguments);
}
}
4 changes: 2 additions & 2 deletions src/Files/RemoteTemporaryFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function delete(): bool
/**
* @return TemporaryFile
*/
public function fresh(): TemporaryFile
public function sync(): TemporaryFile
{
if (!$this->localTemporaryFile->exists()) {
touch($this->localTemporaryFile->getLocalPath());
Expand All @@ -79,7 +79,7 @@ public function fresh(): TemporaryFile
/**
* Store on remote disk.
*/
public function sync()
public function updateRemote()
{
$this->disk->copy(
$this->localTemporaryFile,
Expand Down
4 changes: 2 additions & 2 deletions src/Files/TemporaryFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract public function contents(): string;
/**
* @return TemporaryFile
*/
public function fresh(): TemporaryFile
public function sync(): TemporaryFile
{
return $this;
}
Expand All @@ -63,6 +63,6 @@ public function copyFrom($filePath, string $disk = null): TemporaryFile
$this->put($readStream);
fclose($readStream);

return $this->fresh();
return $this->sync();
}
}
2 changes: 1 addition & 1 deletion src/Files/TemporaryFileFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function makeRemote(): RemoteTemporaryFile

return new RemoteTemporaryFile(
$this->filesystem->disk($this->temporaryDisk),
$this->generateFilename(),
$filename,
$this->makeLocal($filename)
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/FileTypeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Maatwebsite\Excel\Helpers;

use Maatwebsite\Excel\Exceptions\NoTypeDetectedException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Maatwebsite\Excel\Exceptions\NoTypeDetectedException;

class FileTypeDetector
{
Expand Down Expand Up @@ -51,4 +51,4 @@ public static function detectStrict(string $filePath, string $type = null): stri

return $type;
}
}
}
5 changes: 2 additions & 3 deletions src/Jobs/ReadChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Maatwebsite\Excel\Jobs;

use Illuminate\Foundation\Bus\Dispatchable;
use Maatwebsite\Excel\Sheet;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\DB;
Expand All @@ -16,7 +15,7 @@

class ReadChunk implements ShouldQueue
{
use Queueable, Dispatchable;
use Queueable;

/**
* @var IReader
Expand Down Expand Up @@ -90,7 +89,7 @@ public function handle()
$this->reader->setReadEmptyCells(false);

$spreadsheet = $this->reader->load(
$this->temporaryFile->fresh()->getLocalPath()
$this->temporaryFile->sync()->getLocalPath()
);

$sheet = Sheet::byName(
Expand Down
7 changes: 1 addition & 6 deletions src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,20 @@
use InvalidArgumentException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Files\TemporaryFileFactory;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use Maatwebsite\Excel\Events\AfterImport;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeImport;
use Maatwebsite\Excel\Files\TemporaryFile;
use Illuminate\Contracts\Queue\ShouldQueue;
use PhpOffice\PhpSpreadsheet\Reader\IReader;
use Maatwebsite\Excel\Helpers\FilePathHelper;
use Maatwebsite\Excel\Factories\ReaderFactory;
use PhpOffice\PhpSpreadsheet\Reader\Exception;
use Maatwebsite\Excel\Concerns\MapsCsvSettings;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Maatwebsite\Excel\Files\TemporaryFileFactory;
use Maatwebsite\Excel\Concerns\SkipsUnknownSheets;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
use Maatwebsite\Excel\Concerns\WithCalculatedFormulas;
use Symfony\Component\HttpFoundation\File\UploadedFile;
Expand Down
Loading

0 comments on commit d806052

Please sign in to comment.