Input message on websocket connected.
Define and return event name and payload data here.

@param \Swoole\Websocket\Frame $frame

@return array
335007
public function decode($frame)
    {
        $data = json_decode($frame->data, true);

        return [
            'event' => $data['event'] ?? null,
            'data' => $data['data'] ?? null,
        ];
    }
440386
private static function needSkipFrame(array $frame) {return
		\Magento\Framework\App\ErrorHandler::class === dfa($frame, 'class')
		|| df_ends_with(df_path_n(dfa($frame, 'file')), 'Sentry/Breadcrumbs/ErrorHandler.php')
	;}
653986
public function getSubscription(Frame $frame)
    {
        foreach ($this->subscriptions as $subscription) {
            if ($subscription->belongsTo($frame)) {
                return $subscription;
            }
        }
        return false;
    }
883128
def parse_frame(buf):
    """"""
    # read header
    while buf.available < 2:
        yield

    data = buf.read(2)
    first_byte, second_byte = struct.unpack('!BB', data)

    fin = (first_byte >> 7) & 1
    rsv1 = (first_byte >> 6) & 1
    rsv2 = (first_byte >> 5) & 1
    rsv3 = (first_byte >> 4) & 1
    opcode = first_byte & 0xf

    # frame-fin = %x0 ; more frames of this message follow
    #           / %x1 ; final frame of this message
    # frame-rsv1 = %x0 ; 1 bit, MUST be 0 unless negotiated otherwise
    # frame-rsv2 = %x0 ; 1 bit, MUST be 0 unless negotiated otherwise
    # frame-rsv3 = %x0 ; 1 bit, MUST be 0 unless negotiated otherwise
    if rsv1 or rsv2 or rsv3:
        raise WebSocketError('Received frame with non-zero reserved bits')

    if opcode > 0x7 and fin == 0:
        raise WebSocketError('Received fragmented control frame')

    if fin == 0 and opcode == OPCODE_CONTINUATION:
        raise WebSocketError(
            'Received new fragment frame with non-zero opcode')

    has_mask = (second_byte >> 7) & 1
    length = (second_byte) & 0x7f

    # Control frames MUST have a payload length of 125 bytes or less
    if opcode > 0x7 and length > 125:
        raise WebSocketError(
            "Control frame payload cannot be larger than 125 bytes")

    # read payload
    if length == 126:
        while buf.available < 2:
            yield

        length = struct.unpack_from('!H', buf.read(2))[0]
    elif length > 126:
        while buf.available < 4:
            yield

        length = struct.unpack_from('!Q', buf.read(4))[0]

    if has_mask:
        while buf.available < 4:
            yield

        mask = buf.read(4)

    if length:
        while buf.available < length:
            yield

        payload = buf.read(length)
    else:
        payload = b''

    if has_mask:
        mask = [ord(i) for i in mask]
        payload = [chr(ord(b) ^ mask[i % 4]) for i, b in enumerate(payload)]

    yield fin, opcode, payload
38353
protected function readFrame(): void
    {
        $header = $this->forceRead(8);

        if (\strlen($header) < 8) {
            return;
        }

        $decoded = \unpack('C1type/C3/N1size', $header);
        $output = $this->forceRead($decoded['size']);
        $callbackList = [];

        if (0 === $decoded['type']) {
            $callbackList = $this->onStdinCallables;
        }

        if (1 === $decoded['type']) {
            $callbackList = $this->onStdoutCallables;
        }

        if (2 === $decoded['type']) {
            $callbackList = $this->onStderrCallables;
        }

        foreach ($callbackList as $callback) {
            $callback($output);
        }
    }
