Encodes the input as JSONP and sets the Content-Type header to application/javascript.

@param mixed $input
@param string $callback
@return self
484405
public function jsonp($input, $callback)
    {
        return $this
            ->withHeader('Content-Type', 'application/javascript')
            ->write(sprintf('%s(%s);', $callback, json_encode($input)));
    }
215072
public function setInput($input)
    {
        $this->input = ProcessUtils::validateInput(sprintf('%s::%s', __CLASS__, __FUNCTION__), $input);

        return $this;
    }
481777
private function getInput($key, $jsonInput)
    {
        if ($jsonInput) {
            $input = Input::json($key);
        } elseif (Input::file($key)) {
            $input = Input::file($key);
        } else {
            $input = Input::get($key);
        }

        return $input;
    }
750076
public function setCallback($callback)
    {
        // If the provided $value is not a closure, make it one now for easy resolution.
        if (!is_callable($callback)) {
            $callback = function () use ($callback) {
                return $callback;
            };
        }

        if ($this->protected) {
            return $this;
        }

        $this->callback = $callback;

        return $this;
    }
1108357
public function sendPayload($payload, $callback)
    {
        if (!is_string($payload)) {
            throw new \InvalidArgumentException('Payload must be string.');
        }

        try {
            $res = $this->client->post($this->host, [
                'headers' => [
                    'content-type' => 'application/json'
                ],
                'body' => $payload,
                'timeout' => $this->timeout,
                'connect_timeout' => $this->timeout
            ]);
            /**
             * @var StreamInterface $stream ;
             */
            $stream = $res->getBody();
            $json = json_decode($stream);
            $stream->close();

            if (JSON_ERROR_NONE !== json_last_error()) {
                call_user_func($callback, new InvalidArgumentException('json_decode error: ' . json_last_error_msg()), null);
            }
            if (is_array($json)) {
                // batch results
                $results = [];
                $errors = [];

                foreach ($json as $result) {
                    if (property_exists($result,'result')) {
                        $results[] = $result->result;
                    } else {
                        if (isset($json->error)) {
                            $error = $json->error;
                            $errors[] = new RPCException(mb_ereg_replace('Error: ', '', $error->message), $error->code);
                        } else {
                            $results[] = null;
                        }
                    }
                }
                if (count($errors) > 0) {
                    call_user_func($callback, $errors, $results);
                } else {
                    call_user_func($callback, null, $results);
                }
            } elseif (property_exists($json,'result')) {
                call_user_func($callback, null, $json->result);
            } else {
                if (isset($json->error)) {
                    $error = $json->error;

                    call_user_func($callback, new RPCException(mb_ereg_replace('Error: ', '', $error->message), $error->code), null);
                } else {
                    call_user_func($callback, new RPCException('Something wrong happened.'), null);
                }
            }
        } catch (RequestException $err) {
            call_user_func($callback, $err, null);
        }
    }
797226
public function jsonp($callback, $data = [], $status = 200, array $headers = [], $options = 0)
    {
        return $this->json($data, $status, $headers, $options)->setCallback($callback);
    }
1074278
public function setInput($input)
    {
        if ($this->linebuffer === $input) {
            return $this;
        }

        // remember old input length if echo replacement is used
        $oldlen = (is_string($this->echo)) ? $this->strlen($this->linebuffer) : null;

        $this->linebuffer = $input;
        $this->linepos = $this->strlen($this->linebuffer);

        // only redraw if input should be echo'ed (i.e. is not hidden anyway)
        // and echo replacement is used, make sure the input length changes
        if ($this->echo !== false && $this->linepos !== $oldlen) {
            $this->redraw();
        }

        return $this;
    }
55217
public static function register($event, $callback)
	{
		// make sure we're setting the correct events
		$event = str_replace(array('before', 'after', 'validate'), array('before_save', 'after_save', 'after_validation'), $event);

		static::$upload->register($event, $callback);
	}
625805
protected function renderJson($data, $callback = null, $status = 200, $headers = array()) {
		// Check if a output action has be already performed
		$this->_checkIfPerformed();

		// Create a JSON response
		$jsonResponse = \Symfony\Component\HttpFoundation\JsonResponse::create($data, $status, $headers);

		// Set callback
		if ( null !== $callback )
			$jsonResponse->setCallback($callback);

		// Add request informationen
		$jsonResponse->prepare($this->application->requestStack->getCurrentRequest());

		// Replace response object
		$this->application->response = $jsonResponse;
	}
