-
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
6 changed files
with
104 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
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,70 @@ | ||
<?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; | ||
|
||
if (!\interface_exists(WriteBatchInterface::class)) { | ||
class Shopware6BunnyCdnWriteBatchAdapter extends Shopware6BunnyCdnAdapter | ||
{} | ||
} else { | ||
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) { | ||
$sourceFile = $data->getSourceFile(); | ||
|
||
if (\is_string($sourceFile)) { | ||
$files[] = new WriteBatchFile($sourceFile, $targetFile); | ||
|
||
continue; | ||
} | ||
|
||
$metaData = stream_get_meta_data($sourceFile); | ||
if (empty($metaData['uri'])) { | ||
throw new \InvalidArgumentException('Cannot get source file path from stream.'); | ||
} | ||
|
||
$sourcePath = $metaData['uri']; | ||
|
||
$files[] = new WriteBatchFile($sourcePath, $targetFile); | ||
} | ||
|
||
continue; | ||
} | ||
|
||
if ($data instanceof Config) { | ||
$config = $data; | ||
|
||
continue; | ||
} | ||
|
||
if (\is_array($data)) { | ||
foreach ($data as $item) { | ||
if (!$item instanceof WriteBatchFile) { | ||
throw new \InvalidArgumentException('Each value of array must be a WriteBatchFile object.'); | ||
} | ||
|
||
$files[] = $item; | ||
} | ||
} | ||
} | ||
|
||
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