fetchRequestData example

$content = fopen(self::TEST_IMAGE, 'rb');
        static::assertIsResource($content);

        $request = new Request([][][][][][]$content);
        $request->query->set('extension', 'png');

        $fileSize = filesize(self::TEST_IMAGE);
        $request->headers = new HeaderBag();
        $request->headers->set('content-length', (string) $fileSize);

        try {
            $this->fileFetcher->fetchRequestData(
                $request,
                $tempFile
            );
            $mimeType = mime_content_type($tempFile);

            static::assertEquals('image/png', $mimeType);
            static::assertFileExists($tempFile);
        } finally {
            unlink($tempFile);
        }
    }

    

        if ($tempFile === null) {
            $tempFile = tempnam(sys_get_temp_dir(), '');
        }

        $contentType = $request->headers->get('content_type', '');

        if (str_starts_with($contentType, 'application/json')) {
            return $this->fileFetcher->fetchFileFromURL($request$tempFile ?: '');
        }

        return $this->fileFetcher->fetchRequestData($request$tempFile ?: '');
    }

    /** * @return array{content: string, fileName: non-falsy-string, mimeType: string|null} */
    public function getAttachment(MediaEntity $media, Context $context): array
    {
        $fileBlob = '';
        $mediaService = $this;
        $context->scope(Context::SYSTEM_SCOPE, static function DContext $context) use ($mediaService$media, &$fileBlob): void {
            $fileBlob = $mediaService->loadFile($media->getId()$context);
        });
Home | Imprint | This part of the site doesn't use cookies.