Get all environment variables or
a value of specified variable.

Using workaround because $_ENV could be empty
(depends on variables_order directive in PHP.ini)

@param string $variable (optional) Variable name
@return array|string
971614
public static function getEnv($variable = null) {
		$cmd = preg_match("/WIN/Ai", PHP_OS) ? 'set' : 'printenv';
		$output = self::run($cmd)->output;

		$env = [];

		foreach ($output as $line) {
			list($key, $value) = explode("=", $line, 2);

			if ($variable && strtolower($key) === strtolower($variable)) {
				return $value;
			}

			$env[$key] = $value;
		}

		return $env;
	}
1182195
public function getEnvironmentVariables(): array
    {
        if (!isset($this->xml->php->env)) {
            return [];
        }

        $variables = [];

        foreach ($this->xml->php->env as $env) {
            $variables[(string) $env['name']] = (string) $env['value'];
        }

        return $variables;
    }
1031784
public function values($variable)
    {
        foreach ($this->keywordList('VALUES') as $keyword) {
            if ($keyword->subKeys[0] == $variable) {
                return $keyword->values;
            }
        }
        throw new RuntimeException(sprintf('Could not determine values of "%s".', $variable));
    }
1317649
public static function getVariables()
    {
        // Suppress return by-ref
        $vars = [ 'env' => static::$env ];
        // needs to use a for loop, using `array_merge([], $GLOBALS);` left reference traces somehow
        foreach ($GLOBALS as $varName => $varValue) {
            $vars[$varName] = $varValue;
        }

        return $vars;
    }
854715
private static function get_process_env_variables() {
		// Ensure we're using the expected `wp` binary
		$bin_dir        = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( dirname( dirname( __DIR__ ) ) . '/bin' );
		$vendor_dir     = self::get_vendor_dir();
		$path_separator = Utils\is_windows() ? ';' : ':';
		$env            = array(
			'PATH'      => $bin_dir . $path_separator . $vendor_dir . $path_separator . getenv( 'PATH' ),
			'BEHAT_RUN' => 1,
			'HOME'      => sys_get_temp_dir() . '/wp-cli-home',
		);

		$config_path = getenv( 'WP_CLI_CONFIG_PATH' );
		if ( false !== $config_path ) {
			$env['WP_CLI_CONFIG_PATH'] = $config_path;
		}

		$term = getenv( 'TERM' );
		if ( false !== $term ) {
			$env['TERM'] = $term;
		}

		$php_args = getenv( 'WP_CLI_PHP_ARGS' );
		if ( false !== $php_args ) {
			$env['WP_CLI_PHP_ARGS'] = $php_args;
		}

		$php_used = getenv( 'WP_CLI_PHP_USED' );
		if ( false !== $php_used ) {
			$env['WP_CLI_PHP_USED'] = $php_used;
		}

		$php = getenv( 'WP_CLI_PHP' );
		if ( false !== $php ) {
			$env['WP_CLI_PHP'] = $php;
		}

		$travis_build_dir = getenv( 'TRAVIS_BUILD_DIR' );
		if ( false !== $travis_build_dir ) {
			$env['TRAVIS_BUILD_DIR'] = $travis_build_dir;
		}

		$github_token = getenv( 'GITHUB_TOKEN' );
		if ( false !== $github_token ) {
			$env['GITHUB_TOKEN'] = $github_token;
		}
		return $env;
	}
545545
public static function dumperGet(&$variable, $spacing = "") {
        if (is_array($variable)) {
            $type = "Array[" . count( $variable ) . "]";
        } elseif( is_object( $variable ) ) {
            ob_start();
            print_r($variable);
            return ob_get_clean();

        } elseif( gettype( $variable ) == "boolean" ) {
            return $variable ? "true" : "false";
        } elseif( is_null( $variable ) ) {
            return "NULL";
        } else {
            ob_start();
            var_dump($variable);
            return ob_get_clean();
        }
        $buf = $type;
        $spacing .= "    ";
        for (reset( $variable ); list ( $k, $v ) = each( $variable );) {
            if ($k === "GLOBALS" )
                continue;
            $buf .= "\n".$spacing.'['.$k.'] => ' . self::dumperGet( $v, $spacing);
        }

        return $buf;
    }