1357140
public function dispatch(IncomingFrame $incomingFrame)
    {
        switch (true) {
            case $incomingFrame instanceof Basic\BasicDeliverFrame:
            case $incomingFrame instanceof Basic\BasicGetOkFrame:
                $message = new Message();
                $message->setRoutingKey($incomingFrame->routingKey)
                    ->setExchange($incomingFrame->exchange)
                    ->setTag($incomingFrame->deliveryTag)
                    ->setChannel($this);
                $object = new \stdClass();
                if ($incomingFrame instanceof Basic\BasicDeliverFrame) {
                    $object->consumerTag = $incomingFrame->consumerTag;
                }
                $object->message = $message;
                $this->stack->attach($object);
                $this->stack->rewind();
                break;
            case $incomingFrame instanceof Basic\BasicHeaderFrame:
                $object = $this->stack->current();
                /** @var Message $message */
                $message = $object->message;
                $message->setContentLength($incomingFrame->contentLength)
                    ->setContentType($incomingFrame->contentType)
                    ->setContentEncoding($incomingFrame->contentEncoding)
                    ->setHeaders($incomingFrame->headers)
                    ->setMessageId($incomingFrame->messageId)
                    ->setDeliveryMode($incomingFrame->deliveryMode)
                    ->setCorrelationId($incomingFrame->correlationId)
                    ->setReplyTo($incomingFrame->replyTo)
                    ->setExpiration($incomingFrame->expiration)
                    ->setTimestamp($incomingFrame->timestamp)
                    ->setType($incomingFrame->type)
                    ->setUserId($incomingFrame->userId)
                    ->setAppId($incomingFrame->appId)
                    ->setClusterId($incomingFrame->clusterId);
                $object->totalPayloadSize = $incomingFrame->contentLength;
                break;
            case $incomingFrame instanceof BodyFrame:
                $object = $this->stack->current();
                /**
                 * Use only php strlen because wee need string length in bytes
                 */
                $currentContentLength = strlen($incomingFrame->content);

                /** @var Message $message */
                $message = $object->message;
                $message->setContent($message->getContent() . $incomingFrame->content);

                $object->totalPayloadSize -= $currentContentLength;

                if ($object->totalPayloadSize === 0) {
                    if (isset($object->consumerTag)) {
                        $this->trigger(self::EVENT_DISPATCH_CONSUMER_MESSAGE, $object->consumerTag, $message);
                    } else {
                        $this->triggerOneAndUnbind(self::EVENT_DISPATCH_MESSAGE, $message);
                    }
                    $this->stack->detach($object);
                }
                break;
            case $incomingFrame instanceof Basic\BasicGetEmptyFrame:
                $this->triggerOneAndUnbind(self::EVENT_DISPATCH_MESSAGE, false);
                break;
            case $incomingFrame instanceof Basic\BasicCancelOkFrame:
                unset($this->consumers[$incomingFrame->consumerTag]);
                break;

            case $incomingFrame instanceof ProtocolChannel\ChannelOpenOkFrame:
                $this->isConnected = true;
                $this->id = $incomingFrame->frameChannelId;
                //write QoS
                $outputFrame = Basic\BasicQosFrame::create(
                    self::QOS_PREFECTH_SIZE,
                    self::QOS_PREFETCH_COUNT
                );
                $outputFrame->frameChannelId = $incomingFrame->frameChannelId;
                $this->connection->command($outputFrame);
                break;
            case $incomingFrame instanceof ProtocolChannel\ChannelCloseFrame:
                $this->trigger(self::EVENT_ON_CHANNEL_CLOSE_CALLBACK);
                Daemon::log(sprintf('[AMQP] Channel closed by broker. Reason: %s[%d]', $incomingFrame->replyText, $incomingFrame->replyCode));
                $this->isConnected = false;
                break;
            case $incomingFrame instanceof Basic\BasicQosOkFrame:
                $this->trigger(self::EVENT_ON_CHANNEL_OPEN_CALLBACK, $this);
                break;
            case $incomingFrame instanceof Basic\BasicConsumeOkFrame:
                $this->triggerOneAndUnbind(self::EVENT_ON_CHANNEL_CONSUMEOK_CALLBACK, $incomingFrame);
                break;
            case $incomingFrame instanceof ProtocolChannel\ChannelCloseOkFrame:
                $this->isConnected = false;
                break;
            case $incomingFrame instanceof Queue\QueueDeclareOkFrame:
                $this->triggerOneAndUnbind(self::EVENT_ON_CHANNEL_DECLARE_QUEUE_CALLBACK);
                break;
            case $incomingFrame instanceof Queue\QueueDeleteOkFrame:
                $this->triggerOneAndUnbind(self::EVENT_ON_CHANNEL_DELETE_QUEUE_CALLBACK);
                break;
            case $incomingFrame instanceof Queue\QueuePurgeOkFrame:
                $this->triggerOneAndUnbind(self::EVENT_ON_CHANNEL_PURGE_QUEUE_CALLBACK);
                break;
            case $incomingFrame instanceof Queue\QueueBindOkFrame:
                $this->triggerOneAndUnbind(self::EVENT_ON_CHANNEL_BIND_QUEUE_CALLBACK);
                break;
            case $incomingFrame instanceof Queue\QueueUnbindOkFrame:
                $this->triggerOneAndUnbind(self::EVENT_ON_CHANNEL_UNBIND_QUEUE_CALLBACK);
                break;
            case $incomingFrame instanceof Exchange\ExchangeDeclareOkFrame:
                $this->triggerOneAndUnbind(self::EVENT_ON_CHANNEL_DECLARE_EXCHANGE_CALLBACK);
                break;
            case $incomingFrame instanceof Exchange\ExchangeDeleteOkFrame:
                $this->triggerOneAndUnbind(self::EVENT_ON_CHANNEL_DELETE_EXCHANGE_CALLBACK);
                break;
            case $incomingFrame instanceof Exchange\ExchangeBindOkFrame:
                $this->triggerOneAndUnbind(self::EVENT_ON_CHANNEL_BIND_EXCHANGE_CALLBACK);
                break;
            case $incomingFrame instanceof Exchange\ExchangeUnbindOkFrame:
                $this->triggerOneAndUnbind(self::EVENT_ON_CHANNEL_UNBIND_EXCHANGE_CALLBACK);
                break;
        }
    }
