updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -0,0 +1,99 @@
<?php
namespace Maatwebsite\Excel\Files;
use Illuminate\Contracts\Filesystem\Filesystem as IlluminateFilesystem;
/**
* @method bool get(string $filename)
* @method resource readStream(string $filename)
* @method bool delete(string $filename)
* @method bool exists(string $filename)
*/
class Disk
{
/**
* @var IlluminateFilesystem
*/
protected $disk;
/**
* @var string|null
*/
protected $name;
/**
* @var array
*/
protected $diskOptions;
/**
* @param IlluminateFilesystem $disk
* @param string|null $name
* @param array $diskOptions
*/
public function __construct(IlluminateFilesystem $disk, string $name = null, array $diskOptions = [])
{
$this->disk = $disk;
$this->name = $name;
$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
*
* @return bool
*/
public function put(string $destination, $contents): bool
{
return $this->disk->put($destination, $contents, $this->diskOptions);
}
/**
* @param TemporaryFile $source
* @param string $destination
*
* @return bool
*/
public function copy(TemporaryFile $source, string $destination): bool
{
$readStream = $source->readStream();
if (realpath($destination)) {
$tempStream = fopen($destination, 'rb+');
$success = stream_copy_to_stream($readStream, $tempStream) !== false;
if (is_resource($tempStream)) {
fclose($tempStream);
}
} else {
$success = $this->put($destination, $readStream);
}
if (is_resource($readStream)) {
fclose($readStream);
}
return $success;
}
/**
* @param string $filename
*/
public function touch(string $filename)
{
$this->disk->put($filename, '', $this->diskOptions);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Maatwebsite\Excel\Files;
use Illuminate\Contracts\Filesystem\Factory;
class Filesystem
{
/**
* @var Factory
*/
private $filesystem;
/**
* @param Factory $filesystem
*/
public function __construct(Factory $filesystem)
{
$this->filesystem = $filesystem;
}
/**
* @param string|null $disk
* @param array $diskOptions
*
* @return Disk
*/
public function disk(string $disk = null, array $diskOptions = []): Disk
{
return new Disk(
$this->filesystem->disk($disk),
$disk,
$diskOptions
);
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace Maatwebsite\Excel\Files;
class LocalTemporaryFile extends TemporaryFile
{
/**
* @var string
*/
private $filePath;
/**
* @param string $filePath
*/
public function __construct(string $filePath)
{
touch($filePath);
$this->filePath = realpath($filePath);
}
/**
* @return string
*/
public function getLocalPath(): string
{
return $this->filePath;
}
/**
* @return bool
*/
public function exists(): bool
{
return file_exists($this->filePath);
}
/**
* @return bool
*/
public function delete(): bool
{
if (@unlink($this->filePath) || !$this->exists()) {
return true;
}
return unlink($this->filePath);
}
/**
* @return resource
*/
public function readStream()
{
return fopen($this->getLocalPath(), 'rb+');
}
/**
* @return string
*/
public function contents(): string
{
return file_get_contents($this->filePath);
}
/**
* @param @param string|resource $contents
*/
public function put($contents)
{
file_put_contents($this->filePath, $contents);
}
}

View File

@@ -0,0 +1,150 @@
<?php
namespace Maatwebsite\Excel\Files;
class RemoteTemporaryFile extends TemporaryFile
{
/**
* @var string
*/
private $disk;
/**
* @var Disk|null
*/
private $diskInstance;
/**
* @var string
*/
private $filename;
/**
* @var LocalTemporaryFile
*/
private $localTemporaryFile;
/**
* @param string $disk
* @param string $filename
* @param LocalTemporaryFile $localTemporaryFile
*/
public function __construct(string $disk, string $filename, LocalTemporaryFile $localTemporaryFile)
{
$this->disk = $disk;
$this->filename = $filename;
$this->localTemporaryFile = $localTemporaryFile;
$this->disk()->touch($filename);
}
public function __sleep()
{
return ['disk', 'filename', 'localTemporaryFile'];
}
/**
* @return string
*/
public function getLocalPath(): string
{
return $this->localTemporaryFile->getLocalPath();
}
/**
* @return bool
*/
public function existsLocally(): bool
{
return $this->localTemporaryFile->exists();
}
/**
* @return bool
*/
public function exists(): bool
{
return $this->disk()->exists($this->filename);
}
/**
* @return bool
*/
public function deleteLocalCopy(): bool
{
return $this->localTemporaryFile->delete();
}
/**
* @return bool
*/
public function delete(): bool
{
// we don't need to delete local copy as it's deleted at end of each chunk
if (!config('excel.temporary_files.force_resync_remote')) {
$this->deleteLocalCopy();
}
return $this->disk()->delete($this->filename);
}
/**
* @return TemporaryFile
*/
public function sync(): TemporaryFile
{
if (!$this->localTemporaryFile->exists()) {
touch($this->localTemporaryFile->getLocalPath());
}
$this->disk()->copy(
$this,
$this->localTemporaryFile->getLocalPath()
);
return $this;
}
/**
* Store on remote disk.
*/
public function updateRemote()
{
$this->disk()->copy(
$this->localTemporaryFile,
$this->filename
);
}
/**
* @return resource
*/
public function readStream()
{
return $this->disk()->readStream($this->filename);
}
/**
* @return string
*/
public function contents(): string
{
return $this->disk()->get($this->filename);
}
/**
* @param string|resource $contents
*/
public function put($contents)
{
$this->disk()->put($this->filename, $contents);
}
/**
* @return Disk
*/
public function disk(): Disk
{
return $this->diskInstance ?: $this->diskInstance = app(Filesystem::class)->disk($this->disk);
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Maatwebsite\Excel\Files;
use Symfony\Component\HttpFoundation\File\UploadedFile;
abstract class TemporaryFile
{
/**
* @return string
*/
abstract public function getLocalPath(): string;
/**
* @return bool
*/
abstract public function exists(): bool;
/**
* @param @param string|resource $contents
*/
abstract public function put($contents);
/**
* @return bool
*/
abstract public function delete(): bool;
/**
* @return resource
*/
abstract public function readStream();
/**
* @return string
*/
abstract public function contents(): string;
/**
* @return TemporaryFile
*/
public function sync(): TemporaryFile
{
return $this;
}
/**
* @param string|UploadedFile $filePath
* @param string|null $disk
*
* @return TemporaryFile
*/
public function copyFrom($filePath, string $disk = null): TemporaryFile
{
if ($filePath instanceof UploadedFile) {
$readStream = fopen($filePath->getRealPath(), 'rb');
} elseif ($disk === null && realpath($filePath) !== false) {
$readStream = fopen($filePath, 'rb');
} else {
$readStream = app('filesystem')->disk($disk)->readStream($filePath);
}
$this->put($readStream);
if (is_resource($readStream)) {
fclose($readStream);
}
return $this->sync();
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace Maatwebsite\Excel\Files;
use Illuminate\Support\Str;
class TemporaryFileFactory
{
/**
* @var string|null
*/
private $temporaryPath;
/**
* @var string|null
*/
private $temporaryDisk;
/**
* @param string|null $temporaryPath
* @param string|null $temporaryDisk
*/
public function __construct(string $temporaryPath = null, string $temporaryDisk = null)
{
$this->temporaryPath = $temporaryPath;
$this->temporaryDisk = $temporaryDisk;
}
/**
* @param string|null $fileExtension
*
* @return TemporaryFile
*/
public function make(string $fileExtension = null): TemporaryFile
{
if (null !== $this->temporaryDisk) {
return $this->makeRemote($fileExtension);
}
return $this->makeLocal(null, $fileExtension);
}
/**
* @param string|null $fileName
*
* @param string|null $fileExtension
*
* @return LocalTemporaryFile
*/
public function makeLocal(string $fileName = null, string $fileExtension = null): LocalTemporaryFile
{
if (!file_exists($this->temporaryPath) && !mkdir($concurrentDirectory = $this->temporaryPath) && !is_dir($concurrentDirectory)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
}
return new LocalTemporaryFile(
$this->temporaryPath . DIRECTORY_SEPARATOR . ($fileName ?: $this->generateFilename($fileExtension))
);
}
/**
* @param string|null $fileExtension
*
* @return RemoteTemporaryFile
*/
private function makeRemote(string $fileExtension = null): RemoteTemporaryFile
{
$filename = $this->generateFilename($fileExtension);
return new RemoteTemporaryFile(
$this->temporaryDisk,
config('excel.temporary_files.remote_prefix') . $filename,
$this->makeLocal($filename)
);
}
/**
* @param string|null $fileExtension
*
* @return string
*/
private function generateFilename(string $fileExtension = null): string
{
return 'laravel-excel-' . Str::random(32) . ($fileExtension ? '.' . $fileExtension : '');
}
}