PhpSandbox\PHPSandbox::whitelistSuperglobal PHP Méthode

whitelistSuperglobal() public méthode

You can pass a string of the superglobal name, or a string of the superglobal name and a string of the key, or pass an array of superglobal names, or an associative array of superglobal names and their keys to whitelist
public whitelistSuperglobal ( string | array $name, string $key = null )
$name string | array String of superglobal name, or an array of superglobal names, or an associative array of superglobal names and their keys to whitelist
$key string String of superglobal key to whitelist
    public function whitelistSuperglobal($name, $key = null)
    {
        if (is_string($name)) {
            $name = $this->normalizeSuperglobal($name);
        }
        if (is_string($name) && $name && !isset($this->whitelist['superglobals'][$name])) {
            $this->whitelist['superglobals'][$name] = [];
        }
        if (is_array($name)) {
            foreach ($name as $_name => $key) {
                if (is_int($_name)) {
                    if (is_string($key) && $key) {
                        $this->whitelist['superglobals'][$key] = [];
                    }
                } else {
                    $_name = $this->normalizeSuperglobal($_name);
                    if (is_string($_name) && $_name && !isset($this->whitelist['superglobals'][$_name])) {
                        $this->whitelist['superglobals'][$_name] = [];
                    }
                    if (is_string($key) && $key && isset($this->whitelist['superglobals'][$_name])) {
                        $this->whitelist['superglobals'][$_name][$key] = true;
                    } else {
                        if (isset($this->whitelist['superglobals'][$_name]) && is_array($key)) {
                            foreach ($key as $_key) {
                                if (is_string($_key) && $_key) {
                                    $this->whitelist['superglobals'][$_name][$_name] = true;
                                }
                            }
                        }
                    }
                }
            }
        } else {
            if (isset($this->whitelist['superglobals'][$name]) && is_array($key)) {
                foreach ($key as $_key) {
                    if (is_string($_key) && $_key) {
                        $this->whitelist['superglobals'][$name][$_key] = true;
                    }
                }
            } else {
                if (is_string($key) && $key && isset($this->whitelist['superglobals'][$name])) {
                    $this->whitelist['superglobals'][$name][$key] = true;
                }
            }
        }
        return $this;
    }
PHPSandbox