-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
5 changed files
with
93 additions
and
3 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
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
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Frosh\BunnycdnMediaStorage\Adapter; | ||
|
||
use League\Flysystem\Config; | ||
use PlatformCommunity\Flysystem\BunnyCDN\WriteBatchFile; | ||
use Shopware\Core\Framework\Adapter\Filesystem\Plugin\CopyBatchInput; | ||
use Shopware\Core\Framework\Adapter\Filesystem\Plugin\WriteBatchInterface; | ||
|
||
class Shopware6BunnyCdnWriteBatchAdapter extends Shopware6BunnyCdnAdapter implements WriteBatchInterface | ||
{ | ||
public function writeBatch(CopyBatchInput|array|Config ...$input): void | ||
{ | ||
$files = []; | ||
$config = new Config(); | ||
|
||
foreach ($input as $data) { | ||
if ($data instanceof CopyBatchInput) { | ||
// migrate CopyBatchInput of Shopware to WriteBatchFile | ||
foreach ($data->getTargetFiles() as $targetFile) { | ||
if (\is_resource($data->getSourceFile())) { | ||
$sourcePath = stream_get_meta_data($data->getSourceFile())['uri'] ?? null; | ||
|
||
if (!\is_string($sourcePath)) { | ||
throw new \InvalidArgumentException('Cannot get source file path from stream.'); | ||
} | ||
|
||
$files[] = new WriteBatchFile($sourcePath, $targetFile); | ||
|
||
continue; | ||
} | ||
|
||
$files[] = new WriteBatchFile($data->getSourceFile(), $targetFile); | ||
} | ||
|
||
continue; | ||
} | ||
|
||
if ($data instanceof Config) { | ||
$config = $data; | ||
|
||
continue; | ||
} | ||
|
||
if (\is_array($data)) { | ||
foreach ($data as $item) { | ||
if ($item instanceof WriteBatchFile) { | ||
$files[] = $item; | ||
|
||
continue; | ||
} | ||
|
||
throw new \InvalidArgumentException('Each value of array must be a WriteBatchFile object.'); | ||
} | ||
} | ||
} | ||
|
||
if (empty($files)) { | ||
return; | ||
} | ||
|
||
parent::writeBatch($files, $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