src/Valkyrja/Http/NativeJsonResponse.php
public function setCallback(string $callback = null): JsonResponse
    {
        if (null !== $callback) {
            // taken from http://www.geekality.net/2011/08/03/valid-javascript-identifier/
            $pattern = '/^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]*+$/u';
            $parts   = explode('.', $callback);

            foreach ($parts as $part) {
                if (! preg_match($pattern, $part)) {
                    throw new \InvalidArgumentException(
                        'The callback name is not valid.'
                    );
                }
            }
        }

        $this->callback = $callback;

        return $this->update();
    }
public function setCallback(string $callback = null): JsonResponse
    {
        if (null !== $callback) {
            // taken from http://www.geekality.net/2011/08/03/valid-javascript-identifier/
            $pattern = '/^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]*+$/u';
            $parts   = explode('.', $callback);

            foreach ($parts as $part) {
                if (! preg_match($pattern, $part)) {
                    throw new \InvalidArgumentException(
                        'The callback name is not valid.'
                    );
                }
            }
        }

        $this->callback = $callback;

        return $this->update();
    }
Sets the JSONP callback.

@param string $callback [optional] The JSONP callback or null to use none

@throws \InvalidArgumentException When the callback name is not valid

@return \Valkyrja\Http\JsonResponse