StreamedResponse example

$stream = $stream->detach();

        if (!\is_resource($stream)) {
            if (!Feature::isActive('v6.6.0.0')) {
                throw new FileNotFoundException($media->getFilename() . '.' . $media->getFileExtension());
            }

            throw MediaException::fileNotFound($media->getFilename() . '.' . $media->getFileExtension());
        }

        return new StreamedResponse(function D) use ($stream): void {
            fpassthru($stream);
        }, Response::HTTP_OK, $this->getStreamHeaders($media));
    }

    private function getFileSystem(MediaEntity $media): FilesystemOperator
    {
        if ($media->isPrivate()) {
            $filesystem = $this->filesystemPrivate;
        } else {
            $filesystem = $this->filesystemPublic;
        }

        
// only printable ascii                 (string) preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $originalName)
            ),
            'Content-Length' => $this->filesystem->fileSize($entity->getPath()),
            'Content-Type' => 'application/octet-stream',
        ];
        $stream = $this->filesystem->readStream($entity->getPath());
        if (!\is_resource($stream)) {
            throw ImportExportException::fileNotFound($fileId);
        }

        return new StreamedResponse(function D) use ($stream): void {
            fpassthru($stream);
        }, Response::HTTP_OK, $headers);
    }

    private function findFile(Context $context, string $fileId): ImportExportFileEntity
    {
        $entity = $this->fileRepository->search(new Criteria([$fileId])$context)->get($fileId);

        if (!$entity instanceof ImportExportFileEntity) {
            throw ImportExportException::fileNotFound($fileId);
        }

        

class InstallControllerTest extends TestCase
{
    public function testStartPage(): void
    {
        $recovery = $this->createMock(RecoveryManager::class);
        $recovery->method('getShopwareLocation')->willReturn('asd');

        $responseGenerator = $this->createMock(StreamedCommandResponseGenerator::class);
        $responseGenerator->method('runJSON')->willReturn(new StreamedResponse());

        $controller = new InstallController($recovery$responseGenerator$this->createMock(ReleaseInfoProvider::class));
        $controller->setContainer($this->getContainer());

        $response = $controller->index();

        static::assertSame(Response::HTTP_OK, $response->getStatusCode());
        static::assertSame('install.html.twig', $response->getContent());
    }

    public function testInstall(): void
    {
$responseGenerator = $this->createMock(StreamedCommandResponseGenerator::class);
        $responseGenerator
            ->expects(static::once())
            ->method('runJSON')
            ->with([
                '/usr/bin/php',
                '-dmemory_limit=1G',
                '/path/to/shopware/bin/console',
                'system:update:prepare',
                '--no-interaction',
            ])
            ->willReturn(new StreamedResponse());

        $controller = new UpdateController(
            $recoveryManager,
            $this->createMock(ReleaseInfoProvider::class),
            $this->createMock(FlexMigrator::class),
            $responseGenerator,
        );
        $controller->setContainer($this->getContainer());

        $request = new Request();
        $request->setSession(new Session(new MockArraySessionStorage()));
        

    public function run(array $params, callable $finish): StreamedResponse
    {
        $process = new Process($params);
        $process->setEnv(['COMPOSER_HOME' => sys_get_temp_dir() . '/composer']);
        $process->setTimeout(300);

        $process->start();

        return new StreamedResponse(function D) use ($process$finish): void {
            foreach ($process->getIterator() as $item) {
                \assert(\is_string($item));
                echo $item;
                flush();
            }

            $finish($process);
        });
    }

    /** * @param array<string> $params */
'Content-Length' => 0,
            'Content-Type' => 'application/octet-stream',
        ];

        if ($strategy) {
            $response = new Response(null, 200, $headers);
            $response->headers->set($strategy, 'foobar.txt');

            return $response;
        }

        return new StreamedResponse(function D): void {
        }, Response::HTTP_OK, $headers);
    }
}
Home | Imprint | This part of the site doesn't use cookies.