getContentType example


  }

  /** * {@inheritdoc} */
  public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL) {
    parent::initDisplay($view$display$options);

    // If the default 'json' format is not selected as a format option in the     // view display, fallback to the first format available for the default.     if (!empty($options['style']['options']['formats']) && !isset($options['style']['options']['formats'][$this->getContentType()])) {
      $default_format = reset($options['style']['options']['formats']);
      $this->setContentType($default_format);
    }

    // Only use the requested content type if it's not 'html'. This allows     // still falling back to the default for things like views preview.     $request_content_type = $this->view->getRequest()->getRequestFormat();

    if ($request_content_type !== 'html') {
      $this->setContentType($request_content_type);
    }

    

        $p = new DataPart('content', null);
        self::assertNull($p->getFilename());

        $p = new DataPart('content', 'filename');
        self::assertSame('filename', $p->getFilename());
    }

    public function testGetContentType()
    {
        $p = new DataPart('content');
        self::assertSame('application/octet-stream', $p->getContentType());

        $p = new DataPart('content', null, 'application/pdf');
        self::assertSame('application/pdf', $p->getContentType());
    }

    public function testSerialize()
    {
        $r = fopen('php://memory', 'r+', false);
        fwrite($r, 'Text content');
        rewind($r);

        
$this->assertFalse($isNoCache);
    }

    /** * @group legacy */
    public function testGetContentType()
    {
        $this->expectDeprecation('Since symfony/http-foundation 6.2: The "Symfony\Component\HttpFoundation\Request::getContentType()" method is deprecated, use "getContentTypeFormat()" instead.');
        $request = new Request();

        $contentType = $request->getContentType();

        $this->assertNull($contentType);
    }

    public function testGetContentTypeFormat()
    {
        $request = new Request();
        $this->assertNull($request->getContentTypeFormat());

        $server = ['HTTP_CONTENT_TYPE' => 'application/json'];
        $request = new Request([][][][][]$server);
        


        if (!($filter & Caster::EXCLUDE_VERBOSE)) {
            $a += [$prefix.'body' => $c->getBody()];
        }

        $a += [
            $prefix.'delivery_tag' => $c->getDeliveryTag(),
            $prefix.'is_redelivery' => $c->isRedelivery(),
            $prefix.'exchange_name' => $c->getExchangeName(),
            $prefix.'routing_key' => $c->getRoutingKey(),
            $prefix.'content_type' => $c->getContentType(),
            $prefix.'content_encoding' => $c->getContentEncoding(),
            $prefix.'headers' => $c->getHeaders(),
            $prefix.'delivery_mode' => $deliveryMode,
            $prefix.'priority' => $c->getPriority(),
            $prefix.'correlation_id' => $c->getCorrelationId(),
            $prefix.'reply_to' => $c->getReplyTo(),
            $prefix.'expiration' => $c->getExpiration(),
            $prefix.'message_id' => $c->getMessageId(),
            $prefix.'timestamp' => $c->getTimeStamp(),
            $prefix.'type' => $c->getType(),
            $prefix.'user_id' => $c->getUserId(),
            


    public function testReadNonStaticGeneratedDocument(): void
    {
        $operation = new DocumentGenerateOperation($this->orderId, FileTypes::PDF);

        $invoiceStruct = $this->documentGenerator->generate(InvoiceRenderer::TYPE, [$this->orderId => $operation]$this->context)->getSuccess()->first();
        static::assertNotNull($invoiceStruct);
        $generatedDocument = $this->documentGenerator->readDocument($invoiceStruct->getId()$this->context);

        static::assertInstanceOf(RenderedDocument::class$generatedDocument);
        static::assertEquals(PdfRenderer::FILE_CONTENT_TYPE, $generatedDocument->getContentType());

        $document = $this->documentRepository->search(
            new Criteria([$invoiceStruct->getId()]),
            $this->context,
        )->first();

        static::assertNotNull($document);
        static::assertInstanceOf(DocumentEntity::class$document);
        $mediaId = $document->getDocumentMediaFileId();

        static::assertNotNull($mediaId);

        

    protected function buildMessage()
    {
        if ($this->wordWrap === true && $this->mailType !== 'html') {
            $this->body = $this->wordWrap($this->body);
        }

        $this->writeHeaders();
        $hdr  = ($this->getProtocol() === 'mail') ? $this->newline : '';
        $body = '';

        switch ($this->getContentType()) {
            case 'plain':
                $hdr .= 'Content-Type: text/plain; charset='
                    . $this->charset
                    . $this->newline
                    . 'Content-Transfer-Encoding: '
                    . $this->getEncoding();

                if ($this->getProtocol() === 'mail') {
                    $this->headerStr .= $hdr;
                    $this->finalBody = $this->body;
                } else {
                    
/** @var DocumentEntity $document */
        foreach ($entities as $document) {
            $document = $this->documentGenerator->readDocument($document->getId()$context);

            if ($document === null) {
                continue;
            }

            $attachments[] = [
                'content' => $document->getContent(),
                'fileName' => $document->getName(),
                'mimeType' => $document->getContentType(),
            ];
        }

        return $attachments;
    }
}
$this->productExportService->export($contextnew ExportBehavior()$productExport->getId());
        }

        if (!$this->fileSystem->fileExists($filePath)) {
            $exportNotGeneratedException = new ExportNotGeneratedException();
            $this->logException($context->getContext()$exportNotGeneratedException);

            throw $exportNotGeneratedException;
        }

        $content = $this->fileSystem->read($filePath);
        $contentType = $this->getContentType($productExport->getFileFormat());
        $encoding = $productExport->getEncoding();

        return (new Response($content ?: null, 200, ['Content-Type' => $contentType . ';charset=' . $encoding]))
            ->setCharset($encoding);
    }

    private function getContentType(string $fileFormat): string
    {
        $contentType = 'text/plain';

        switch ($fileFormat) {
            
$document = $this->documentGenerator->readDocument($documentId$context->getContext()$deepLinkCode);

        if ($document === null) {
            return new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT);
        }

        return $this->createResponse(
            $document->getName(),
            $document->getContent(),
            $download,
            $document->getContentType()
        );
    }

    private function createResponse(string $filename, string $content, bool $forceDownload, string $contentType): Response
    {
        $response = new Response($content);

        $disposition = HeaderUtils::makeDisposition(
            $forceDownload ? HeaderUtils::DISPOSITION_ATTACHMENT : HeaderUtils::DISPOSITION_INLINE,
            $filename,
            // only printable ascii
static::assertNull($mergeResult);
            },
        ];

        yield 'merge non static documents' => [
            2,
            false,
            true,
            function D?RenderedDocument $mergeResult): void {
                static::assertInstanceOf(RenderedDocument::class$mergeResult);
                static::assertEquals('Dummy output', $mergeResult->getContent());
                static::assertEquals(PdfRenderer::FILE_CONTENT_TYPE, $mergeResult->getContentType());
            },
        ];

        yield 'merge static documents without media' => [
            2,
            true,
            false,
            function D?RenderedDocument $mergeResult): void {
                static::assertNull($mergeResult);
            },
        ];

        
