Exemplo n.º 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();
 }
Exemplo n.º 2
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();
 }