getContents example

$this->assertRequestIsSigned($registrationRequest$secret);

        $app = $this->fetchApp($id);

        static::assertEquals(TestAppServer::APP_SECRET, $app->getAppSecret());

        static::assertEquals(2, $this->getRequestCount());

        $confirmationReq = $this->getPastRequest(1);
        static::assertEquals('POST', $confirmationReq->getMethod());

        $postBody = \json_decode($confirmationReq->getBody()->getContents(), true, 512, \JSON_THROW_ON_ERROR);
        static::assertEquals($secretAccessKey$postBody['secretKey']);

        $integration = $app->getIntegration();
        static::assertNotNull($integration);
        static::assertEquals($integration->getAccessKey()$postBody['apiKey']);

        static::assertEquals($_SERVER['APP_URL']$postBody['shopUrl']);
        static::assertEquals($this->shopIdProvider->getShopId()$postBody['shopId']);

        $json = \json_encode($postBody, \JSON_THROW_ON_ERROR);
        static::assertNotFalse($json);

        
class BlockTemplateLoader extends AbstractBlockTemplateLoader
{
    public function getTemplateForBlock(CmsExtensions $cmsExtensions, string $blockName): string
    {
        try {
            $templateFiles = (new Finder())
                ->files()
                ->name('preview.html')
                ->in(sprintf('%s/cms/blocks/%s', $cmsExtensions->getPath()$blockName));

            foreach ($templateFiles as $templateFile) {
                return $templateFile->getContents();
            }
        } catch (\Exception) {
        }

        throw new AppCmsExtensionException(sprintf('Preview file for block "%s" is missing', $blockName));
    }

    public function getStylesForBlock(CmsExtensions $cmsExtensions, string $blockName): string
    {
        try {
            $styleFiles = (new Finder())
                
->first();

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

        static::assertNotNull($mediaId);

        $media = $this->context->scope(Context::SYSTEM_SCOPE, fn (Context $context) => $this->getContainer()->get(FileLoader::class)->loadMediaFileStream($mediaId$context));

        static::assertInstanceOf(StreamInterface::class$media);
        static::assertNotNull($media->getContents());
    }

    public function testReadStaticGeneratedDocument(): void
    {
        $operation = new DocumentGenerateOperation($this->orderId, FileTypes::PDF, [], null, true);

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

        $generatedDocument = $this->documentGenerator->readDocument($invoiceStruct->getId()$this->context);

        
$this->endpoints['login'],
            [
                'query' => $this->getQueries($context),
                'json' => [
                    'shopwareId' => $shopwareId,
                    'password' => $password,
                    'shopwareUserId' => $userId,
                ],
            ]
        );

        $data = \json_decode($response->getBody()->getContents(), true, flags: \JSON_THROW_ON_ERROR);

        $userToken = new ShopUserTokenStruct(
            $data['shopUserToken']['token'],
            new \DateTimeImmutable($data['shopUserToken']['expirationDate'])
        );

        $accessTokenStruct = new AccessTokenStruct(
            $userToken,
            $data['shopSecret'] ?? null,
        );

        


            $parts = $this->extractProductionNamespaceParts($file$basePathParts);

            $path = implode('\\', $parts);
            if (mb_strpos($path, 'Recovery') === 0) {
                continue;
            }

            $namespace = rtrim('namespace Shopware\\' . $path, '\\');

            if (mb_strpos($file->getContents()$namespace) === false) {
                $relativePath = str_replace($basePath, '', $file->getPathname());
                $errors['src/' . $relativePath] = $namespace;
            }
        }

        $errorMessage = 'Expected the following files to have a correct namespace:' . \PHP_EOL . \PHP_EOL . print_r($errors, true);

        static::assertCount(0, $errors$errorMessage);
    }

    public function testNoGlobalExceptionDirectories(): void
    {


        try {
            $response = $this->client->request('POST', self::GOOGLE_CAPTCHA_VERIFY_ENDPOINT, [
                'form_params' => [
                    'secret' => $secretKey,
                    'response' => $request->get(self::CAPTCHA_REQUEST_PARAMETER),
                    'remoteip' => $request->getClientIp(),
                ],
            ]);

            $responseRaw = $response->getBody()->getContents();
            $response = json_decode($responseRaw, true);

            $thresholdScore = !empty($captchaConfig['config']['thresholdScore']) ? (float) $captchaConfig['config']['thresholdScore'] : self::DEFAULT_THRESHOLD_SCORE;

            return $response && (bool) $response['success'] && (float) $response['score'] >= $thresholdScore;
        } catch (ClientExceptionInterface) {
            return false;
        }
    }

    /** * {@inheritdoc} */
