Parse given parameters with custom prefix

@param mixed[] $variables
@return mixed[]
509163
public static function parseParameters(array $variables, string $prefix): array
	{
		$map = function (&$array, array $keys, $value) use (&$map) {
			if (count($keys) <= 0) return $value;

			$key = array_shift($keys);

			if (!is_array($array)) {
				throw new InvalidStateException(sprintf('Invalid structure for key "%s" value "%s"', implode($keys), $value));
			}

			if (!array_key_exists($key, $array)) {
				$array[$key] = [];
			}

			// Recursive
			$array[$key] = $map($array[$key], $keys, $value);

			return $array;
		};

		$parameters = [];
		foreach ($variables as $key => $value) {
			// Ensure value
			$value = getenv($key);
			if (strpos($key, $prefix) === 0 && $value !== false) {
				// Parse PREFIX{delimiter=__}{NAME-1}{delimiter=__}{NAME-N}
				$keys = static::parseParameter(substr($key, strlen($prefix)));
				// Make array structure
				$map($parameters, $keys, $value);
			}
		}

		return $parameters;
	}
938025
protected function getSforInVariableNode($variable)
    {
        $env = new \Twig_Environment(new \Twig_Loader_Array());
        $parser = new \Twig_Parser($env);
        $lexer = new \Twig_Lexer($env);
        $stream = $lexer->tokenize(new \Twig_Source('{{'.$variable.'}}', 'variables'));

        return $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr')->getNode('node');
    }
574728
public function variables(array $variables)
    {
        $this->options['variables'] = Arr::mergeRecursive(
            $this->options['variables'] ?? [],
            $variables
        );

        return $this;
    }
312551
protected function prepareVariables(array $variables)
    {
        // My kingdom for a generator.
        $ret = [];
        foreach ($variables as $name => $val) {
            if ($this->showItem($name)) {
                $fname = '$' . $name;
                $ret[$fname] = [
                    'name'  => $fname,
                    'style' => \in_array($name, self::$specialNames) ? self::IS_PRIVATE : self::IS_PUBLIC,
                    'value' => $this->presentRef($val),
                ];
            }
        }

        return $ret;
    }
312535
public function codes($variable)
    {
        foreach ($this->keywordList('CODES') as $keyword) {
            if ($keyword->subKeys[0] == $variable) {
                return $keyword->values;
            }
        }

        return null;
    }
580653
protected function _parseVariableInParameters($parameter) {
        return preg_replace_callback('`' . preg_quote($this->markup['vars'][0]) . $this->_space . '([\[\]\(\)A-Za-z0-9\$\'._>\+-:\\\\]+)' . $this->_space . preg_quote($this->markup['vars'][1]) . '`', ['Gcs\Framework\Core\Template\Parser', '_parseVariableInParametersCallback'], $parameter);
    }
518284
private static function parseVariablePattern(string $patern) : array
    {
        static $supported_types = [
            'string',
            'integer',
            'int',
            'float',
            'double',
            'boolean',
            'bool',
        ];
    
        $tmp = explode(':',$patern);
        $varname = $tmp[1] ?? null;
        $regex   = $tmp[2] ?? null;
        $type    = $tmp[3] ?? null;
        
        if (!preg_match('/^[a-zA-Z_][0-9a-zA-Z_]*(\[\])?$/',$varname)){
            throw new RoutingRuleParseException($patern, "illegal variable name: $varname");
        }
        if ($regex && !preg_match('/^[0-9a-zA-Z@#_=%\\\^\$\.\[\]\|\(\)\?\*\+\{\}\^\-]*$/',$regex)){
            throw new RoutingRuleParseException($patern, "illegal variable regex pattern: $regex");
        }
        if ($type && !in_array($type,$supported_types)){
            throw new RoutingRuleParseException($patern, "unsupported variable type: $type");
        }
        
        $res = [];
        
        if ($varname){
            $res['varname'] = $varname;
        }
        if ($regex){
            $res['regex'] = $regex;
        }
        if ($type){
            $res['type'] = $type;
        }
    
        return $res;
    }
