TODO

@param $url
@param $key
@param $value
@return string
960348
public function addParameterToURL($url, $key, $value)
    {
        $key = urlencode($key);
        $value = urlencode($value);
        if (strrpos($url, '?') > 0) {
            $url .= "&$key=$value";
        } else {
            $url .= "?$key=$value";
        }

        return $url;
    }
318760
private function buildProperty($value, $key): string
    {
        if (collect(['from', 'to'])->contains($key)) {
            $value = $this->implode($value);
        }

        return vsprintf("<apps:property name='%s' value='%s'/>", [
            $key,
            htmlentities($this->implode($value)),
        ]);
    }
510769
static function addUrlParam($url, $key, $val)
    {
        // Separate the anchor element from the URL if it exists.
        $urlParts = parse_url($url);
        if(isset($urlParts['fragment'])){
            $url = str_replace('#'.$urlParts['fragment'], '', $url);
        }

        $separator = (parse_url($url, PHP_URL_QUERY) == NULL) ? '?' : '&';
        $url .= $separator.$key.'='.$val;

        // Add the anchor back to the URL.
        if(isset($urlParts['fragment'])){
            $url .= '#'.$urlParts['fragment'];
        }

        return $url;
    }
1073411
private static function generateQueryString($key, $value)
    {
        // Query string separators ("=", "&") within the key or value need to be encoded
        // (while preventing double-encoding) before setting the query string. All other
        // chars that need percent-encoding will be encoded by withQuery().
        $queryString = strtr($key, self::$replaceQuery);

        if ($value !== null) {
            $queryString .= '=' . strtr($value, self::$replaceQuery);
        }

        return $queryString;
    }
69996
public function replace($path, $key, $value) {
        $path = str_replace(s('{%s}', $key), $value, $path);

        return $path;
    }
996373
public static function setVar($key, $value)
    {
        $var = new Vars($key);
        $var->key = $key;
        $var->value = $value;
        return $var->save();
    }
1129479
private function parseArray(string $key, $value): string
    {
        return sprintf('%s%s%s', $key, $this->delimiter, implode(',', $value));
    }
595672
public function setUrlParameter($key, $value = null)
    {
        Argument::i()
            //argument 1 must be a string or array
            ->test(1, 'array', 'string')
            //argument 2 must be scalar
            ->test(2, 'scalar');

        if (is_array($key)) {
            $this->param = $key;
            return $this;
        }

        $this->param[$key] = $value;
    }
553953
private function parseValue(string $key, $value): string
    {

        if (is_array($value)) {
            return $this->parseArray($key, $value);
        }

        return $this->parseScalar($key, $value);
    }
788959
public function put(string $key, $value)
    {
        $this->cache[$this->hashKey($key)] = $value;
        return $value;
    }
966330
protected function getKeyValuePair($key, $value)
    {
        if (strpos($value, '"') !== false) {
            return ' ' . $key . '=\'' . $value . '\'';
        }
        return ' ' . $key . '="' . $value . '"';
    }
26745
public static function prepare($key, $value)
    {
        if ($value == 'true') {
            return true;
        } elseif ($value == 'false') {
            return false;
        } elseif ($key == 'debug.level' && substr($value, 0, 2) == "E_") {
            return eval('return ' . $value . ';');
        } elseif ($key == 'application.path' && ($value === false || $value === 'false' || $value === 'auto')) {
            $sLibraryPath = DS . 'vendor' . DS . 'pabana' . DS . 'pabana' . DS . 'src' . DS . 'Core';
            return str_replace($sLibraryPath, '', __DIR__);
        }
        return $value;
    }
1025608
private function parseHeader(string $key, $value)
    {
        switch ($key) {
            case 'msgno':
                return (int) $value;
            case 'from':
            case 'to':
            case 'cc':
            case 'bcc':
            case 'reply_to':
            case 'sender':
            case 'return_path':
                /** @var \stdClass $address */
                foreach ($value as $address) {
                    if (isset($address->mailbox)) {
                        $address->host     = $address->host ?? null;
                        $address->personal = isset($address->personal) ? $this->decode($address->personal) : null;
                    }
                }

                return $value;
            case 'date':
            case 'subject':
                return $this->decode($value);
        }

        return $value;
    }
1252935
private function parseParameter(string $key, string $value, &$params): string
    {
        if (isset($params[$key])) {
            $par = $params[$key];
            unset($params[$key]);

            $value = $value ? $value . '_' . $par : $par;
        }

        return static::makeParam($key, $value);
    }
712217
public function dismissUrl(string $key, string $url = null): string
    {
        return $this->s::restActionUrl('§dismiss-notice', $key, $url);
    }
2253
public function addRequestHeader($key, $value = null)
    {
        if (is_array($key)) {
            foreach ($key as $newKey => $newValue) {
                $this->addRequestHeader($newKey, $newValue);
            }
        } else {
            $key = preg_replace_callback(
                '/([\s\-_]|^)([a-z0-9-_])/',
                function ($match) {
                    return strtoupper($match[0]);
                },
                $key
            );
            $this->requestHeader[] = "$key: $value";
        }
    }
1267080
public function post($key = null, $value = null)
    {
        if (!is_null($this->except)) {
            $this->skip();
        }

        if (!is_null($key) && !string_has($key, '.') && is_null($value)) {
            $postValue = '';
            $key = $this->security->sanitize($key);
            $postValue = $this->security->sanitize($this->request['post'][$key]);
            $this->request['post'][$key] = $postValue;

            if (array_key_exists($key, $this->request['post'])) {
                return $this->request['post'][$key];
            }

            throw new InvalidArgumentException("Invalid key $key passed to ".__METHOD__);
        }

        /*
         | User can access post array element by passing
         | key as dot separator with index
         | ['user' => ['name' => 'foo']]
         |
         | $input->post('user.name'); // output: foo
         */
        if (!is_null($key) && string_has($key, '.') && is_null($value)) {
            $arr = ArrayAccessor::make($this->request['post']);

            return $arr->toString($this->security->sanitize($key));
        }

        $this->setPostValue($key, $value);

        if (is_null($key)) {
            $postArr = $this->security->sanitize($this->request['post']);

            return (!empty($postArr)) ? $postArr : null;
        }
    }