44 parent::__construct(
'', $status,
$headers);
47 $data = new \ArrayObject();
96 $pattern =
'/^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]*(?:\[(?:"(?:\\\.|[^"\\\])*"|\'(?:\\\.|[^\'\\\])*\'|\d+)\])*?$/u';
98 'break',
'do',
'instanceof',
'typeof',
'case',
'else',
'new',
'var',
'catch',
'finally',
'return',
'void',
'continue',
'for',
'switch',
'while',
99 'debugger',
'function',
'this',
'with',
'default',
'if',
'throw',
'delete',
'in',
'try',
'class',
'enum',
'extends',
'super',
'const',
'export',
100 'import',
'implements',
'let',
'private',
'public',
'yield',
'interface',
'package',
'protected',
'static',
'null',
'true',
'false',
103 foreach ($parts as $part) {
104 if (!preg_match($pattern, $part) || in_array($part, $reserved,
true)) {
105 throw new \InvalidArgumentException(
'The callback name is not valid.');
142 if (defined(
'HHVM_VERSION')) {
146 $data = json_encode(
$data, $this->encodingOptions);
152 $data = json_encode(
$data, $this->encodingOptions);
153 }
catch (\Exception $e) {
154 if (
'Exception' === get_class($e) && 0 === strpos($e->getMessage(),
'Failed calling ')) {
155 throw $e->getPrevious() ?: $e;
161 if (JSON_ERROR_NONE !== json_last_error()) {
162 throw new \InvalidArgumentException(json_last_error_msg());
189 return $this->
setData(json_decode($this->data));
199 if (
null !== $this->callback) {
201 $this->headers->set(
'Content-Type',
'text/javascript');
203 return $this->
setContent(sprintf(
'/**/%s(%s);', $this->callback, $this->data));
208 if (!$this->headers->has(
'Content-Type') ||
'text/javascript' === $this->headers->get(
'Content-Type')) {
209 $this->headers->set(
'Content-Type',
'application/json');