public function escapeFieldPath($fieldPath)
    {
        if ($fieldPath instanceof FieldPath) {
            $parts = $fieldPath->path();

            $out = [];
            foreach ($parts as $part) {
                $out[] = $this->escapePathPart($part);
            }

            $fieldPath = implode('.', $out);
        } else {
            if (!preg_match(self::VALID_FIELD_PATH, $fieldPath)) {
                throw new \InvalidArgumentException('Paths cannot be empty and must not contain `*~/[]\`.');
            }
        }

        $this->validateFieldPath($fieldPath);
        return $fieldPath;
    }