60 lines
1.2 KiB
PHP
60 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Aweos\Resizer\Lib;
|
|
|
|
use Aweos\Resizer\Compressors\Compressor;
|
|
use Aweos\Resizer\Compressors\Factory as CompressorFactory;
|
|
use Aweos\Resizer\Models\Setting;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use MediaLibrary;
|
|
|
|
class TempMediaPath extends MediaPath
|
|
{
|
|
|
|
private string $tempPath;
|
|
|
|
public function __construct(string $path)
|
|
{
|
|
parent::__construct($path);
|
|
$this->createTemp();
|
|
}
|
|
|
|
public function __destruct()
|
|
{
|
|
$this->destroyTemp();
|
|
}
|
|
|
|
public function root(): string
|
|
{
|
|
return $this->tempPath;
|
|
}
|
|
|
|
public function publicUrl(): string
|
|
{
|
|
return '';
|
|
}
|
|
|
|
public function get(): string
|
|
{
|
|
return file_get_contents($this->tempPath);
|
|
}
|
|
|
|
private function createTemp(): void
|
|
{
|
|
$this->tempPath = '/tmp/'.pathinfo($this->path, PATHINFO_FILENAME);
|
|
|
|
if (Storage::exists($this->storagePath())) {
|
|
$stream = Storage::readStream($this->storagePath());
|
|
$contents = stream_get_contents($stream);
|
|
file_put_contents($this->tempPath, $contents);
|
|
}
|
|
}
|
|
|
|
private function destroyTemp(): void
|
|
{
|
|
@unlink($this->tempPath);
|
|
}
|
|
|
|
}
|