示例#1
0
 /**
  * Output the content
  */
 public function __invoke(SenderInterface $sender)
 {
     $data = $this->data;
     if ($data !== null) {
         if (method_exists($data, 'toArray')) {
             $data = $data->toArray();
         } elseif ($data instanceof \Traversable) {
             $temp = array();
             foreach ($data as $key => $val) {
                 $temp[$key] = $val;
             }
             $data = $temp;
         }
         switch ($this->format) {
             case 'serialize':
                 $data = "serialize\r\n\r\n" . serialize($data);
                 break;
             case 'plain':
                 $data = "plain\r\n\r\n" . print_r($data, true);
                 break;
             case 'json':
             default:
                 $data = "json\r\n\r\n" . json_encode($data);
                 break;
         }
     }
     $sender->setContent($data);
     $sender->send();
 }
示例#2
0
 /**
  * Output the content
  */
 public function __invoke(SenderInterface $sender)
 {
     $view = $this->getView();
     $view->setVariable('_INPUT', $this->getInput());
     $sender->setContent($this->getViewManager()->render($view));
     $sender->send();
 }
示例#3
0
 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'));
     }
 }
示例#4
0
 /**
  * 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();
 }
示例#5
0
 /**
  * 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();
 }