overrideGlobals example

$response->prepare($request);

        return $response;
    }

    /** * @return EnlightRequest */
    public function transformSymfonyRequestToEnlightRequest(SymfonyRequest $request)
    {
        // Overwrite superglobals with state of the SymfonyRequest         $request->overrideGlobals();

        $enlightRequest = EnlightRequest::createFromGlobals();
        $enlightRequest->setContent($request->getContent());
        $enlightRequest->setFiles($request->files->all());

        return $enlightRequest;
    }

    /** * Boots the Shopware and Symfony DI container * * @param bool $skipDatabase * * @throws Exception */
$this->disableHttpMethodParameterOverride();
    }

    public function testOverrideGlobals()
    {
        $request = new Request();
        $request->initialize(['foo' => 'bar']);

        // as the Request::overrideGlobals really work, it erase $_SERVER, so we must backup it         $server = $_SERVER;

        $request->overrideGlobals();

        $this->assertEquals(['foo' => 'bar']$_GET);

        $request->initialize([]['foo' => 'bar']);
        $request->overrideGlobals();

        $this->assertEquals(['foo' => 'bar']$_POST);

        $this->assertArrayNotHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER);

        $request->headers->set('X_FORWARDED_PROTO', 'https');

        
$bags = [
        'query' => 'Potentially unsafe keys removed from query string parameters (GET): %s',
        'request' => 'Potentially unsafe keys removed from request body parameters (POST): %s',
        'cookies' => 'Potentially unsafe keys removed from cookie parameters: %s',
      ];
      foreach ($bags as $bag => $message) {
        if (static::processParameterBag($request->$bag$safe_keys$log_sanitized_keys$bag$message)) {
          $update_globals = TRUE;
        }
      }
      if ($update_globals) {
        $request->overrideGlobals();
      }
      $request->attributes->set(self::SANITIZED, TRUE);
    }
    return $request;
  }

  /** * Processes a request parameter bag. * * @param \Symfony\Component\HttpFoundation\ParameterBag $bag * The parameter bag to process. * @param string[] $safe_keys * An array of keys to consider safe. * @param bool $log_sanitized_keys * Set to TRUE to log keys that are sanitized. * @param string $bag_name * The request parameter bag name. Either 'query', 'request' or 'cookies'. * @param string $message * The message to log if the parameter bag contains keys that are removed. * If the message contains %s that is replaced by a list of removed keys. * * @return bool * TRUE if the parameter bag has been sanitized, FALSE if not. */
            $form_state->setInvalidToken(TRUE);

            // Ignore all submitted values.             $form_state->setUserInput([]);

            $request = $this->requestStack->getCurrentRequest();
            // Do not trust any POST data.             $request->request = new ParameterBag();
            // Make sure file uploads do not get processed.             $request->files = new FileBag();
            // Ensure PHP globals reflect these changes.             $request->overrideGlobals();
          }
        }
      }
      else {
        $form_state->setProcessInput(FALSE);
      }

      // All form elements should have an #array_parents property.       $element['#array_parents'] = [];
    }

    
Home | Imprint | This part of the site doesn't use cookies.