603549
private function resolveKey($keys)
    {
        if (is_array($keys)) {
            $result = [];
            foreach ($keys as $key) {
                $result[] = $this->prefix . $key;
            }

            return $result;
        }

        return $this->prefix . $keys;
    }
408242
protected function parseTemplate($variables = [], $template = null)
    {
        if (null === $template) $template = 'migration';
        $replacements = array_merge($variables, $this->templateVariables);
        return strtr(file_get_contents(dirname(__DIR__) . '/templates/' . $template . '.tpl'), $replacements);
    }
881351
protected function getJSTemplateVars($vars)
    {
        if (is_array($vars)) {
            return $vars;
        }
        
        if ($this->hasMethod($vars)) {
            return $this->{$vars}();
        }
        
        return [];
    }
381359
private function filterVariablesUsedAsPlaceholders($string, array $variables)
    {
        if (empty($string)) {
            return $variables;
        }

        // array_filter() is not used because ARRAY_FILTER_USE_KEY requires PHP 5.6
        $filteredVariables = array();
        foreach ($variables as $key => $value) {
            if (false === strpos($string, '{'.$key.'}')) {
                $filteredVariables[$key] = $value;
            }
        }

        return $filteredVariables;
    }
1322175
public function variables(array $variables) {
	    foreach($variables as $name => $value) {
	        $this->variable($name, $value);
	    }
	    return $this;
	}
882240
public function createFiltersMethods(array $names, $variable)
    {
        if($names === array())
        {
            return $variable;
        }

        $filter = array_shift($names);

        if($filter === 'raw')
        {
            $result = $this->createFiltersMethods($names, $variable);
        }
        else
        {
            $begin = '';
            $end   = '';

            if(function_exists($filter))
            {
                $begin = "{$filter}(";
            }
            else
            {
                $begin = "\$env->filter('{$filter}', ";
            }

            $result = $begin.$this->createFiltersMethods($names, $variable).')';
        }

        return $result;
    }
957775
private function prefixPaths (array $paths, string $prefix) : array
    {
        $result = [];

        foreach ($paths as $namespace => $path)
        {
            $result[$namespace] = "{$prefix}/" . trim($path, "/");
        }

        return $result;
    }
1289588
private function parseParameters(array $parameters)
    {
        if (empty($parameters)) {
            return '';
        }

        $parameters = implode('&', array_map(
            function ($value, $key) {
                return sprintf('%s=%s', $key, urlencode($value));
            },
            $parameters,
            array_keys($parameters)
        ));

        return "&{$parameters}";
    }
617330
private function getMethodsContainsVariable(array $methods, $variableName)
    {
        $methodsWithVariable = [];

        foreach ($methods as $method) {
            $propertyPostfixes = $method->findChildrenOfType('PropertyPostfix');

            /** @var AbstractNode $propertyPostfix */
            foreach ($propertyPostfixes as $propertyPostfix) {
                $identifier = $propertyPostfix->getFirstChildOfType('Identifier');

                if (null === $identifier) {
                    continue;
                }

                if ($variableName === $identifier->getName()) {
                    $methodsWithVariable[] = $method;

                    break;
                }
            }
        }

        return $methodsWithVariable;
    }
1371246
private function sanitizeParam($var): array
    {
        if (\is_object($var)) {
            $className = \get_class($var);

            return method_exists($var, '__toString') ?
                [sprintf('/* Object(%s): */"%s"', $className, $var->__toString()), false] :
                [sprintf('/* Object(%s) */', $className), false];
        }

        if (\is_array($var)) {
            $a = [];
            $original = true;
            foreach ($var as $k => $v) {
                list($value, $orig) = $this->sanitizeParam($v);
                $original = $original && $orig;
                $a[$k] = $value;
            }

            return [$a, $original];
        }

        if (\is_resource($var)) {
            return [sprintf('/* Resource(%s) */', get_resource_type($var)), false];
        }

        return [$var, true];
    }