1223156
function add_frame(Frame $frame) {
    
    $style = $frame->get_style();
    $display = $style->display;

    $collapse = $this->_table->get_style()->border_collapse == "collapse";

    // Recursively add the frames within tables, table-row-groups and table-rows
    if ( $display === "table-row" ||
         $display === "table" ||
         $display === "inline-table" ||
         in_array($display, Table_Frame_Decorator::$ROW_GROUPS) ) {

      $start_row = $this->__row;
      foreach ( $frame->get_children() as $child )
        $this->add_frame( $child );

      if ( $display === "table-row" )
        $this->add_row();

      $num_rows = $this->__row - $start_row - 1;
      $key = $frame->get_id();

      // Row groups always span across the entire table
      $this->_frames[$key]["columns"] = range(0,max(0,$this->_num_cols-1));
      $this->_frames[$key]["rows"] = range($start_row, max(0, $this->__row - 1));
      $this->_frames[$key]["frame"] = $frame;

      if ( $display !== "table-row" && $collapse ) {

        $bp = $style->get_border_properties();

        // Resolve the borders
        for ( $i = 0; $i < $num_rows+1; $i++) {
          $this->_resolve_border($start_row + $i, 0, "vertical", $bp["left"]);
          $this->_resolve_border($start_row + $i, $this->_num_cols, "vertical", $bp["right"]);
        }

        for ( $j = 0; $j < $this->_num_cols; $j++) {
          $this->_resolve_border($start_row, $j, "horizontal", $bp["top"]);
          $this->_resolve_border($this->__row, $j, "horizontal", $bp["bottom"]);
        }
      }


      return;
    }
    
    $node = $frame->get_node();
    
    // Determine where this cell is going
    $colspan = $node->getAttribute("colspan");
    $rowspan = $node->getAttribute("rowspan");

    if ( !$colspan ) {
      $colspan = 1;
      $node->setAttribute("colspan",1);
    }

    if ( !$rowspan ) {
      $rowspan = 1;
      $node->setAttribute("rowspan",1);
    }
    $key = $frame->get_id();

    $bp = $style->get_border_properties();


    // Add the frame to the cellmap
    $max_left = $max_right = 0;

    // Find the next available column (fix by Ciro Mondueri)
    $ac = $this->__col;
    while ( isset($this->_cells[$this->__row][$ac]) )
       $ac++;
    $this->__col = $ac;

    // Rows:
    for ( $i = 0; $i < $rowspan; $i++ ) {
      $row = $this->__row + $i;

      $this->_frames[$key]["rows"][] = $row;

      for ( $j = 0; $j < $colspan; $j++)
        $this->_cells[$row][$this->__col + $j] = $frame;

      if ( $collapse ) {
        // Resolve vertical borders
        $max_left = max($max_left, $this->_resolve_border($row, $this->__col, "vertical", $bp["left"]));
        $max_right = max($max_right, $this->_resolve_border($row, $this->__col + $colspan, "vertical", $bp["right"]));
      }
    }

    $max_top = $max_bottom = 0;

    // Columns:
    for ( $j = 0; $j < $colspan; $j++ ) {
      $col = $this->__col + $j;
      $this->_frames[$key]["columns"][] = $col;

      if ( $collapse ) {
        // Resolve horizontal borders
        $max_top = max($max_top, $this->_resolve_border($this->__row, $col, "horizontal", $bp["top"]));
        $max_bottom = max($max_bottom, $this->_resolve_border($this->__row + $rowspan, $col, "horizontal", $bp["bottom"]));
      }
    }

    $this->_frames[$key]["frame"] = $frame;

    // Handle seperated border model
    if ( !$collapse ) {
      list($h, $v) = $this->_table->get_style()->border_spacing;

      // Border spacing is effectively a margin between cells
      $v = $style->length_in_pt($v) / 2;
      $h = $style->length_in_pt($h) / 2;
      $style->margin = "$v $h";

      // The additional 1/2 width gets added to the table proper

    } else {

      // Drop the frame's actual border
      $style->border_left_width = $max_left / 2;
      $style->border_right_width = $max_right / 2;
      $style->border_top_width = $max_top / 2;
      $style->border_bottom_width = $max_bottom / 2;
      $style->margin = "none";
    }

    // Resolve the frame's width
    list($frame_min, $frame_max) = $frame->get_min_max_width();

    $width = $style->width;

    if ( is_percent($width) ) {
      $var = "percent";
      $val = (float)rtrim($width, "% ") / $colspan;

    } else if ( $width !== "auto" ) {
      $var = "absolute";
      $val = $style->length_in_pt($frame_min) / $colspan;
    }

    if (!$this->_columns_locked) {
      $min = 0;
      $max = 0;
      for ( $cs = 0; $cs < $colspan; $cs++ ) {
  
        // Resolve the frame's width(s) with other cells
        $col =& $this->get_column( $this->__col + $cs );
  
        // Note: $var is either 'percent' or 'absolute'.  We compare the
        // requested percentage or absolute values with the existing widths
        // and adjust accordingly.
        if ( isset($var) && $val > $col[$var] ) {
          $col[$var] = $val;
          $col["auto"] = false;
        }
  
        $min += $col["min-width"];
        $max += $col["max-width"];
      }
  
  
      if ( $frame_min > $min ) {
        // The frame needs more space.  Expand each sub-column
        $inc = ($frame_min - $min) / $colspan;
        for ($c = 0; $c < $colspan; $c++) {
          $col =& $this->get_column($this->__col + $c);
          $col["min-width"] += $inc;
        }
      }
  
      if ( $frame_max > $max ) {
        $inc = ($frame_max - $max) / $colspan;
        for ($c = 0; $c < $colspan; $c++) {
          $col =& $this->get_column($this->__col + $c);
          $col["max-width"] += $inc;
        }
      }
    }

    $this->__col += $colspan;
    if ( $this->__col > $this->_num_cols )
      $this->_num_cols = $this->__col;

  }
769235
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
        if (frame instanceof CloseWebSocketFrame) {
            this.handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
            CompletableFuture.completedFuture(new WebSocketContext(this.session,this.handler))
                    .thenAcceptAsync(this.handler::onDisConnect);
            return;
        }
        if (frame instanceof PingWebSocketFrame) {
            ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
            return;
        }

        if (!(frame instanceof TextWebSocketFrame)) {
            throw new UnsupportedOperationException("unsupported frame type: " + frame.getClass().getName());
        }
        CompletableFuture.completedFuture(new WebSocketContext(this.session,this.handler,((TextWebSocketFrame) frame).text()))
                .thenAcceptAsync(this.handler::onText,ctx.executor());
    }