1329335
public function export($storageVariable)
    {
        return '$'.$storageVariable.' = ['.PHP_EOL.
            implode('', array_map(function (Requirement $requirement) use ($storageVariable) {
                if ($requirement->isRequired()) {
                    $dependencyName = $requirement->getDependency()->getName();

                    return '  '.var_export($dependencyName, true).
                        ' => '.
                        $this->dumpDependency($dependencyName, $storageVariable).
                        ','.PHP_EOL;
                }

                return '';
            }, $this->dependencies)).
            '];'.PHP_EOL;
    }
1028574
static boolean hasEnvironmentVariable(String variable) {
        final String value = System.getenv(variable);
        if (value != null) {
            return true;
        }
        return false;
    }
81749
public function compileVariable($variable)
    {
        if (strpos($variable, '(') == 0) {
            // not a variable variable
            $var = trim($variable, '\'');
            $this->tag_nocache = $this->tag_nocache |
                $this->template->ext->getTemplateVars->_getVariable($this->template, $var, null, true, false)->nocache;
            // todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache;
        }
        return '$_smarty_tpl->tpl_vars[' . $variable . ']->value';
    }
1100005
private function getConfigVariable($var, $default = null)
    {

        if (preg_match("/^SW_/", $var)) {
            $var = strtolower(preg_replace("/SW_/", "", $var));
        }

        if (isset($this->variables["config"][$var])) {
            return $this->variables["config"][$var];
        } else {
            if (defined("SW_" . strtoupper($var))) {
                return constant("SW_" . strtoupper($var));
            }
        }

        return $default;

    }
933871
public function env(string $var, $default = null)
    {
        $value = getenv($var) ?? null;

        if ($value === false) {
            return $default instanceof Closure ? $default() : $default;
        }

        switch (strtolower($value)) {
            case 'true':
            case '(true)':
                return true;
            case 'false':
            case '(false)':
                return false;
            case 'empty':
            case '(empty)':
                return '';
            case 'null':
            case '(null)':
                return null;
        }

        if (
            strlen($value) > 1
            && (0 === strpos($value, '"'))
            && (strlen($value) - 1 === strpos($value, '"'))
        ) {
            return substr($value, 1, -1);
        }

        return $value;
    }
250727
protected function getPhpConstant($variable, $constant)
    {
        return $this->computeServerVariable($variable, function () use ($variable, $constant) {
            $value = $this->bash->runRaw('php -r "echo '.$constant.';"');
            $this->localStorage->set($this->getVariablePath($variable), $value);

            return $value ?: constant($constant);
        });
    }
1211243
public function resolveEnv(string $template, array $variables = null)
    {
        if (is_null($variables)) {
            $variables = [];
        }
        
        $env = $this->getAutoBindings($template);
        // explicit-bound variables precedes to auto-bound variables.
        return array_merge($env, $variables);
    }
1064351
public static function Option($optionName = null, $envVariableName = null, $default = false) {
		if (empty($optionName) && empty($envVariableName)) {
			return $default;
		}

		if ($envVariableName == null) {
			$envVariableName = str_replace('-','_', strtoupper($optionName));
		}

		if (is_array($envVariableName)) {
			foreach($envVariableName as $envVariable) {
				$envval = getenv($envVariable);
				if ($envval) {
					return $envval;
				}
			}
		} else {
			$envval = getenv($envVariableName);
			if ($envval) {
				return $envval;
			}
		}

		if (empty($optionName)) {
			return $default;
		}

		return get_option($optionName, $default);
	}
287140
public function get($variable, $htmlEncode = true)
    {
        $value = null;

        if ( isset($this->variables[$variable]) ) {
            $value = $this->variables[$variable][$htmlEncode ? 'safe' : 'unsafe'];
        }

        return $value;
    }
1014157
protected function evalMethodDesc($variable)
    {
        $parts = explode('|', $variable);
        if (count($parts) < 2) {
            return null;
        }

        $method = $parts[1];
        return $this->commentMap[$method] ?? null;
    }
882317
public function getVar($key)
    {
        return (array_key_exists($key, $this->vars)) ? $this->vars[$key] : null;
    }