openZip example

return (new DownloadStep($version$request->getDestination()))->run($request->getOffset());
    }

    /** * @param string $file * @param string $pluginName * * @throws Exception */
    public function extractPluginZip($file$pluginName)
    {
        $archive = ZipUtils::openZip($file);
        $pluginZipDetector = new PluginZipDetector();

        if ($pluginZipDetector->isLegacyPlugin($archive)) {
            $source = $this->getPluginSource($pluginName);
            if (!$source) {
                $source = 'Community';
            }
            $destination = $this->pluginDirectories[$source];
            $extractor = new LegacyPluginExtractor();
            $extractor->extract($archive$destination);
        } elseif ($pluginZipDetector->isPlugin($archive)) {
            
return $this->get('events')->filter('Shopware_Theme_Listing_Query_Created', $builder);
    }

    /** * Helper function to decompress zip files. * * @throws Exception */
    private function unzip(UploadedFile $file, string $targetDirectory): void
    {
        $filePath = $file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename();
        $zipUtils = ZipUtils::openZip($filePath);
        $zipUtils->extractTo($targetDirectory);
    }

    /** * Helper function which checks if the passed template * or the inheritance templates has configuration sets. */
    private function hasTemplateConfigSet(Template $template): bool
    {
        $theme = $this->get(Util::class)->getThemeByTemplate($template);

        
public function __construct(
        private readonly array $extensionDirectories,
        private readonly Filesystem $filesystem
    ) {
    }

    /** * Extracts the provided zip file to the plugin directory */
    public function extract(string $zipFilePath, bool $delete, string $type): void
    {
        $archive = ZipUtils::openZip($zipFilePath);

        $destination = $this->extensionDirectories[$type];

        if (!is_writable($destination)) {
            throw new PluginExtractionException(sprintf('Destination directory "%s" is not writable', $destination));
        }

        $pluginName = $this->getPluginName($archive);
        $this->validatePluginZip($pluginName$archive);

        $oldFile = $this->findOldFile($destination$pluginName);
        
class PluginZipDetectorTest extends TestCase
{
    private PluginZipDetector $zipDetector;

    protected function setUp(): void
    {
        $this->zipDetector = new PluginZipDetector();
    }

    public function testIsPlugin(): void
    {
        $archive = ZipUtils::openZip(__DIR__ . '/_fixture/archives/SwagFashionTheme.zip');

        $isPlugin = $this->zipDetector->isPlugin($archive);

        static::assertTrue($isPlugin);
    }

    public function testIsNoPlugin(): void
    {
        $archive = ZipUtils::openZip(__DIR__ . '/_fixture/archives/NoPlugin.zip');

        $isPlugin = $this->zipDetector->isPlugin($archive);

        

#[Package('core')] class PluginZipDetector
{
    /** * @return PluginManagementService::PLUGIN|PluginManagementService::APP */
    public function detect(string $zipFilePath): string
    {
        try {
            $archive = ZipUtils::openZip($zipFilePath);
        } catch (PluginExtractionException $e) {
            throw PluginException::noPluginFoundInZip($zipFilePath);
        }

        try {
            return match (true) {
                $this->isPlugin($archive) => PluginManagementService::PLUGIN,
                $this->isApp($archive) => PluginManagementService::APP,
                default => throw PluginException::noPluginFoundInZip($zipFilePath)
            };
        } finally {
            
/** * @internal */
class ZipUtilsTest extends TestCase
{
    public function testExceptionIsThrownIfZipFileDoesNotExist(): void
    {
        static::expectException(PluginException::class);
        static::expectExceptionMessage('No such zip file: /some/file/that/does/not/exist.zip');

        ZipUtils::openZip('/some/file/that/does/not/exist.zip');
    }

    public function testExceptionIsThrownIfZipIsInvalid(): void
    {
        static::expectException(PluginException::class);
        static::expectExceptionMessage(sprintf('%s is not a zip archive.', __FILE__));

        ZipUtils::openZip(__FILE__);
    }

    public function testArchiveIsReturnedForValidZip(): void
    {
Home | Imprint | This part of the site doesn't use cookies.