546336
public function render(Frame $frame)
    {
        global $_dompdf_debug;

        $this->_check_callbacks("begin_frame", $frame);

        if ($_dompdf_debug) {
            echo $frame;
            flush();
        }

        $style = $frame->get_style();

        if (in_array($style->visibility, array("hidden", "collapse"))) {
            return;
        }

        $display = $style->display;

        // Starts the CSS transformation
        if ($style->transform && is_array($style->transform)) {
            $this->_canvas->save();
            list($x, $y) = $frame->get_padding_box();
            $origin = $style->transform_origin;

            foreach ($style->transform as $transform) {
                list($function, $values) = $transform;
                if ($function === "matrix") {
                    $function = "transform";
                }

                $values = array_map("floatval", $values);
                $values[] = $x + (float)$style->length_in_pt($origin[0], (float)$style->length_in_pt($style->width));
                $values[] = $y + (float)$style->length_in_pt($origin[1], (float)$style->length_in_pt($style->height));

                call_user_func_array(array($this->_canvas, $function), $values);
            }
        }

        switch ($display) {

            case "block":
            case "list-item":
            case "inline-block":
            case "table":
            case "inline-table":
                $this->_render_frame("block", $frame);
                break;

            case "inline":
                if ($frame->is_text_node()) {
                    $this->_render_frame("text", $frame);
                } else {
                    $this->_render_frame("inline", $frame);
                }
                break;

            case "table-cell":
                $this->_render_frame("table-cell", $frame);
                break;

            case "table-row-group":
            case "table-header-group":
            case "table-footer-group":
                $this->_render_frame("table-row-group", $frame);
                break;

            case "-dompdf-list-bullet":
                $this->_render_frame("list-bullet", $frame);
                break;

            case "-dompdf-image":
                $this->_render_frame("image", $frame);
                break;

            case "none":
                $node = $frame->get_node();

                if ($node->nodeName === "script") {
                    if ($node->getAttribute("type") === "text/php" ||
                        $node->getAttribute("language") === "php"
                    ) {
                        // Evaluate embedded php scripts
                        $this->_render_frame("php", $frame);
                    } elseif ($node->getAttribute("type") === "text/javascript" ||
                        $node->getAttribute("language") === "javascript"
                    ) {
                        // Insert JavaScript
                        $this->_render_frame("javascript", $frame);
                    }
                }

                // Don't render children, so skip to next iter
                return;

            default:
                break;

        }

        // Starts the overflow: hidden box
        if ($style->overflow === "hidden") {
            list($x, $y, $w, $h) = $frame->get_padding_box();

            // get border radii
            $style = $frame->get_style();
            list($tl, $tr, $br, $bl) = $style->get_computed_border_radius($w, $h);

            if ($tl + $tr + $br + $bl > 0) {
                $this->_canvas->clipping_roundrectangle($x, $y, (float)$w, (float)$h, $tl, $tr, $br, $bl);
            } else {
                $this->_canvas->clipping_rectangle($x, $y, (float)$w, (float)$h);
            }
        }

        $stack = array();

        foreach ($frame->get_children() as $child) {
            // < 0 : nagative z-index
            // = 0 : no z-index, no stacking context
            // = 1 : stacking context without z-index
            // > 1 : z-index
            $child_style = $child->get_style();
            $child_z_index = $child_style->z_index;
            $z_index = 0;

            if ($child_z_index !== "auto") {
                $z_index = intval($child_z_index) + 1;
            } elseif ($child_style->float !== "none" || $child->is_positionned()) {
                $z_index = 1;
            }

            $stack[$z_index][] = $child;
        }

        ksort($stack);

        foreach ($stack as $by_index) {
            foreach ($by_index as $child) {
                $this->render($child);
            }
        }

        // Ends the overflow: hidden box
        if ($style->overflow === "hidden") {
            $this->_canvas->clipping_end();
        }

        if ($style->transform && is_array($style->transform)) {
            $this->_canvas->restore();
        }

        // Check for end frame callback
        $this->_check_callbacks("end_frame", $frame);
    }
1099346
public function doMessage(swoole_server $server, swoole_websocket_frame $frame)
    {
        $data = $frame->data;
        $data = Json::decode($data);
        $request = new ServerRequest($data['method'], $data['path']);
        if (isset($data['args'])) {
            if ('GET' === $request->getMethod()) {
                $request->withQueryParams($data['args']);
            } else {
                $request->withParsedBody($data['args']);
            }
        }
        $response = app()->handleRequest($request);
        $fd = null !== ($fd = $response->getFileDescriptor()) ? $fd : $frame->fd;
        if (false === $server->connection_info($fd)) {
            return -1;
        }
        $server->push($fd, (string) $response->getBody());
        app()->shutdown($request, $response);

        return 0;
    }
1036140
function check_page_break(Frame $frame) {
    // Do not split if we have already or if the frame was already 
    // pushed to the next page (prevents infinite loops)
    if ( $this->_page_full || $frame->_already_pushed ) {
      return false;
    }
    
    // If the frame is absolute of fixed it shouldn't break
    $p = $frame;
    do {
      if ( $p->is_absolute() )
        return false;
    } while ( $p = $p->get_parent() );
    
    $margin_height = $frame->get_margin_height();
    
    // FIXME If the row is taller than the page and 
    // if it the first of the page, we don't break
    if ( $frame->get_style()->display === "table-row" &&
         !$frame->get_prev_sibling() && 
         $margin_height > $this->get_margin_height() )
      return false;

    // Determine the frame's maximum y value
    $max_y = $frame->get_position("y") + $margin_height;

    // If a split is to occur here, then the bottom margins & paddings of all
    // parents of $frame must fit on the page as well:
    $p = $frame->get_parent();
    while ( $p ) {
      $style = $p->get_style();
      $max_y += $style->length_in_pt(array($style->margin_bottom,
                                           $style->padding_bottom,
                                           $style->border_bottom_width));
      $p = $p->get_parent();
    }


    // Check if $frame flows off the page
    if ( $max_y <= $this->_bottom_page_margin )
      // no: do nothing
      return false;

    dompdf_debug("page-break", "check_page_break");
    dompdf_debug("page-break", "in_table: " . $this->_in_table);

    // yes: determine page break location
    $iter = $frame;
    $flg = false;

    $in_table = $this->_in_table;

    dompdf_debug("page-break","Starting search");
    while ( $iter ) {
//       echo "\nbacktrack: " .$iter->get_node()->nodeName ." ".spl_object_hash($iter->get_node()). "";
      if ( $iter === $this ) {
         dompdf_debug("page-break", "reached root.");
        // We've reached the root in our search.  Just split at $frame.
        break;
      }

      if ( $this->_page_break_allowed($iter) ) {
        dompdf_debug("page-break","break allowed, splitting.");
        $iter->split(null, true);
        $this->_page_full = true;
        $this->_in_table = $in_table;
        $frame->_already_pushed = true;
        return true;
      }

      if ( !$flg && $next = $iter->get_last_child() ) {
         dompdf_debug("page-break", "following last child.");

        if ( $next->is_table() )
          $this->_in_table++;

        $iter = $next;
        continue;
      }

      if ( $next = $iter->get_prev_sibling() ) {
         dompdf_debug("page-break", "following prev sibling.");

             if ( $next->is_table() && !$iter->is_table() )
          $this->_in_table++;

        else if ( !$next->is_table() && $iter->is_table() )
          $this->_in_table--;

        $iter = $next;
        $flg = false;
        continue;
      }

      if ( $next = $iter->get_parent() ) {
         dompdf_debug("page-break", "following parent.");

        if ( $iter->is_table() )
          $this->_in_table--;

        $iter = $next;
        $flg = true;
        continue;
      }

      break;
    }

    $this->_in_table = $in_table;

    // No valid page break found.  Just break at $frame.
    dompdf_debug("page-break", "no valid break found, just splitting.");

    // If we are in a table, backtrack to the nearest top-level table row
    if ( $this->_in_table ) {
      $num_tables = $this->_in_table - 1;

      $iter = $frame;
      while ( $iter && $num_tables && $iter->get_style()->display !== "table" ) {
        $iter = $iter->get_parent();
        $num_tables--;
      }

      $iter = $frame;
      while ($iter && $iter->get_style()->display !== "table-row" )
        $iter = $iter->get_parent();
    }

    $frame->split(null, true);
    $this->_page_full = true;
    $frame->_already_pushed = true;
    return true;
    
  }
