public function setQuery($query, $rawString = false)
    {
        if ($query instanceof Query) {
            $this->query = $query;
        } elseif (is_string($query)) {
            if (!$rawString) {
                $this->query = Query::fromString($query);
            } else {
                // Ensure the query does not have illegal characters.
                $this->query = preg_replace_callback(
                    self::$queryPattern,
                    [__CLASS__, 'encodeMatch'],
                    $query
                );
            }

        } elseif (is_array($query)) {
            $this->query = new Query($query);
        } else {
            throw new \InvalidArgumentException('Query must be a Query, '
                . 'array, or string. Got ' . Core::describeType($query));
        }
    }