Пример #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
 /**
  * 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();
 }
Пример #4
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();
 }