15662
public function message(Server $server, Frame $frame)
    {
        $fd = $frame->fd;

        try {
            if (!$path = WebSocketContext::getMeta('path', $fd)) {
                throw new ContextLostException("The connection info has lost of the fd#$fd, on message");
            }

            $className = $this->getHandler($path)[0];

            /** @var HandlerInterface $handler */
            $handler = \bean($className);
            $handler->onMessage($server, $frame);
        } catch (\Throwable $e) {
            /** @see \Swoft\Event\EventManager::hasListenerQueue() */
            if (App::hasBean('eventManager') && \bean('eventManager')->hasListenerQueue(WsEvent::ON_ERROR)) {
                App::trigger(WsEvent::ON_ERROR, $frame, $e);
            } else {
                App::error($e->getMessage(), ['fd' => $fd, 'data' => $frame->data]);
                // close connection
                $server->close($fd);
            }
        }
    }
21630
function check_page_break(Frame $frame)
    {
        //FIXME: should not need to do this since we're tracking table status in `$this->_in_table`
        $p = $frame;
        $in_table = false;
        while ($p) {
            if ($p->is_table()) { $in_table = true; break; }
            $p = $p->get_parent();
        }
        // Do not split if we have already or if the frame was already
        // pushed to the next page (prevents infinite loops)
        if ($in_table) {
            if ($this->_page_full && $frame->_already_pushed) {
                return false;
            }
        } elseif ($this->_page_full || $frame->_already_pushed) {
            return false;
        }

        //FIXME: work-around for infinite loop due to tables 
        if ($in_table && $frame->_already_pushed) {
            return false;
        }
        $p = $frame;
        do {
            $display = $p->get_style()->display;
            if ($display == "table-row") {
                if ($p->_already_pushed) { return false; }
            }
        } while ($p = $p->get_parent());

        // If the frame is absolute of fixed it shouldn't break
        $p = $frame;
        do {
            if ($p->is_absolute()) {
                return false;
            }

            // FIXME If the row is taller than the page and
            // if it the first of the page, we don't break
            $display = $p->get_style()->display;
            if ($display === "table-row"
                && !$p->get_prev_sibling()
                && $p->get_margin_height() > $this->get_margin_height()
            ) {
                return false;
            }
        } while ($p = $p->get_parent());

        $margin_height = $frame->get_margin_height();

        // Determine the frame's maximum y value
        $max_y = (float)$frame->get_position("y") + $margin_height;

        // If a split is to occur here, then the bottom margins & paddings of all
        // parents of $frame must fit on the page as well:
        $p = $frame->get_parent();
        while ($p) {
            $max_y += $p->get_style()->computed_bottom_spacing();
            $p = $p->get_parent();
        }


        // Check if $frame flows off the page
        if ($max_y <= $this->_bottom_page_margin) {
            // no: do nothing
            return false;
        }

        Helpers::dompdf_debug("page-break", "check_page_break");
        Helpers::dompdf_debug("page-break", "in_table: " . $this->_in_table);

        // yes: determine page break location
        $iter = $frame;
        $flg = false;

        $in_table = $this->_in_table;

        Helpers::dompdf_debug("page-break", "Starting search");
        while ($iter) {
            // echo "\nbacktrack: " .$iter->get_node()->nodeName ." ".spl_object_hash($iter->get_node()). "";
            if ($iter === $this) {
                Helpers::dompdf_debug("page-break", "reached root.");
                // We've reached the root in our search.  Just split at $frame.
                break;
            }

            if ($this->_page_break_allowed($iter)) {
                Helpers::dompdf_debug("page-break", "break allowed, splitting.");
                $iter->split(null, true);
                $this->_page_full = true;
                $this->_in_table = $in_table;
                $frame->_already_pushed = true;

                return true;
            }

            if (!$flg && $next = $iter->get_last_child()) {
                Helpers::dompdf_debug("page-break", "following last child.");

                if ($next->is_table()) {
                    $this->_in_table++;
                }

                $iter = $next;
                continue;
            }

            if ($next = $iter->get_prev_sibling()) {
                Helpers::dompdf_debug("page-break", "following prev sibling.");

                if ($next->is_table() && !$iter->is_table()) {
                    $this->_in_table++;
                } else if (!$next->is_table() && $iter->is_table()) {
                    $this->_in_table--;
                }

                $iter = $next;
                $flg = false;
                continue;
            }

            if ($next = $iter->get_parent()) {
                Helpers::dompdf_debug("page-break", "following parent.");

                if ($iter->is_table()) {
                    $this->_in_table--;
                }

                $iter = $next;
                $flg = true;
                continue;
            }

            break;
        }

        $this->_in_table = $in_table;

        // No valid page break found.  Just break at $frame.
        Helpers::dompdf_debug("page-break", "no valid break found, just splitting.");

        // If we are in a table, backtrack to the nearest top-level table row
        if ($this->_in_table) {
            $iter = $frame;
            while ($iter && $iter->get_style()->display !== "table-row" && $iter->get_style()->display !== 'table-row-group' && $iter->_already_pushed === false) {
                $iter = $iter->get_parent();
            }

            if ($iter) {
                $iter->split(null, true);
            } else {
                return false;
            }
        } else {
            $frame->split(null, true);
        }

        $this->_page_full = true;
        $frame->_already_pushed = true;

        return true;
    }