955989
public function update($callbackId, CallbackBuilder $input, array $queryParams = [])
    {
        $response = $this->api->callbacks()->update($callbackId, $input->toArray(), $queryParams);

        return new CallbackResponse($response);
    }
130680
public static function callback($key = null, $callback)
    {
        // Get parameters for callback
        $callbackParams = func_get_args();
        unset($callbackParams[0], $callbackParams[1]);
        $callbackParams = array_values($callbackParams);

        // Get key if no key is given
        if (is_null($key)) {
            if (is_string($callback)) {
                $key = $callback;
            } elseif (is_array($callback)) {
                $keyArr = [];
                foreach ($callback as $k => $v) {
                    if (is_string($v)) {
                        $keyArr[] = $v;
                    } elseif (is_object($v)) {
                        $keyArr[] = get_class($v);
                    }
                }

                $key = implode('', $keyArr);
                if (count($keyArr) > 1) {
                    $method = array_pop($keyArr);
                    $key    = implode('/', $keyArr);
                    $key    .= '::' . $method;
                }

                unset($keyArr, $method);
            } elseif (is_object($callback) && $callback instanceof \Closure) {
                $key = 'closure';
            }
            $key = 'callback: ' . $key;
        }

        // Set default return value
        $returnValue = true;

        // Set error handler, to convert errors to exceptions
        set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) {
            throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
        });

        try {
            // Start output buffer to capture any output
            ob_start();

            // Start profiler
            self::start($key);

            // Execute callback, and get result
            $callbackResult = call_user_func_array($callback, $callbackParams);

            // Stop profiler
            self::stop($key);

            // Get and clean output buffer
            $callbackOutput = ob_get_clean();
        } catch (\ErrorException $callbackException) {
            // Stop and clean output buffer
            ob_end_clean();

            // Show error message
            self::output('Invalid callback sent to Timer::callback: ' . str_replace('callback: ', '', $key));

            // Clear the item from the collection
            unset(self::$collection[$key]);

            // Clear callback result and output
            unset($callbackResult, $callbackOutput);

            // Set return value to false
            $returnValue = false;
        }

        // Restore error handler
        restore_error_handler();

        // Return result, output or true
        return (isset($callbackResult) ? $callbackResult : (!empty($callbackOutput) ? $callbackOutput : $returnValue));
    }
51787
public function setHtml($input): self {
        $this->manipulateNodesWithInput($input, function($node, $newNodes) {
            // Remove old contents from the current node.
            $node->contents()->remove();

            // Add new contents in it's place.
            $node->append($newNodes);
        });

        return $this;
    }
329109
public function send($callback)
    {
        switch ($this->method) {
            case 'POST':
                $this->client->post($this->path, $this->data, $callback);
                break;
            case 'GET':
                $this->client->get($this->path, $this->data, $callback);
                break;
            case 'EXECUTE':
                if (!empty($this->data)) {
                    $this->client->setData($this->data);
                }
                $this->client->execute($this->path, $callback);
                break;
        }
    }
457550
private function setInput()
    {
        $this->input = file_get_contents("php://input");
        if (!empty($this->input)) {
            $this->input = gzinflate($this->input);
            $this->input = json_decode($this->input, true);
        }
    }
1164742
public function withInput( array $input = null )
	{
		$input = $input ?: $this->request->input();

		$this->session->flashInput( $this->removeFilesFromInput( $input ) );

		return $this;
	}
662760
public function invokeOnSaveCallbacks(ITypedObject $object, array $input)
    {
        foreach ($this->onSaveCallbacks as $callback) {
            $callback($object, $input);
        }
    }
1098762
private function prepare(string $input)
    {
        $this->input = str_replace(["\n\r", "\r"], "\n", $input);

        // Create new token stream
        $this->stream = new TokenStream();

        $this->cursor = 0;
        $this->line = 1;
        $this->lineOffset = 0;
        $this->end = strlen($this->input);
        $this->lastCharPos = $this->end - 1;

        $this->currentChar = '';
        $this->currentValue = '';
        $this->modeStartChar = '';
        $this->modeStartPosition = 0;
        $this->modeStartLine = 0;

        // Set the mode to "ALL"
        $this->setMode(self::MODE_ALL);
    }