setServer example


    public function setHeader($key$value = null)
    {
        if ($value !== null) {
            $key = $this->_normalizeHeaderName($key);
            $this->headers->set($key(string) $value);
        } else {
            $this->headers->remove($key);
        }
        $this->setServer('HTTP_' . $key$value);

        return $this;
    }

    /** * Set request headers * * @return Enlight_Controller_Request_RequestTestCase */
    public function setHeaders(array $headers)
    {
        

        $config = config(App::class);
        $uri    = new SiteURI($config);

        // $path may have a query in it         $path  = URI::removeDotSegments($path);
        $parts = explode('?', $path);
        $path  = $parts[0];
        $query = $parts[1] ?? '';

        $superglobals = Services::superglobals();
        $superglobals->setServer('QUERY_STRING', $query);

        $uri->setPath($path);
        $uri->setQuery($query);

        Services::injectMock('uri', $uri);

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

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

        
$path = implode('/', $keep);
        }

        // This section ensures that even on servers that require the URI to         // contain the query string (Nginx) a correct URI is found, and also         // fixes the QUERY_STRING Server var and $_GET array.         if (trim($path, '/') === '' && strncmp($query, '/', 1) === 0) {
            $parts    = explode('?', $query, 2);
            $path     = $parts[0];
            $newQuery = $query[1] ?? '';

            $this->superglobals->setServer('QUERY_STRING', $newQuery);
        } else {
            $this->superglobals->setServer('QUERY_STRING', $query);
        }

        // Update our global GET for values likely to have been changed         parse_str($this->superglobals->server('QUERY_STRING')$get);
        $this->superglobals->setGetArray($get);

        return URI::removeDotSegments($path);
    }

    
&& !$options instanceof ArrayAccess
            && !$options instanceof Traversable
        ) {
            throw new Zend_Http_UserAgent_Exception(sprintf(
                'Invalid argument; expected array, Zend_Config object, or object implementing ArrayAccess and Traversable; received %s',
                (is_object($options) ? get_class($options) : gettype($options))
            ));
        }

        // Set $_SERVER first         if (isset($options['server'])) {
            $this->setServer($options['server']);
            unset($options['server']);
        }

        // Get plugin loaders sorted         if (isset($options['plugin_loader'])) {
            $plConfig = $options['plugin_loader'];
            if (is_array($plConfig) || $plConfig instanceof Traversable) {
                foreach ($plConfig as $type => $class) {
                    $this->setPluginLoader($type$class);
                }
            }
            
Home | Imprint | This part of the site doesn't use cookies.