792534
function render(Frame $frame) {
    $style = $frame->get_style();
    
    if ( trim($frame->get_node()->nodeValue) === "" && $style->empty_cells === "hide" ) {
      return;
    }

    $this->_set_opacity( $frame->get_opacity( $style->opacity ) );
    list($x, $y, $w, $h) = $frame->get_border_box();
    
    // Draw our background, border and content
    if ( ($bg = $style->background_color) !== "transparent" ) {
      $this->_canvas->filled_rectangle($x, $y, $w, $h, $bg);
    }

    if ( ($url = $style->background_image) && $url !== "none" ) {
      $this->_background_image($url, $x, $y, $w, $h, $style);
    }
    
    $table = Table_Frame_Decorator::find_parent_table($frame);

    if ( $table->get_style()->border_collapse !== "collapse" ) {
      $this->_render_border($frame);
      $this->_render_outline($frame);
      return;
    }

    // The collapsed case is slightly complicated...
    // @todo Add support for outlines here

    $cellmap  = $table->get_cellmap();
    $cells    = $cellmap->get_spanned_cells($frame);
    $num_rows = $cellmap->get_num_rows();
    $num_cols = $cellmap->get_num_cols();

    // Determine the top row spanned by this cell
    $i = $cells["rows"][0];
    $top_row = $cellmap->get_row($i);

    // Determine if this cell borders on the bottom of the table.  If so,
    // then we draw its bottom border.  Otherwise the next row down will
    // draw its top border instead.
    if (in_array( $num_rows - 1, $cells["rows"])) {
      $draw_bottom = true;
      $bottom_row = $cellmap->get_row($num_rows - 1);
    } else
      $draw_bottom = false;


    // Draw the horizontal borders
    foreach ( $cells["columns"] as $j ) {
      $bp = $cellmap->get_border_properties($i, $j);

      $y = $top_row["y"] - $bp["top"]["width"] / 2;

      $col = $cellmap->get_column($j);
      $x = $col["x"] - $bp["left"]["width"] / 2;
      $w = $col["used-width"] + ($bp["left"]["width"] + $bp["right"]["width"] ) / 2;

      if ( $bp["top"]["style"] !== "none" && $bp["top"]["width"] > 0 ) {
        $widths = array($bp["top"]["width"],
                        $bp["right"]["width"],
                        $bp["bottom"]["width"],
                        $bp["left"]["width"]);
        $method = "_border_". $bp["top"]["style"];
        $this->$method($x, $y, $w, $bp["top"]["color"], $widths, "top", "square");
      }

      if ( $draw_bottom ) {
        $bp = $cellmap->get_border_properties($num_rows - 1, $j);
        if ( $bp["bottom"]["style"] === "none" || $bp["bottom"]["width"] <= 0 )
          continue;

        $y = $bottom_row["y"] + $bottom_row["height"] + $bp["bottom"]["width"] / 2;

        $widths = array($bp["top"]["width"],
                        $bp["right"]["width"],
                        $bp["bottom"]["width"],
                        $bp["left"]["width"]);
        $method = "_border_". $bp["bottom"]["style"];
        $this->$method($x, $y, $w, $bp["bottom"]["color"], $widths, "bottom", "square");

      }
    }

    $j = $cells["columns"][0];

    $left_col = $cellmap->get_column($j);

    if (in_array($num_cols - 1, $cells["columns"])) {
      $draw_right = true;
      $right_col = $cellmap->get_column($num_cols - 1);
    } else
      $draw_right = false;

    // Draw the vertical borders
    foreach ( $cells["rows"] as $i ) {
      $bp = $cellmap->get_border_properties($i, $j);

      $x = $left_col["x"] - $bp["left"]["width"] / 2;

      $row = $cellmap->get_row($i);

      $y = $row["y"] - $bp["top"]["width"] / 2;
      $h = $row["height"] + ($bp["top"]["width"] + $bp["bottom"]["width"])/ 2;

      if ( $bp["left"]["style"] !== "none" && $bp["left"]["width"] > 0 ) {

        $widths = array($bp["top"]["width"],
                        $bp["right"]["width"],
                        $bp["bottom"]["width"],
                        $bp["left"]["width"]);

        $method = "_border_" . $bp["left"]["style"];
        $this->$method($x, $y, $h, $bp["left"]["color"], $widths, "left", "square");
      }

      if ( $draw_right ) {
        $bp = $cellmap->get_border_properties($i, $num_cols - 1);
        if ( $bp["right"]["style"] === "none" || $bp["right"]["width"] <= 0 )
          continue;

        $x = $right_col["x"] + $right_col["used-width"] + $bp["right"]["width"] / 2;

        $widths = array($bp["top"]["width"],
                        $bp["right"]["width"],
                        $bp["bottom"]["width"],
                        $bp["left"]["width"]);

        $method = "_border_" . $bp["right"]["style"];
        $this->$method($x, $y, $h, $bp["right"]["color"], $widths, "right", "square");

      }
    }

  }
992636
protected function getReceivingFrame(): Frame
    {
        $current = $this->getCurrentFrame();

        if ($current->isComplete()) {
            if ($current->isFinal()) {
                throw new PayloadException('Payload cannot receive data: it is already complete');
            } else {
                $this->frames[] = $current = $this->getFrame();
            }
        }

        return $current;
    }
