-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b512a3
commit 59b847e
Showing
2 changed files
with
94 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,52 +4,32 @@ | |
|
||
namespace diecoding\flysystem\adapter; | ||
|
||
use DateTimeInterface; | ||
use diecoding\flysystem\traits\ChecksumAdapterTrait; | ||
use diecoding\flysystem\traits\UrlGeneratorAdapterTrait; | ||
use League\Flysystem\ChecksumProvider; | ||
use League\Flysystem\Config; | ||
use League\Flysystem\FileAttributes; | ||
use League\Flysystem\FilesystemAdapter; | ||
use League\Flysystem\UnixVisibility\VisibilityConverter; | ||
use League\Flysystem\UrlGeneration\PublicUrlGenerator; | ||
use League\Flysystem\UrlGeneration\TemporaryUrlGenerator; | ||
use League\Flysystem\ZipArchive\ZipArchiveAdapter as LeagueZipArchiveAdapter; | ||
use League\Flysystem\ZipArchive\ZipArchiveProvider; | ||
use League\MimeTypeDetection\MimeTypeDetector; | ||
use yii\helpers\Json; | ||
use yii\helpers\Url; | ||
|
||
/** | ||
* @method bool fileExists(string $location) | ||
* @method bool directoryExists(string $location) | ||
* @method bool has(string $location) check fileExists or directoryExists | ||
* @method void write(string $location, string $contents, array $config = []) | ||
* @method void writeStream(string $location, $contents, array $config = []) | ||
* @method string read(string $location) | ||
* @method resource readStream(string $location) | ||
* @method void delete(string $location) | ||
* @method void deleteDirectory(string $location) | ||
* @method void createDirectory(string $location, array $config = []) | ||
* @method \League\Flysystem\DirectoryListing listContents(string $location, bool = \League\Flysystem\Filesystem::LIST_SHALLOW) | ||
* @method void move(string $source, string $destination, array $config = []) | ||
* @method void copy(string $source, string $destination, array $config = []) | ||
* @method int lastModified(string $path) | ||
* @method int fileSize(string $path) | ||
* @method string mimeType(string $path) | ||
* @method void setVisibility(string $path, string $visibility) | ||
* @method string visibility(string $path) | ||
* | ||
* @link https://sugengsulistiyawan.my.id/ | ||
* @author Sugeng Sulistiyawan <[email protected]> | ||
* @copyright Copyright (c) 2024 | ||
*/ | ||
final class ZipArchiveAdapter implements ChecksumProvider, PublicUrlGenerator, TemporaryUrlGenerator | ||
|
||
final class ZipArchiveAdapter implements FilesystemAdapter, ChecksumProvider, PublicUrlGenerator, TemporaryUrlGenerator | ||
{ | ||
use UrlGeneratorAdapterTrait, ChecksumAdapterTrait; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected $skipPrefixer = true; | ||
|
||
/** | ||
* @var LeagueZipArchiveAdapter | ||
*/ | ||
protected $_adapter; | ||
private $_adapter; | ||
|
||
public function __construct( | ||
private ZipArchiveProvider $zipArchiveProvider, | ||
|
@@ -61,16 +41,6 @@ public function __construct( | |
$this->setAdapter(new LeagueZipArchiveAdapter($zipArchiveProvider, $root, $mimeTypeDetector, $visibility, $detectMimeTypeUsingPath)); | ||
} | ||
|
||
/** | ||
* @param string $method | ||
* @param array $parameters | ||
* @return mixed | ||
*/ | ||
public function __call($method, $parameters) | ||
{ | ||
return call_user_func_array([$this->getAdapter(), $method], $parameters); | ||
} | ||
|
||
/** | ||
* @return LeagueZipArchiveAdapter | ||
*/ | ||
|
@@ -88,25 +58,88 @@ public function setAdapter(LeagueZipArchiveAdapter $value) | |
$this->_adapter = $value; | ||
} | ||
|
||
public function publicUrl(string $path, Config $config): string | ||
public function fileExists(string $path): bool | ||
{ | ||
return $this->getAdapter()->fileExists($path); | ||
} | ||
|
||
public function write(string $path, string $contents, Config $config): void | ||
{ | ||
$this->getAdapter()->write($path, $contents, $config); | ||
} | ||
|
||
public function writeStream(string $path, $contents, Config $config): void | ||
{ | ||
$this->getAdapter()->writeStream($path, $contents, $config); | ||
} | ||
|
||
public function read(string $path): string | ||
{ | ||
return $this->getAdapter()->read($path); | ||
} | ||
|
||
public function readStream(string $path) | ||
{ | ||
return $this->getAdapter()->readStream($path); | ||
} | ||
|
||
public function delete(string $path): void | ||
{ | ||
$this->getAdapter()->delete($path); | ||
} | ||
|
||
public function deleteDirectory(string $path): void | ||
{ | ||
$this->getAdapter()->deleteDirectory($path); | ||
} | ||
|
||
public function createDirectory(string $path, Config $config): void | ||
{ | ||
$this->getAdapter()->createDirectory($path, $config); | ||
} | ||
|
||
public function directoryExists(string $path): bool | ||
{ | ||
return $this->getAdapter()->directoryExists($path); | ||
} | ||
|
||
public function setVisibility(string $path, string $visibility): void | ||
{ | ||
$this->getAdapter()->setVisibility($path, $visibility); | ||
} | ||
|
||
public function visibility(string $path): FileAttributes | ||
{ | ||
// TODO: Use absolute path and don't encrypt | ||
$params = [ | ||
'path' => $path, | ||
'expires' => 0, | ||
]; | ||
return $this->getAdapter()->visibility($path); | ||
} | ||
|
||
return Url::toRoute([$this->component?->action, 'data' => $this->component?->encrypt(Json::encode($params))], true); | ||
public function mimeType(string $path): FileAttributes | ||
{ | ||
return $this->getAdapter()->mimeType($path); | ||
} | ||
|
||
public function temporaryUrl(string $path, DateTimeInterface $expiresAt, Config $config): string | ||
public function lastModified(string $path): FileAttributes | ||
{ | ||
// TODO: Use absolute path and don't encrypt | ||
$params = [ | ||
'path' => $path, | ||
'expires' => (int) $expiresAt->getTimestamp(), | ||
]; | ||
return $this->getAdapter()->lastModified($path); | ||
} | ||
|
||
return Url::toRoute([$this->component?->action, 'data' => $this->component?->encrypt(Json::encode($params))], true); | ||
public function fileSize(string $path): FileAttributes | ||
{ | ||
return $this->getAdapter()->fileSize($path); | ||
} | ||
|
||
public function listContents(string $path, bool $deep): iterable | ||
{ | ||
return $this->getAdapter()->listContents($path, $deep); | ||
} | ||
|
||
public function move(string $source, string $destination, Config $config): void | ||
{ | ||
$this->getAdapter()->move($source, $destination, $config); | ||
} | ||
|
||
public function copy(string $source, string $destination, Config $config): void | ||
{ | ||
$this->getAdapter()->copy($source, $destination, $config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters