invalidRequestParameter example

$quantity = $request->request->getInt('quantity', 1);

        $lineItem = new LineItem($identifier$type, null, $quantity);
        $label = $request->request->get('label');
        $description = $request->request->get('description');
        $removeable = (bool) $request->request->get('removeable', true);
        $stackable = (bool) $request->request->get('stackable', true);
        $payload = $request->request->all('payload');
        $priceDefinition = $request->request->all('priceDefinition');

        if ($label !== null && !\is_string($label)) {
            throw RoutingException::invalidRequestParameter('label');
        }

        if ($description !== null && !\is_string($description)) {
            throw RoutingException::invalidRequestParameter('description');
        }

        $lineItem->setLabel($label);
        $lineItem->setDescription($description);
        $lineItem->setRemovable($removeable);
        $lineItem->setStackable($stackable);
        $lineItem->setPayload($payload);

        
$this->dataValidator->validate($params$definition);

        return $this->downloadService->createFileResponse($context$params['fileId']$params['accessToken']);
    }

    #[Route(path: '/api/_action/import-export/cancel', name: 'api.action.import_export.cancel', methods: ['POST'])]     public function cancel(Request $request, Context $context): Response
    {
        $logId = $request->request->get('logId');

        if (!\is_string($logId)) {
            throw RoutingException::invalidRequestParameter('logId');
        }

        $this->importExportService->cancel($context$logId);
        $this->importExportFactory->create($logId)->abort();

        return new Response('', Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/import-export/prepare-template-file-download', name: 'api.action.import_export.template_file.prepare_download', methods: ['POST'])]     public function prepareTemplateFileDownload(Request $request, Context $context): Response
    {
        
return $this->renderStorefront('@Storefront/storefront/page/account/profile/recover-password.html.twig', [
            'page' => $page,
        ]);
    }

    #[Route(path: '/account/recover', name: 'frontend.account.recover.request', methods: ['POST'])]     public function generateAccountRecovery(Request $request, RequestDataBag $data, SalesChannelContext $context): Response
    {
        try {
            $mailData = $data->get('email');
            if (!$mailData instanceof DataBag) {
                throw RoutingException::invalidRequestParameter('email');
            }
            $mailData->set('storefrontUrl', $request->attributes->get(RequestTransformer::STOREFRONT_URL));

            $this->sendPasswordRecoveryMailRoute->sendRecoveryMail(
                $mailData->toRequestDataBag(),
                $context,
                false
            );

            $this->addFlash(self::SUCCESS, $this->trans('account.recoveryMailSend'));
        } catch (CustomerNotFoundException $e) {
            
private readonly array $cspTemplates
    ) {
    }

    #[Route(path: '/store-api/_info/openapi3.json', defaults: ['auth_required' => '%shopware.api.api_browser.auth_required_str%'], name: 'store-api.info.openapi3', methods: ['GET'])]     public function info(Request $request): JsonResponse
    {
        $apiType = $request->query->getAlpha('type', DefinitionService::TYPE_JSON_API);

        $apiType = $this->definitionService->toApiType($apiType);
        if ($apiType === null) {
            throw RoutingException::invalidRequestParameter('type');
        }

        $data = $this->definitionService->generate(OpenApi3Generator::FORMAT, DefinitionService::STORE_API, $apiType);

        return new JsonResponse($data);
    }

    #[Route(path: '/store-api/_info/open-api-schema.json', defaults: ['auth_required' => '%shopware.api.api_browser.auth_required_str%'], name: 'store-api.info.open-api-schema', methods: ['GET'])]     public function openApiSchema(): JsonResponse
    {
        $data = $this->definitionService->getSchema(OpenApi3Generator::FORMAT, DefinitionService::STORE_API);

        
/** * @covers \Shopware\Core\Framework\Routing\RoutingException * * @internal */
#[Package('core')] class RoutingExceptionTest extends TestCase
{
    public function testInvalidRequestParameter(): void
    {
        $e = RoutingException::invalidRequestParameter('foo');

        static::assertSame(Response::HTTP_BAD_REQUEST, $e->getStatusCode());
        static::assertSame(RoutingException::INVALID_REQUEST_PARAMETER_CODE, $e->getErrorCode());
    }

    /** * @DisabledFeatures("v6.6.0.0") * * @deprecated tag:v6.6.0.0 - will be removed */
    public function testInvalidRequestParameterLegacy(): void
    {
public static function fromRequest(int $extensionId, Request $request): ReviewStruct
    {
        $acceptGuidelines = $request->request->getBoolean('tocAccepted');
        $authorName = $request->request->get('authorName');
        $headline = $request->request->get('headline');
        $text = $request->request->get('text');
        $rating = $request->request->get('rating');
        $version = $request->request->get('version');

        if (!\is_string($authorName) || $authorName === '') {
            throw RoutingException::invalidRequestParameter('authorName');
        }

        if (!\is_string($headline) || $headline === '') {
            throw RoutingException::invalidRequestParameter('headline');
        }

        if (!\is_int($rating) || !$rating) {
            throw RoutingException::invalidRequestParameter('rating');
        }

        if (self::validateRatingValue($rating)) {
            
$download,
            $generatedDocument->getContentType()
        );
    }

    #[Route(path: '/api/_action/order/document/download', name: 'api.action.download.documents', methods: ['POST'], defaults: ['_acl' => ['document:read']])]     public function downloadDocuments(Request $request, Context $context): Response
    {
        $documentIds = $request->get('documentIds', []);

        if (!\is_array($documentIds) || empty($documentIds)) {
            throw RoutingException::invalidRequestParameter('documentIds');
        }

        $download = $request->query->getBoolean('download', true);
        $combinedDocument = $this->documentMerger->merge($documentIds$context);

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

        return $this->createResponse(
            $combinedDocument->getName(),
            


        if (empty($status)) {
            throw RoutingException::missingRequestParameter('status');
        }

        if (empty($message)) {
            throw RoutingException::missingRequestParameter('message');
        }

        if (!\is_array($requiredPrivileges)) {
            throw RoutingException::invalidRequestParameter('requiredPrivileges');
        }

        $integrationId = $source->getIntegrationId();
        $createdByUserId = $source->getUserId();

        try {
            $cacheKey = $createdByUserId ?? $integrationId . '-' . $request->getClientIp();
            $this->rateLimiter->ensureAccepted(self::NOTIFICATION, $cacheKey);
        } catch (RateLimitExceededException $exception) {
            throw new NotificationThrottledException($exception->getWaitTime()$exception);
        }

        
$params = [];
        if (!$request->request->has('email')) {
            throw RoutingException::missingRequestParameter('email');
        }

        $email = (string) $request->request->get('email');
        $isCustomerBoundSalesChannel = $this->systemConfigService->get('core.systemWideLoginRegistration.isCustomerBoundToSalesChannel');
        $boundSalesChannelId = null;
        if ($isCustomerBoundSalesChannel) {
            $boundSalesChannelId = $request->request->get('boundSalesChannelId');
            if ($boundSalesChannelId !== null && !\is_string($boundSalesChannelId)) {
                throw RoutingException::invalidRequestParameter('boundSalesChannelId');
            }
        }

        $customer = $this->getCustomerByEmail((string) $request->request->get('id')$email$context$boundSalesChannelId);
        if (!$customer) {
            return new JsonResponse(
                ['isValid' => true]
            );
        }

        $message = 'The email address {{ email }} is already in use';
        

        return Profiler::trace('cart::delete-line-items', function D) use ($cart$request$context) {
            try {
                $idData = $request->get('ids');
                if (!\is_array($idData) || $idData === []) {
                    throw RoutingException::missingRequestParameter('ids');
                }

                $ids = [];
                foreach ($idData as $key => $id) {
                    if (!\is_string($id)) {
                        throw RoutingException::invalidRequestParameter("ids[{$key}]");
                    }

                    $ids[] = $id;
                }

                $cart = $this->cartService->removeItems($cart$ids$context);

                if (!$this->traceErrors($cart)) {
                    $this->addFlash(self::SUCCESS, $this->trans('checkout.cartUpdateSuccess'));
                }
            } catch (\Exception) {
                
public function getDecorated(): AbstractCancelOrderRoute
    {
        throw new DecorationPatternException(self::class);
    }

    #[Route(path: '/store-api/order/state/cancel', name: 'store-api.order.state.cancel', methods: ['POST'], defaults: ['_loginRequired' => true, '_loginRequiredAllowGuest' => true])]     public function cancel(Request $request, SalesChannelContext $context): CancelOrderRouteResponse
    {
        $orderId = $request->get('orderId', null);

        if ($orderId === null) {
            throw RoutingException::invalidRequestParameter('orderId');
        }

        $this->verify($orderId$context);

        $newState = $this->orderService->orderStateTransition(
            $orderId,
            'cancel',
            new ParameterBag(),
            $context->getContext()
        );

        
private readonly DecoderInterface $serializer,
        private readonly DataValidator $dataValidator
    ) {
    }

    #[Route(path: '/api/_action/order/document/{documentTypeName}/create', name: 'api.action.document.bulk.create', methods: ['POST'], defaults: ['_acl' => ['document:create']])]     public function createDocuments(Request $request, string $documentTypeName, Context $context): JsonResponse
    {
        $documents = $this->serializer->decode($request->getContent(), 'json');

        if (empty($documents) || !\is_array($documents)) {
            throw RoutingException::invalidRequestParameter('Request parameters must be an array of documents object');
        }

        $operations = [];

        $definition = new DataValidationDefinition();
        $definition->addList(
            'documents',
            (new DataValidationDefinition())
                ->add('orderId', new NotBlank())
                ->add('fileType', new Choice([FileTypes::PDF]))
                ->add('config', new Type('array'))
                
Home | Imprint | This part of the site doesn't use cookies.