public function setKeyPattern($keyPattern)
    {
        $keyPattern = (string)$keyPattern;
        if ($this->keyPattern !== $keyPattern) {
            // validate pattern
            if ($keyPattern !== '') {
                ErrorHandler::start(E_WARNING);
                $result = preg_match($keyPattern, '');
                $error  = ErrorHandler::stop();
                if ($result === false) {
                    throw new Exception\InvalidArgumentException(
                        sprintf(
                            'Invalid pattern "%s"%s',
                            $keyPattern,
                            ($error ? ': ' . $error->getMessage() : '')
                        ),
                        0,
                        $error
                    );
                }
            }

            $this->keyPattern = $keyPattern;
        }

        return $this;
    }