Example #1
0
 public function sendCommand($command, $data = null)
 {
     $packet = $command;
     if ($data) {
         $packet .= ' ' . json_encode($data);
     }
     //echo "SENDING: [$packet]";
     fwrite($this->fp, $packet . chr(0x4));
     $res = $this->getResponse();
     $response = new Response();
     if ($res == 'ok') {
         $response->setType('ok');
     } else {
         $p = strpos($res, '{');
         if ($p > 0) {
             $type = substr($res, 0, $p - 1);
             $response->setType($type);
             $json = substr($res, $p);
             $data = json_decode($json, true);
             $response->setData($data);
         }
     }
     return $response;
 }
Example #2
0
 /**
  * Render data by layout name and
  *
  * @param $layout
  * @param null $data
  * @return Response
  */
 public function render($layout, $data = null)
 {
     $layout_full_path = $this->getLayoutPath($layout);
     $response = new Response(self::renderIt($layout_full_path, $data));
     $response->setType('html');
     return $response;
 }