MatthiasMullie\Scrapbook\Adapters\Memcached::encodeKey PHP Method

encodeKey() protected method

We encode spaces and line breaks to avoid protocol errors. We encode the other control characters for compatibility with libmemcached verify_key. We leave other punctuation alone, to maximise backwards compatibility.
See also: https://github.com/wikimedia/mediawiki/commit/be76d869#diff-75b7c03970b5e43de95ff95f5faa6ef1R100
See also: https://github.com/wikimedia/mediawiki/blob/master/includes/libs/objectcache/MemcachedBagOStuff.php#L116
protected encodeKey ( string $key ) : string
$key string
return string
    protected function encodeKey($key)
    {
        $regex = '/[^\\x21\\x22\\x24\\x26-\\x39\\x3b-\\x7e]+/';
        $key = preg_replace_callback($regex, function ($match) {
            return rawurlencode($match[0]);
        }, $key);
        if (strlen($key) > 255) {
            throw new InvalidKey("Invalid key: {$key}. Encoded Memcached keys can not exceed 255 chars.");
        }
        return $key;
    }