コード例 #1
0
ファイル: ZombieServer.php プロジェクト: NaszvadiG/ImageCMS
 protected function doEvalJS(Connection $conn, $str, $returnType = 'js')
 {
     $result = null;
     switch ($returnType) {
         case 'js':
             $result = $conn->socketSend($str);
             break;
         case 'json':
             $result = json_decode($conn->socketSend("stream.end(JSON.stringify({$str}))"));
             break;
         default:
             break;
     }
     return $result;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 protected function doEvalJS(Connection $conn, $str, $returnType = 'js')
 {
     switch ($returnType) {
         case 'js':
             $result = $conn->socketSend($str);
             break;
         case 'json':
             $result = $conn->socketSend("stream.end(JSON.stringify({$str}))");
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Invalid return type "%s"', $returnType));
     }
     $errorPrefixLength = strlen(self::ERROR_PREFIX);
     if (self::ERROR_PREFIX === substr($result, 0, $errorPrefixLength)) {
         $errorMessage = json_decode(substr($result, $errorPrefixLength), true);
         throw new DriverException(sprintf('Error "%s" while executing code: %s', $errorMessage, $str));
     }
     if ('json' === $returnType) {
         return json_decode($result);
     }
     return $result;
 }