foreach ($media as [
            'file' => $file,
            'alt' => $alt,
            'subtitles' => $subtitles,
            'category' => $category,
            'owners' => $extraOwners,
        ]) {
            $query = [
                'command' => 'INIT',
                'total_bytes' => $file->getSize(),
                'media_type' => $file->getContentType(),
            ];

            if ($category) {
                $query['media_category'] = $category;
            }

            if ($extraOwners) {
                $query['additional_owners'] = implode(',', $extraOwners);
            }

            $pool[++$i] = $this->request('POST', '/1.1/media/upload.json', [
                
private ?string $cid = null;

    /** * @param resource|string|File $body Use a File instance to defer loading the file until rendering */
    public function __construct($body, string $filename = null, string $contentType = null, string $encoding = null)
    {
        if ($body instanceof File && !$filename) {
            $filename = $body->getFilename();
        }

        $contentType ??= $body instanceof File ? $body->getContentType() : 'application/octet-stream';
        [$this->mediaType, $subtype] = explode('/', $contentType);

        parent::__construct($body, null, $subtype$encoding);

        if (null !== $filename) {
            $this->filename = $filename;
            $this->setName($filename);
        }
        $this->setDisposition('attachment');
    }

    
public function getAttributes(): array
    {
        return $this->attributes;
    }

    public static function createFromAmqpEnvelope(\AMQPEnvelope $amqpEnvelope, self $previousStamp = null, string $retryRoutingKey = null): self
    {
        $attr = $previousStamp->attributes ?? [];

        $attr['headers'] ??= $amqpEnvelope->getHeaders();
        $attr['content_type'] ??= $amqpEnvelope->getContentType();
        $attr['content_encoding'] ??= $amqpEnvelope->getContentEncoding();
        $attr['delivery_mode'] ??= $amqpEnvelope->getDeliveryMode();
        $attr['priority'] ??= $amqpEnvelope->getPriority();
        $attr['timestamp'] ??= $amqpEnvelope->getTimestamp();
        $attr['app_id'] ??= $amqpEnvelope->getAppId();
        $attr['message_id'] ??= $amqpEnvelope->getMessageId();
        $attr['user_id'] ??= $amqpEnvelope->getUserId();
        $attr['expiration'] ??= $amqpEnvelope->getExpiration();
        $attr['type'] ??= $amqpEnvelope->getType();
        $attr['reply_to'] ??= $amqpEnvelope->getReplyTo();
        $attr['correlation_id'] ??= $amqpEnvelope->getCorrelationId();

        


  /** * Tests the getContentType() method with AJAX iframe upload. * * @covers ::getContentType */
  public function testAjaxIframeUpload() {
    $request = new Request();
    $request->request->set('ajax_iframe_upload', '1');

    $this->assertSame('iframeupload', $this->contentNegotiation->getContentType($request));
  }

  /** * Tests the specifying a format via query parameters gets used. * * @covers ::getContentType */
  public function testFormatViaQueryParameter() {
    $request = new Request();
    $request->query->set('_format', 'bob');

    
$this->assertSame('html', $c->getFormat());
        $this->assertEquals('foobar', $c->getRoute());
        $this->assertEquals(['name' => 'foo']$c->getRouteParams());
        $this->assertSame([]$c->getSessionAttributes());
        $this->assertSame('en', $c->getLocale());
        $this->assertContainsEquals(__FILE__, $attributes->get('resource'));
        $this->assertSame('stdClass', $attributes->get('object')->getType());

        $this->assertInstanceOf(ParameterBag::class$c->getResponseHeaders());
        $this->assertSame('OK', $c->getStatusText());
        $this->assertSame(200, $c->getStatusCode());
        $this->assertSame('application/json', $c->getContentType());
    }

    public function testCollectWithoutRouteParams()
    {
        $request = $this->createRequest([]);

        $c = new RequestDataCollector();
        $c->collect($request$this->createResponse());
        $c->lateCollect();

        $this->assertEquals([]$c->getRouteParams());
    }
Home | Imprint | This part of the site doesn't use cookies.