$signature = $header[0];

        if (empty($signature)) {
            throw new StoreSignatureValidationException(sprintf('Signature not found in header "%s"', $signatureHeaderName));
        }

        if (!$this->openSslVerifier->isSystemSupported()) {
            return $response;
        }

        if ($this->openSslVerifier->isValid($response->getBody()->getContents()$signature)) {
            $response->getBody()->rewind();

            return $response;
        }

        throw new StoreSignatureValidationException('Signature not valid');
    }
}
/** * @param class-string<AbstractResponse> $responseClass */
    public function request(string $url, SourcedPayloadInterface $payload, AppEntity $app, string $responseClass, Context $context): ?Struct
    {
        $optionRequest = $this->getRequestOptions($payload$app$context);

        try {
            $response = $this->client->post($url$optionRequest);

            $content = $response->getBody()->getContents();

            $transactionId = null;
            if ($payload instanceof PaymentPayloadInterface) {
                $transactionId = $payload->getOrderTransaction()->getId();
            }

            return $responseClass::create($transactionIdjson_decode($content, true, 512, \JSON_THROW_ON_ERROR));
        } catch (GuzzleException) {
            return null;
        }
    }

    
$response = RefundResponse::create($transactionId[
            'status' => 'complete',
        ]);

        $this->appendNewResponse($this->signResponse($response->jsonSerialize()));

        $this->paymentRefundProcessor->processRefund($refundId$salesChannelContext->getContext());

        /** @var Request $request */
        $request = $this->getLastRequest();
        $body = $request->getBody()->getContents();

        $appSecret = $this->app->getAppSecret();
        static::assertNotNull($appSecret);

        static::assertTrue($request->hasHeader('shopware-shop-signature'));
        static::assertSame(hash_hmac('sha256', $body$appSecret)$request->getHeaderLine('shopware-shop-signature'));
        static::assertNotEmpty($request->getHeaderLine('sw-version'));
        static::assertNotEmpty($request->getHeaderLine(AuthMiddleware::SHOPWARE_USER_LANGUAGE));
        static::assertNotEmpty($request->getHeaderLine(AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE));
        static::assertSame('POST', $request->getMethod());
        static::assertJson($body);
        
public function testReturnsResponseWithRewoundBody(): void
    {
        $response = new Response(200, ['X-Shopware-Signature' => 'v3rys3cr3t'], 'response body');

        $middleware = new VerifyResponseSignatureMiddleware(
            $this->createOpenSslVerifier(true, true)
        );

        $handledResponse = $middleware($response);

        static::assertSame($response$handledResponse);
        static::assertEquals('response body', $handledResponse->getBody()->getContents());
    }

    public function testReturnsResponseWithRewoundBodyIfSystemNotSupported(): void
    {
        $response = new Response(200, ['X-Shopware-Signature' => 'v3rys3cr3t'], 'response body');

        $middleware = new VerifyResponseSignatureMiddleware(
            $this->createOpenSslVerifier(false, true)
        );

        $handledResponse = $middleware($response);

        

    final public const SHOPWARE_APP_SIGNATURE = 'shopware-app-signature';

    final public const SHOPWARE_SHOP_SIGNATURE = 'shopware-shop-signature';

    public function signRequest(RequestInterface $request, string $secret): RequestInterface
    {
        if ($request->getMethod() !== 'POST') {
            return clone $request;
        }

        $body = $request->getBody()->getContents();

        $request->getBody()->rewind();

        if (!\strlen($body)) {
            return clone $request;
        }

        return $request->withAddedHeader(self::SHOPWARE_SHOP_SIGNATURE, $this->signPayload($body$secret));
    }

    public function isResponseAuthentic(ResponseInterface $response, string $secret): bool
    {

    public function __construct(int $hwm = 16384)
    {
        $this->hwm = $hwm;
    }

    public function __toString(): string
    {
        return $this->getContents();
    }

    public function getContents(): string
    {
        $buffer = $this->buffer;
        $this->buffer = '';

        return $buffer;
    }

    public function close(): void
    {
Request::METHOD_POST,
            '/swplatform/firstrunwizard/login',
            [
                'json' => [
                    'shopwareId' => $shopwareId,
                    'password' => $password,
                ],
                'query' => $this->optionsProvider->getDefaultQueryParameters($context),
            ]
        );

        return json_decode($response->getBody()->getContents(), true, flags: \JSON_THROW_ON_ERROR);
    }

    /** * @return array{shopUserToken: array{token: string, expirationDate: string}, shopSecret: string} */
    public function upgradeAccessToken(Context $context): array
    {
        if (!$context->getSource() instanceof AdminApiSource
            || $context->getSource()->getUserId() === null) {
            throw new \RuntimeException('First run wizard requires a logged in user');
        }

        
/** * @var string */
    protected $documentationLink;

    public function __construct(ClientException $exception)
    {
        $data = [];

        try {
            $data = json_decode($exception->getResponse()->getBody()->getContents(), true, 512, \JSON_THROW_ON_ERROR);
        } catch (\JsonException) {
        }

        parent::__construct($data['description'] ?? $exception->getMessage());

        $this->title = $data['title'] ?? '';
        $this->documentationLink = $data['documentationLink'] ?? '';
    }

    public function getStatusCode(): int
    {
        
private readonly array $tosUrls
    ) {
    }

    public function fetch(Request $request): string
    {
        $locale = $request->attributes->get('_locale');
        $uri = $this->tosUrls[$locale] ?? $this->tosUrls[InstallerLocaleListener::FALLBACK_LOCALE];

        $response = $this->guzzle->get($uri);

        return $response->getBody()->getContents();
    }
}
Home | Imprint | This part of the site doesn't use cookies.