Skip to content

Commit

Permalink
Replace Request::get with explicit input sources (#614)
Browse files Browse the repository at this point in the history
* cherrypick

* different
  • Loading branch information
kingjia90 authored Jan 23, 2025
1 parent 08f9265 commit 583a722
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 41 deletions.
20 changes: 10 additions & 10 deletions src/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function loginAction(
]);

//store referer in session to get redirected after login
if (!$request->get('no-referer-redirect')) {
if (!$request->query->getInt('no-referer-redirect')) {
$request->getSession()->set('_security.demo_frontend.target_path', $request->headers->get('referer'));
}

Expand Down Expand Up @@ -215,18 +215,18 @@ public function updateMarketingPermissionAction(
): RedirectResponse {
if ($user instanceof Customer) {
$currentNewsletterPermission = $user->getNewsletter()->getConsent();
if (!$currentNewsletterPermission && $request->get('newsletter')) {
if (!$currentNewsletterPermission && $request->request->getInt('newsletter')) {
$consentService->giveConsent($user, 'newsletter', $translator->trans('general.newsletter'));
$newsletterDoubleOptInService->sendDoubleOptInMail($user, $this->document->getProperty('newsletter_confirm_mail'));
} elseif ($currentNewsletterPermission && !$request->get('newsletter')) {
} elseif ($currentNewsletterPermission && !$request->request->getInt('newsletter')) {
$user->setNewsletterConfirmed(false);
$consentService->revokeConsent($user, 'newsletter');
}

$currentProfilingPermission = $user->getProfiling()->getConsent();
if (!$currentProfilingPermission && $request->get('profiling')) {
if (!$currentProfilingPermission && $request->request->getInt('profiling')) {
$consentService->giveConsent($user, 'profiling', $translator->trans('general.profiling'));
} elseif ($currentProfilingPermission && !$request->get('profiling')) {
} elseif ($currentProfilingPermission && !$request->request->getInt('profiling')) {
$consentService->revokeConsent($user, 'profiling');
}

Expand All @@ -246,7 +246,7 @@ public function confirmNewsletterAction(
NewsletterDoubleOptInService $newsletterDoubleOptInService,
Translator $translator
): RedirectResponse {
$token = $request->get('token');
$token = $request->query->getString('token');
$customer = $newsletterDoubleOptInService->handleDoubleOptInConfirmation($token);
if ($customer) {
$this->addFlash('success', $translator->trans('account.marketing-permissions-confirmed-newsletter'));
Expand All @@ -270,7 +270,7 @@ public function sendPasswordRecoveryMailAction(
if ($request->isMethod(Request::METHOD_POST)) {
try {
$service->sendRecoveryMail(
$request->get('email', ''),
$request->query->getString('email', ''),
$this->document->getProperty('password_reset_mail')
);

Expand All @@ -284,7 +284,7 @@ public function sendPasswordRecoveryMailAction(

return $this->render('account/send_password_recovery_mail.html.twig', [
'hideBreadcrumbs' => true,
'emailPrefill' => $request->get('email')
'emailPrefill' => $request->query->getString('email')
]);
}

Expand All @@ -296,7 +296,7 @@ public function resetPasswordAction(
PasswordRecoveryService $service,
Translator $translator
): RedirectResponse|Response {
$token = $request->get('token');
$token = $request->query->getString('token');
$customer = $service->getCustomerByToken($token);
$error = null;
try {
Expand All @@ -306,7 +306,7 @@ public function resetPasswordAction(

if ($request->isMethod(Request::METHOD_POST)) {

$newPassword = $request->get('password');
$newPassword = $request->request->getString('password');

$this->checkPassword($newPassword);

Expand Down
12 changes: 6 additions & 6 deletions src/Controller/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function getCart(): CartInterface
*/
public function addToCartAction(Request $request, Factory $ecommerceFactory): RedirectResponse
{
if (!$this->isCsrfTokenValid('addToCart', $request->request->get('_csrf_token'))) {
if (!$this->isCsrfTokenValid('addToCart', $request->request->getString('_csrf_token'))) {
throw new \Exception('Invalid request');
}

Expand Down Expand Up @@ -89,11 +89,11 @@ public function cartListingAction(
$cart = $this->getCart();

if ($request->getMethod() == Request::METHOD_POST) {
if (!$this->isCsrfTokenValid('cartListing', $request->get('_csrf_token'))) {
if (!$this->isCsrfTokenValid('cartListing', $request->request->getString('_csrf_token'))) {
throw new AccessDeniedHttpException('Invalid request');
}

$items = $request->get('items');
$items = $request->request->all('items');

foreach ($items as $itemKey => $quantity) {
if (!is_numeric($quantity)) {
Expand Down Expand Up @@ -128,7 +128,7 @@ public function cartListingAction(
*/
public function removeFromCartAction(Request $request, Factory $ecommerceFactory): RedirectResponse
{
if (!$this->isCsrfTokenValid('cartListing', $request->request->get('_csrf_token'))) {
if (!$this->isCsrfTokenValid('cartListing', $request->request->getString('_csrf_token'))) {
throw new \Exception('Invalid request');
}

Expand All @@ -155,7 +155,7 @@ public function removeFromCartAction(Request $request, Factory $ecommerceFactory
*/
public function applyVoucherAction(Request $request, Translator $translator, Factory $ecommerceFactory): RedirectResponse
{
if ($token = strip_tags($request->get('voucher-code'))) {
if ($token = strip_tags($request->request->getString('voucher-code'))) {
$cart = $this->getCart();

try {
Expand Down Expand Up @@ -183,7 +183,7 @@ public function applyVoucherAction(Request $request, Translator $translator, Fac
*/
public function removeVoucherAction(Request $request, Translator $translator, Factory $ecommerceFactory): RedirectResponse
{
if ($token = strip_tags($request->get('voucher-code'))) {
if ($token = strip_tags($request->query->getString('voucher-code'))) {
$cart = $this->getCart();

try {
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ public function checkoutCompletedAction(Request $request, Factory $ecommerceFact
*/
public function confirmationMailAction(Request $request)
{
$order = $request->get('order');
$order = $request->attributes->get('order');

if ($request->get('order-id')) {
$order = OnlineShopOrder::getById($request->get('order-id'));
if ($request->request->has('order-id')) {
$order = OnlineShopOrder::getById($request->request->getInt('order-id'));
}

return $this->render('checkout/confirmation_mail.html.twig', [
'order' => $order,
'ordernumber' => $request->get('ordernumber')
'ordernumber' => $request->request->getString('ordernumber')
]);
}
}
8 changes: 4 additions & 4 deletions src/Controller/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ public function tenantSwitchesAction(Request $request, Factory $ecommerceFactory
{
$environment = $ecommerceFactory->getEnvironment();

if ($request->get('change-checkout-tenant')) {
$checkoutTenant = $request->get('change-checkout-tenant');
if ($request->query->has('change-checkout-tenant')) {
$checkoutTenant = $request->query->getString('change-checkout-tenant');
$checkoutTenant = $checkoutTenant == 'default' ? '' : $checkoutTenant;
$environment->setCurrentCheckoutTenant(strip_tags($checkoutTenant));
$environment->save();
}

if ($request->get('change-assortment-tenant')) {
$assortmentTenant = $request->get('change-assortment-tenant');
if ($request->query->has('change-assortment-tenant')) {
$assortmentTenant = $request->query->getString('change-assortment-tenant');
$assortmentTenant = $assortmentTenant == 'default' ? '' : $assortmentTenant;
$environment->setCurrentAssortmentTenant(strip_tags($assortmentTenant));
$environment->save();
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function genericMailAction(): Response
public function galleryRenderletAction(Request $request): Response
{
$params = [];
if ($request->attributes->get('id') && $request->attributes->get('type') === 'asset') {
if ($request->attributes->getInt('id') && $request->attributes->getString('type') === 'asset') {
$params['asset'] = Asset::getById($request->attributes->getInt('id'));
}

Expand Down
12 changes: 6 additions & 6 deletions src/Controller/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function listingAction(Request $request, PaginatorInterface $paginator):

$paginator = $paginator->paginate(
$newsList,
$request->get('page', 1),
$request->query->getInt('page', 1),
6
);

Expand All @@ -57,7 +57,7 @@ public function listingAction(Request $request, PaginatorInterface $paginator):
*/
public function detailAction(Request $request, HeadTitle $headTitleHelper, Placeholder $placeholderHelper, NewsLinkGenerator $newsLinkGenerator, BreadcrumbHelperService $breadcrumbHelperService): Response
{
$news = News::getById($request->get('news'));
$news = News::getById($request->attributes->getInt('news'));

if (!($news instanceof News && ($news->isPublished() || $this->verifyPreviewRequest($request, $news)))) {
throw new NotFoundHttpException('News not found.');
Expand All @@ -76,8 +76,8 @@ public function detailAction(Request $request, HeadTitle $headTitleHelper, Place
public function newsTeaserAction(Request $request): Response
{
$paramsBag = [];
if ($request->get('type') === 'object') {
$news = News::getById($request->get('id'));
if ($request->attributes->getString('type') === 'object') {
$news = News::getById($request->attributes->getInt('id'));
$paramsBag['news'] = $news;

return $this->render('news/news_teaser.html.twig', $paramsBag);
Expand All @@ -89,8 +89,8 @@ public function newsTeaserAction(Request $request): Response
public function emailNewsTeaserAction(Request $request, NewsLinkGenerator $newsLinkGenerator): Response
{
$paramsBag = [];
if ($request->get('type') === 'object') {
$news = News::getById($request->get('id'));
if ($request->attributes->getString('type') === 'object') {
$news = News::getById($request->attributes->getInt('id'));
$paramsBag['news'] = $news;
$paramsBag['detailLink'] = $newsLinkGenerator->generate($news, ['document' => $this->document->getProperty('news_default_document')]);

Expand Down
10 changes: 5 additions & 5 deletions src/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ public function listingAction(
$trackingManager->trackCategoryPageView($category->getName(), null);
}

if ($request->get('filterdefinition') instanceof FilterDefinition) {
$filterDefinition = $request->get('filterdefinition');
if (isset($params['filterdefinition']) && $params['filterdefinition'] instanceof FilterDefinition) {
$filterDefinition = $params['filterdefinition'];
}

if (empty($filterDefinition)) {
Expand All @@ -178,7 +178,7 @@ public function listingAction(
// init pagination
$paginator = $paginator->paginate(
$productListing,
$request->get('page', 1),
$request->query->getInt('page', 1),
$filterDefinition->getPageLimit()
);

Expand All @@ -201,7 +201,7 @@ public function listingAction(
public function productTeaserAction(Request $request, Factory $ecommerceFactory): Response
{
$paramsBag = [];
$type = $request->attributes->get('type')?:$request->query->get('type');
$type = $request->attributes->getString('type')?:$request->query->getString('type');
if ($type === 'object') {
AbstractObject::setGetInheritedValues(true);
$id = $request->attributes->getInt('id')?:$request->query->getInt('id');
Expand Down Expand Up @@ -243,7 +243,7 @@ public function searchAction(
$productListing = $indexService->getProductListForCurrentTenant();
$productListing->setVariantMode(ProductListInterface::VARIANT_MODE_VARIANTS_ONLY);

$term = strip_tags($request->query->get('term'));
$term = strip_tags($request->query->getString('term'));

if ($productListing instanceof AbstractElasticSearch) {

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Web2printController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function productPrintAction(Request $request): Response
$params['product'] = $obj;
$html = $this->renderView('web2print/product_detail.html.twig', $params);

if ($request->get('html')) {
if ($request->query->getInt('html')) {
return new Response($html);
}

Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/UserSessionPerspectiveListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UserSessionPerspectiveListener extends UserPerspectiveListener
protected function setRequestedPerspective(User $user, Request $request): void
{
// update perspective settings
$requestedPerspective = $request->get('perspective');
$requestedPerspective = $request->query->getString('perspective');
$sessionPerspective = $request->getSession()->get('sessionPerspective');

if ($requestedPerspective) {
Expand Down
6 changes: 3 additions & 3 deletions src/Twig/Extension/LanguageSwitcherExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ public function getLocalizedLinks(Document $document): array
}
}

$route = $request->get('_route');
$route = $request->attributes->getString('_route');

if ($route && array_key_exists($route, $dynamicRoutesMapping)) {
$routeParams = $request->get('_route_params', []);
$routeParams = $request->attributes->all('_route_params');
$requiredField = $dynamicRoutesMapping[$route]['requiredField'];

if (!array_key_exists($requiredField, $routeParams)){
continue;
}

$generator = $dynamicRoutesMapping[$route]['generator'];
$object = $request->get($requiredField);
$object = $request->attributes->get($requiredField);

if (!is_object($object)) {
$object = DataObject::getById($object);
Expand Down

0 comments on commit 583a722

Please sign in to comment.