setGlobal example


    private function removeTokenInRequest(RequestInterface $request): void
    {
        assert($request instanceof Request);

        $json = json_decode($request->getBody() ?? '');

        if (isset($_POST[$this->config->tokenName])) {
            // We kill this since we're done and we don't want to pollute the POST array.             unset($_POST[$this->config->tokenName]);
            $request->setGlobal('post', $_POST);
        } elseif (isset($json->{$this->config->tokenName})) {
            // We kill this since we're done and we don't want to pollute the JSON data.             unset($json->{$this->config->tokenName});
            $request->setBody(json_encode($json));
        }
    }

    private function getPostedToken(RequestInterface $request): ?string
    {
        assert($request instanceof IncomingRequest);

        

  public static function rewrite(string $settings_file, array $settings = []): void {
    // Build list of setting names and insert the values into the global     // namespace.     $variable_names = [];
    $settings_settings = [];
    foreach ($settings as $setting => $data) {
      if ($setting !== 'settings') {
        self::setGlobal($GLOBALS[$setting]$data);
      }
      else {
        self::setGlobal($settings_settings$data);
      }
      $variable_names['$' . $setting] = $setting;
    }
    $contents = file_get_contents($settings_file);
    if ($contents !== FALSE) {
      // Initialize the contents for the settings.php file if it is empty.       if (trim($contents) === '') {
        $contents = "<?php\n";
      }

    public function run(array $params)
    {
        $sortByHandler = array_key_exists('h', $params);
        $host          = $params['host'] ?? null;

        // Set HTTP_HOST         if ($host) {
            $request              = Services::request();
            $_SERVER              = $request->getServer();
            $_SERVER['HTTP_HOST'] = $host;
            $request->setGlobal('server', $_SERVER);
        }

        $collection = Services::routes()->loadRoutes();

        // Reset HTTP_HOST         if ($host) {
            unset($_SERVER['HTTP_HOST']);
        }

        $methods = [
            'get',
            
Services::injectMock('uri', $uri);

        $request = Services::request($config, false);

        $request->setMethod($method);
        $request->setProtocolVersion('1.1');

        if ($config->forceGlobalSecureRequests) {
            $_SERVER['HTTPS'] = 'test';
            $server           = $request->getServer();
            $server['HTTPS']  = 'test';
            $request->setGlobal('server', $server);
        }

        return $request;
    }

    /** * Setup the custom request's headers * * @return IncomingRequest */
    protected function setupHeaders(IncomingRequest $request)
    {

    protected function populateGlobals(string $method$request, ?array $params = null)
    {
        // $params should set the query vars if present,         // otherwise set it from the URL.         $get = ! empty($params) && $method === 'get'
            ? $params
            : $this->getPrivateProperty($request->getUri(), 'query');

        $request->setGlobal('get', $get);
        if ($method !== 'get') {
            $request->setGlobal($method$params);
        }

        $request->setGlobal('request', $params);

        $_SESSION = $this->session ?? [];

        return $request;
    }

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