getParts example



        if ($body instanceof AlternativePart) {
            return self::createEmailFromAlternativePart($message$body);
        }

        if ($body instanceof RelatedPart) {
            return self::createEmailFromRelatedPart($message$body);
        }

        if ($body instanceof MixedPart) {
            $parts = $body->getParts();
            if ($parts[0] instanceof RelatedPart) {
                $email = self::createEmailFromRelatedPart($message$parts[0]);
            } elseif ($parts[0] instanceof AlternativePart) {
                $email = self::createEmailFromAlternativePart($message$parts[0]);
            } elseif ($parts[0] instanceof TextPart) {
                $email = self::createEmailFromTextPart($message$parts[0]);
            } else {
                throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
            }

            return self::addParts($email, \array_slice($parts, 1));
        }


        if ($body instanceof AlternativePart) {
            return self::createEmailFromAlternativePart($message$body);
        }

        if ($body instanceof RelatedPart) {
            return self::createEmailFromRelatedPart($message$body);
        }

        if ($body instanceof MixedPart) {
            $parts = $body->getParts();
            if ($parts[0] instanceof RelatedPart) {
                $email = self::createEmailFromRelatedPart($message$parts[0]);
            } elseif ($parts[0] instanceof AlternativePart) {
                $email = self::createEmailFromAlternativePart($message$parts[0]);
            } elseif ($parts[0] instanceof TextPart) {
                $email = self::createEmailFromTextPart($message$parts[0]);
            } else {
                throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
            }

            return self::addParts($email, \array_slice($parts, 1));
        }

    public function send(Zend_Mail $mail)
    {
        $this->_isMultipart = false;
        $this->_mail        = $mail;
        $this->_parts       = $mail->getParts();
        $mime               = $mail->getMime();

        // Build body content         $this->_buildBody();

        // Determine number of parts and boundary         $count    = count($this->_parts);
        $boundary = null;
        if ($count < 1) {
            /** * @see Zend_Mail_Transport_Exception */
$this->generator->getCriteriaHash($criteria),
            $this->generator->getSalesChannelContextHash($context[RuleAreas::PRODUCT_AREA, RuleAreas::CATEGORY_AREA]),
        ];

        $event = new ProductListingRouteCacheKeyEvent($parts$categoryId$request$context$criteria);
        $this->dispatcher->dispatch($event);

        if (!$event->shouldCache()) {
            return null;
        }

        return self::buildName($categoryId) . '-' . md5(Json::encode($event->getParts()));
    }

    /** * @return array<string> */
    private function generateTags(string $categoryId, Request $request, ProductListingRouteResponse $response, SalesChannelContext $context, Criteria $criteria): array
    {
        $streamId = $response->getResult()->getStreamId();

        $tags = array_merge(
            $this->tracer->get(self::buildName($categoryId)),
            [

        $email = $this->prepareEmail('Text', null);
        $this->assertEquals('Text', $email->getBody()->bodyToString());
    }

    public function testRenderHtmlOnlyWithDefaultConverter()
    {
        $html = '<head><meta charset="utf-8"></head><b>HTML</b><style>css</style>';
        $email = $this->prepareEmail(null, $html[]new DefaultHtmlToTextConverter());
        $body = $email->getBody();
        $this->assertInstanceOf(AlternativePart::class$body);
        $this->assertEquals('HTML', $body->getParts()[0]->bodyToString());
        $this->assertEquals(str_replace(['=', "\n"]['=3D', "\r\n"]$html)$body->getParts()[1]->bodyToString());
    }

    public function testRenderHtmlOnlyWithLeagueConverter()
    {
        $html = '<head><meta charset="utf-8"></head><b>HTML</b><style>css</style>';
        $email = $this->prepareEmail(null, $html);
        $body = $email->getBody();
        $this->assertInstanceOf(AlternativePart::class$body);
        $this->assertEquals('**HTML**', $body->getParts()[0]->bodyToString());
        $this->assertEquals(str_replace(['=', "\n"]['=3D', "\r\n"]$html)$body->getParts()[1]->bodyToString());
    }
$this->generator->getCriteriaHash($criteria),
            $this->generator->getSalesChannelContextHash($context[RuleAreas::CATEGORY_AREA]),
        ];

        $event = new NavigationRouteCacheKeyEvent($parts$active$rootId$depth$request$context$criteria);
        $this->dispatcher->dispatch($event);

        if (!$event->shouldCache()) {
            return null;
        }

        return self::buildName($active) . '-' . md5(Json::encode($event->getParts()));
    }

    /** * @param array<string> $tags * * @return array<string> */
    private function generateTags(array $tags, string $active, string $rootId, int $depth, Request $request, StoreApiResponse $response, SalesChannelContext $context, Criteria $criteria): array
    {
        $tags = array_merge(
            $tags,
            
$this->generator->getCriteriaHash($criteria),
            $this->generator->getSalesChannelContextHash($context[RuleAreas::PRODUCT_AREA, RuleAreas::CATEGORY_AREA]),
        ];

        $event = new ProductDetailRouteCacheKeyEvent($parts$request$context$criteria);
        $this->dispatcher->dispatch($event);

        if (!$event->shouldCache()) {
            return null;
        }

        return self::buildName($productId) . '-' . md5(Json::encode($event->getParts()));
    }

    /** * @return array<string> */
    private function generateTags(string $productId, Request $request, ProductDetailRouteResponse $response, SalesChannelContext $context, Criteria $criteria): array
    {
        $parentId = $response->getProduct()->getParentId() ?? $response->getProduct()->getId();
        $pageId = $response->getProduct()->getCmsPageId();

        $tags = array_merge(
            
$this->generator->getCriteriaHash($criteria),
            $this->generator->getSalesChannelContextHash($context),
        ];

        $event = new CountryRouteCacheKeyEvent($parts$request$context$criteria);
        $this->dispatcher->dispatch($event);

        if (!$event->shouldCache()) {
            return null;
        }

        return self::buildName($context->getSalesChannelId()) . '-' . md5(Json::encode($event->getParts()));
    }

    /** * @return array<string> */
    private function generateTags(Request $request, StoreApiResponse $response, SalesChannelContext $context, Criteria $criteria): array
    {
        $tags = array_merge(
            $this->tracer->get(self::buildName($context->getSalesChannelId())),
            [self::buildName($context->getSalesChannelId()), self::ALL_TAG]
        );

        
public function testGenerateBodyWithTextAndHtmlAndAttachedFileAndAttachedImageReferencedViaCid()
    {
        [$text$html$filePart$file$imagePart$image] = $this->generateSomeParts();
        $e = (new Email())->from('me@example.com')->to('you@example.com');
        $e->html($content = 'html content <img src="cid:test.gif">');
        $e->text('text content');
        $e->addPart(new DataPart($file));
        $e->addPart(new DataPart($image, 'test.gif'));
        $body = $e->getBody();
        $this->assertInstanceOf(MixedPart::class$body);
        $this->assertCount(2, $related = $body->getParts());
        $this->assertInstanceOf(RelatedPart::class$related[0]);
        $this->assertEquals($filePart$related[1]);
        $this->assertCount(2, $parts = $related[0]->getParts());
        $this->assertInstanceOf(AlternativePart::class$parts[0]);
        $generatedHtml = $parts[0]->getParts()[1];
        $this->assertStringContainsString('cid:'.$parts[1]->getContentId()$generatedHtml->getBody());
    }

    public function testGenerateBodyWithTextAndHtmlAndAttachedFileAndAttachedImageReferencedViaCidAndContentId()
    {
        [$text$html$filePart$file$imagePart$image] = $this->generateSomeParts();
        
$documents = $this->entityManager->getRepository(Order::class)->getDocuments([$logEntry->getOrder()->getId()]);
        $filenameIdMap = [];

        foreach ($documents as $document) {
            $filename = $this->getDocumentFilename($document);

            if ($filename) {
                $filenameIdMap[$filename] = $document['id'];
            }
        }

        foreach ($mail->getParts() as $part) {
            if (isset($filenameIdMap[$part->filename])) {
                $document = $this->entityManager->getPartialReference(
                    Document::class,
                    $filenameIdMap[$part->filename]
                );
                if ($document instanceof Document) {
                    $logEntry->addDocument($document);
                }
            }
        }
    }

    
$this->generator->getSalesChannelContextHash($context[RuleAreas::PRODUCT_AREA]),
            $request->get('search'),
        ];

        $event = new ProductSearchRouteCacheKeyEvent($parts$request$context$criteria);
        $this->dispatcher->dispatch($event);

        if (!$event->shouldCache()) {
            return null;
        }

        return self::NAME . '-' . md5(Json::encode($event->getParts()));
    }

    /** * @return array<string> */
    private function generateTags(Request $request, StoreApiResponse $response, SalesChannelContext $context, Criteria $criteria): array
    {
        $tags = array_merge(
            $this->tracer->get(self::NAME),
            [self::NAME]
        );

        
private function generateKey(string $landingPageId, Request $request, SalesChannelContext $context): ?string
    {
        $parts = [...$request->query->all(), ...$request->request->all(), ...[$this->generator->getSalesChannelContextHash($context[RuleAreas::LANDING_PAGE_AREA, RuleAreas::PRODUCT_AREA, RuleAreas::CATEGORY_AREA])]];

        $event = new LandingPageRouteCacheKeyEvent($landingPageId$parts$request$context, null);
        $this->dispatcher->dispatch($event);

        if (!$event->shouldCache()) {
            return null;
        }

        return self::buildName($landingPageId) . '-' . md5(Json::encode($event->getParts()));
    }

    /** * @return array<string> */
    private function generateTags(string $landingPageId, LandingPageRouteResponse $response, Request $request, SalesChannelContext $context): array
    {
        $tags = array_merge(
            $this->tracer->get(self::buildName($landingPageId)),
            $this->extractIds($response),
            [self::buildName($landingPageId)]
        );
$this->generator->getCriteriaHash($criteria),
            $this->generator->getSalesChannelContextHash($context),
        ];

        $event = new CurrencyRouteCacheKeyEvent($parts$request$context$criteria);
        $this->dispatcher->dispatch($event);

        if (!$event->shouldCache()) {
            return null;
        }

        return self::buildName($context->getSalesChannelId()) . '-' . md5((string) Json::encode($event->getParts()));
    }

    /** * @return array<string> */
    private function generateTags(Request $request, StoreApiResponse $response, SalesChannelContext $context, Criteria $criteria): array
    {
        $tags = array_merge(
            $this->tracer->get(self::buildName($context->getSalesChannelId())),
            [self::buildName($context->getSalesChannelId()), self::ALL_TAG],
        );

        
$this->generator->getSalesChannelContextHash($context[RuleAreas::SHIPPING_AREA]),
            $request->query->getBoolean('onlyAvailable', false),
        ];

        $event = new ShippingMethodRouteCacheKeyEvent($parts$request$context$criteria);
        $this->dispatcher->dispatch($event);

        if (!$event->shouldCache()) {
            return null;
        }

        return self::buildName($context->getSalesChannelId()) . '-' . md5(Json::encode($event->getParts()));
    }

    /** * @return array<string> */
    private function generateTags(Request $request, StoreApiResponse $response, SalesChannelContext $context, Criteria $criteria): array
    {
        $tags = array_merge(
            $this->tracer->get(self::buildName($context->getSalesChannelId())),
            [self::buildName($context->getSalesChannelId()), self::ALL_TAG]
        );

        
public function getPreparedHeaders(): Headers
    {
        $headers = parent::getPreparedHeaders();
        $headers->setHeaderParameter('Content-Type', 'boundary', $this->getBoundary());

        return $headers;
    }

    public function bodyToString(): string
    {
        $parts = $this->getParts();
        $string = '';
        foreach ($parts as $part) {
            $string .= '--'.$this->getBoundary()."\r\n".$part->toString()."\r\n";
        }
        $string .= '--'.$this->getBoundary()."--\r\n";

        return $string;
    }

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