/** * Output the content */ public function __invoke(SenderInterface $sender) { $msg = msgpack_pack($this->variables); $contentType = 'application/json'; if ($sender instanceof HttpSender) { $headers = $sender->getHeaders(); $headers->addHeaderLine('Content-Type', $contentType); } $sender->setContent($msg); $sender->send(); }
public function __invoke(SenderInterface $sender) { if (!$sender instanceof HttpSender) { throw new Exception\RuntimeException('This output must use at Sender\\Http'); } $fileName = $this->getFileName(); $fileName = strstr($_SERVER["HTTP_USER_AGENT"], 'MSIE') ? rawurlencode($fileName) : htmlspecialchars($fileName); $headers = $sender->getHeaders(); $headers->addHeaderLine('Content-Type', $this->getMimeType())->addHeaderLine('Content-Disposition', 'attachment; filename="' . $fileName . '"')->addHeaderLine('Content-Length', filesize($this->file)); if ($this->XSendFile) { $headers->addHeaderLine('X-Sendfile', realpath($this->file)); } else { $sender->setContent(fopen($this->file, 'r')); } }
/** * Output the content */ public function __invoke(SenderInterface $sender) { $json = json_encode($this->variables); $contentType = 'application/json'; if (null !== $this->callback) { $json = $this->callback . '(' . $json . ');'; $contentType = 'application/x-javascript'; } if ($sender instanceof HttpSender) { $headers = $sender->getHeaders(); $headers->addHeaderLine('Content-Type', $contentType); } $sender->setContent($json); $sender->send(); }