1247997
public function appendMethodFrame(MethodFrame $frame, Buffer $buffer)
    {
        $buffer->appendUint16($frame->classId);
        $buffer->appendUint16($frame->methodId);

        if ($frame instanceof MethodConnectionStartFrame) {
            $buffer->appendUint8($frame->versionMajor);
            $buffer->appendUint8($frame->versionMinor);
            $this->appendTable($frame->serverProperties, $buffer);
            $buffer->appendUint32(strlen($frame->mechanisms)); $buffer->append($frame->mechanisms);
            $buffer->appendUint32(strlen($frame->locales)); $buffer->append($frame->locales);
        } elseif ($frame instanceof MethodConnectionStartOkFrame) {
            $this->appendTable($frame->clientProperties, $buffer);
            $buffer->appendUint8(strlen($frame->mechanism)); $buffer->append($frame->mechanism);
            $buffer->appendUint32(strlen($frame->response)); $buffer->append($frame->response);
            $buffer->appendUint8(strlen($frame->locale)); $buffer->append($frame->locale);
        } elseif ($frame instanceof MethodConnectionSecureFrame) {
            $buffer->appendUint32(strlen($frame->challenge)); $buffer->append($frame->challenge);
        } elseif ($frame instanceof MethodConnectionSecureOkFrame) {
            $buffer->appendUint32(strlen($frame->response)); $buffer->append($frame->response);
        } elseif ($frame instanceof MethodConnectionTuneFrame) {
            $buffer->appendInt16($frame->channelMax);
            $buffer->appendInt32($frame->frameMax);
            $buffer->appendInt16($frame->heartbeat);
        } elseif ($frame instanceof MethodConnectionTuneOkFrame) {
            $buffer->appendInt16($frame->channelMax);
            $buffer->appendInt32($frame->frameMax);
            $buffer->appendInt16($frame->heartbeat);
        } elseif ($frame instanceof MethodConnectionOpenFrame) {
            $buffer->appendUint8(strlen($frame->virtualHost)); $buffer->append($frame->virtualHost);
            $buffer->appendUint8(strlen($frame->capabilities)); $buffer->append($frame->capabilities);
            $this->appendBits([$frame->insist], $buffer);
        } elseif ($frame instanceof MethodConnectionOpenOkFrame) {
            $buffer->appendUint8(strlen($frame->knownHosts)); $buffer->append($frame->knownHosts);
        } elseif ($frame instanceof MethodConnectionCloseFrame) {
            $buffer->appendInt16($frame->replyCode);
            $buffer->appendUint8(strlen($frame->replyText)); $buffer->append($frame->replyText);
            $buffer->appendInt16($frame->closeClassId);
            $buffer->appendInt16($frame->closeMethodId);
        } elseif ($frame instanceof MethodConnectionCloseOkFrame) {
        } elseif ($frame instanceof MethodConnectionBlockedFrame) {
            $buffer->appendUint8(strlen($frame->reason)); $buffer->append($frame->reason);
        } elseif ($frame instanceof MethodConnectionUnblockedFrame) {
        } elseif ($frame instanceof MethodChannelOpenFrame) {
            $buffer->appendUint8(strlen($frame->outOfBand)); $buffer->append($frame->outOfBand);
        } elseif ($frame instanceof MethodChannelOpenOkFrame) {
            $buffer->appendUint32(strlen($frame->channelId)); $buffer->append($frame->channelId);
        } elseif ($frame instanceof MethodChannelFlowFrame) {
            $this->appendBits([$frame->active], $buffer);
        } elseif ($frame instanceof MethodChannelFlowOkFrame) {
            $this->appendBits([$frame->active], $buffer);
        } elseif ($frame instanceof MethodChannelCloseFrame) {
            $buffer->appendInt16($frame->replyCode);
            $buffer->appendUint8(strlen($frame->replyText)); $buffer->append($frame->replyText);
            $buffer->appendInt16($frame->closeClassId);
            $buffer->appendInt16($frame->closeMethodId);
        } elseif ($frame instanceof MethodChannelCloseOkFrame) {
        } elseif ($frame instanceof MethodAccessRequestFrame) {
            $buffer->appendUint8(strlen($frame->realm)); $buffer->append($frame->realm);
            $this->appendBits([$frame->exclusive, $frame->passive, $frame->active, $frame->write, $frame->read], $buffer);
        } elseif ($frame instanceof MethodAccessRequestOkFrame) {
            $buffer->appendInt16($frame->reserved1);
        } elseif ($frame instanceof MethodExchangeDeclareFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->exchange)); $buffer->append($frame->exchange);
            $buffer->appendUint8(strlen($frame->exchangeType)); $buffer->append($frame->exchangeType);
            $this->appendBits([$frame->passive, $frame->durable, $frame->autoDelete, $frame->internal, $frame->nowait], $buffer);
            $this->appendTable($frame->arguments, $buffer);
        } elseif ($frame instanceof MethodExchangeDeclareOkFrame) {
        } elseif ($frame instanceof MethodExchangeDeleteFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->exchange)); $buffer->append($frame->exchange);
            $this->appendBits([$frame->ifUnused, $frame->nowait], $buffer);
        } elseif ($frame instanceof MethodExchangeDeleteOkFrame) {
        } elseif ($frame instanceof MethodExchangeBindFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->destination)); $buffer->append($frame->destination);
            $buffer->appendUint8(strlen($frame->source)); $buffer->append($frame->source);
            $buffer->appendUint8(strlen($frame->routingKey)); $buffer->append($frame->routingKey);
            $this->appendBits([$frame->nowait], $buffer);
            $this->appendTable($frame->arguments, $buffer);
        } elseif ($frame instanceof MethodExchangeBindOkFrame) {
        } elseif ($frame instanceof MethodExchangeUnbindFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->destination)); $buffer->append($frame->destination);
            $buffer->appendUint8(strlen($frame->source)); $buffer->append($frame->source);
            $buffer->appendUint8(strlen($frame->routingKey)); $buffer->append($frame->routingKey);
            $this->appendBits([$frame->nowait], $buffer);
            $this->appendTable($frame->arguments, $buffer);
        } elseif ($frame instanceof MethodExchangeUnbindOkFrame) {
        } elseif ($frame instanceof MethodQueueDeclareFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->queue)); $buffer->append($frame->queue);
            $this->appendBits([$frame->passive, $frame->durable, $frame->exclusive, $frame->autoDelete, $frame->nowait], $buffer);
            $this->appendTable($frame->arguments, $buffer);
        } elseif ($frame instanceof MethodQueueDeclareOkFrame) {
            $buffer->appendUint8(strlen($frame->queue)); $buffer->append($frame->queue);
            $buffer->appendInt32($frame->messageCount);
            $buffer->appendInt32($frame->consumerCount);
        } elseif ($frame instanceof MethodQueueBindFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->queue)); $buffer->append($frame->queue);
            $buffer->appendUint8(strlen($frame->exchange)); $buffer->append($frame->exchange);
            $buffer->appendUint8(strlen($frame->routingKey)); $buffer->append($frame->routingKey);
            $this->appendBits([$frame->nowait], $buffer);
            $this->appendTable($frame->arguments, $buffer);
        } elseif ($frame instanceof MethodQueueBindOkFrame) {
        } elseif ($frame instanceof MethodQueuePurgeFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->queue)); $buffer->append($frame->queue);
            $this->appendBits([$frame->nowait], $buffer);
        } elseif ($frame instanceof MethodQueuePurgeOkFrame) {
            $buffer->appendInt32($frame->messageCount);
        } elseif ($frame instanceof MethodQueueDeleteFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->queue)); $buffer->append($frame->queue);
            $this->appendBits([$frame->ifUnused, $frame->ifEmpty, $frame->nowait], $buffer);
        } elseif ($frame instanceof MethodQueueDeleteOkFrame) {
            $buffer->appendInt32($frame->messageCount);
        } elseif ($frame instanceof MethodQueueUnbindFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->queue)); $buffer->append($frame->queue);
            $buffer->appendUint8(strlen($frame->exchange)); $buffer->append($frame->exchange);
            $buffer->appendUint8(strlen($frame->routingKey)); $buffer->append($frame->routingKey);
            $this->appendTable($frame->arguments, $buffer);
        } elseif ($frame instanceof MethodQueueUnbindOkFrame) {
        } elseif ($frame instanceof MethodBasicQosFrame) {
            $buffer->appendInt32($frame->prefetchSize);
            $buffer->appendInt16($frame->prefetchCount);
            $this->appendBits([$frame->global], $buffer);
        } elseif ($frame instanceof MethodBasicQosOkFrame) {
        } elseif ($frame instanceof MethodBasicConsumeFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->queue)); $buffer->append($frame->queue);
            $buffer->appendUint8(strlen($frame->consumerTag)); $buffer->append($frame->consumerTag);
            $this->appendBits([$frame->noLocal, $frame->noAck, $frame->exclusive, $frame->nowait], $buffer);
            $this->appendTable($frame->arguments, $buffer);
        } elseif ($frame instanceof MethodBasicConsumeOkFrame) {
            $buffer->appendUint8(strlen($frame->consumerTag)); $buffer->append($frame->consumerTag);
        } elseif ($frame instanceof MethodBasicCancelFrame) {
            $buffer->appendUint8(strlen($frame->consumerTag)); $buffer->append($frame->consumerTag);
            $this->appendBits([$frame->nowait], $buffer);
        } elseif ($frame instanceof MethodBasicCancelOkFrame) {
            $buffer->appendUint8(strlen($frame->consumerTag)); $buffer->append($frame->consumerTag);
        } elseif ($frame instanceof MethodBasicPublishFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->exchange)); $buffer->append($frame->exchange);
            $buffer->appendUint8(strlen($frame->routingKey)); $buffer->append($frame->routingKey);
            $this->appendBits([$frame->mandatory, $frame->immediate], $buffer);
        } elseif ($frame instanceof MethodBasicReturnFrame) {
            $buffer->appendInt16($frame->replyCode);
            $buffer->appendUint8(strlen($frame->replyText)); $buffer->append($frame->replyText);
            $buffer->appendUint8(strlen($frame->exchange)); $buffer->append($frame->exchange);
            $buffer->appendUint8(strlen($frame->routingKey)); $buffer->append($frame->routingKey);
        } elseif ($frame instanceof MethodBasicDeliverFrame) {
            $buffer->appendUint8(strlen($frame->consumerTag)); $buffer->append($frame->consumerTag);
            $buffer->appendInt64($frame->deliveryTag);
            $this->appendBits([$frame->redelivered], $buffer);
            $buffer->appendUint8(strlen($frame->exchange)); $buffer->append($frame->exchange);
            $buffer->appendUint8(strlen($frame->routingKey)); $buffer->append($frame->routingKey);
        } elseif ($frame instanceof MethodBasicGetFrame) {
            $buffer->appendInt16($frame->reserved1);
            $buffer->appendUint8(strlen($frame->queue)); $buffer->append($frame->queue);
            $this->appendBits([$frame->noAck], $buffer);
        } elseif ($frame instanceof MethodBasicGetOkFrame) {
            $buffer->appendInt64($frame->deliveryTag);
            $this->appendBits([$frame->redelivered], $buffer);
            $buffer->appendUint8(strlen($frame->exchange)); $buffer->append($frame->exchange);
            $buffer->appendUint8(strlen($frame->routingKey)); $buffer->append($frame->routingKey);
            $buffer->appendInt32($frame->messageCount);
        } elseif ($frame instanceof MethodBasicGetEmptyFrame) {
            $buffer->appendUint8(strlen($frame->clusterId)); $buffer->append($frame->clusterId);
        } elseif ($frame instanceof MethodBasicAckFrame) {
            $buffer->appendInt64($frame->deliveryTag);
            $this->appendBits([$frame->multiple], $buffer);
        } elseif ($frame instanceof MethodBasicRejectFrame) {
            $buffer->appendInt64($frame->deliveryTag);
            $this->appendBits([$frame->requeue], $buffer);
        } elseif ($frame instanceof MethodBasicRecoverAsyncFrame) {
            $this->appendBits([$frame->requeue], $buffer);
        } elseif ($frame instanceof MethodBasicRecoverFrame) {
            $this->appendBits([$frame->requeue], $buffer);
        } elseif ($frame instanceof MethodBasicRecoverOkFrame) {
        } elseif ($frame instanceof MethodBasicNackFrame) {
            $buffer->appendInt64($frame->deliveryTag);
            $this->appendBits([$frame->multiple, $frame->requeue], $buffer);
        } elseif ($frame instanceof MethodTxSelectFrame) {
        } elseif ($frame instanceof MethodTxSelectOkFrame) {
        } elseif ($frame instanceof MethodTxCommitFrame) {
        } elseif ($frame instanceof MethodTxCommitOkFrame) {
        } elseif ($frame instanceof MethodTxRollbackFrame) {
        } elseif ($frame instanceof MethodTxRollbackOkFrame) {
        } elseif ($frame instanceof MethodConfirmSelectFrame) {
            $this->appendBits([$frame->nowait], $buffer);
        } elseif ($frame instanceof MethodConfirmSelectOkFrame) {
        } else {
            throw new ProtocolException('Unhandled method frame ' . get_class($frame) . '.');
        }
    }
250650
public function deserializeEvent($serial)
    {
        $data = unserialize($serial);

        return array(
            'name' => $data['name'],
            'class' => $data['class'],
            'event' => $this->serializer->deserialize($data['event'], $data['class'], 'json'),
        );
    }