public function frameCheck(FrameInterface $frame) {
        if (false !== $frame->getRsv1() ||
            false !== $frame->getRsv2() ||
            false !== $frame->getRsv3()
        ) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid reserve code');
        }

        if ($this->checkForMask && !$frame->isMasked()) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an incorrect frame mask');
        }

        $opcode = $frame->getOpcode();

        if ($opcode > 2) {
            if ($frame->getPayloadLength() > 125 || !$frame->isFinal()) {
                return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected a mismatch between final bit and indicated payload length');
            }

            switch ($opcode) {
                case Frame::OP_CLOSE:
                    $closeCode = 0;

                    $bin = $frame->getPayload();

                    if (empty($bin)) {
                        return $this->newCloseFrame(Frame::CLOSE_NORMAL);
                    }

                    if (strlen($bin) === 1) {
                        return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid close code');
                    }

                    if (strlen($bin) >= 2) {
                        list($closeCode) = array_merge(unpack('n*', substr($bin, 0, 2)));
                    }

                    $checker = $this->closeFrameChecker;
                    if (!$checker($closeCode)) {
                        return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid close code');
                    }

                    if (!$this->checkUtf8(substr($bin, 2))) {
                        return $this->newCloseFrame(Frame::CLOSE_BAD_PAYLOAD, 'Ratchet detected an invalid UTF-8 payload in the close reason');
                    }

                    return $frame;
                    break;
                case Frame::OP_PING:
                case Frame::OP_PONG:
                    break;
                default:
                    return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid OP code');
                    break;
            }

            return $frame;
        }

        if (Frame::OP_CONTINUE === $frame->getOpcode() && 0 === count($this->messageBuffer)) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected the first frame of a message was a continue');
        }

        if (count($this->messageBuffer) > 0 && Frame::OP_CONTINUE !== $frame->getOpcode()) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected invalid OP code when expecting continue frame');
        }

        return $frame;
    }
public function frameCheck(FrameInterface $frame) {
        if (false !== $frame->getRsv1() ||
            false !== $frame->getRsv2() ||
            false !== $frame->getRsv3()
        ) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid reserve code');
        }

        if ($this->checkForMask && !$frame->isMasked()) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an incorrect frame mask');
        }

        $opcode = $frame->getOpcode();

        if ($opcode > 2) {
            if ($frame->getPayloadLength() > 125 || !$frame->isFinal()) {
                return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected a mismatch between final bit and indicated payload length');
            }

            switch ($opcode) {
                case Frame::OP_CLOSE:
                    $closeCode = 0;

                    $bin = $frame->getPayload();

                    if (empty($bin)) {
                        return $this->newCloseFrame(Frame::CLOSE_NORMAL);
                    }

                    if (strlen($bin) === 1) {
                        return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid close code');
                    }

                    if (strlen($bin) >= 2) {
                        list($closeCode) = array_merge(unpack('n*', substr($bin, 0, 2)));
                    }

                    $checker = $this->closeFrameChecker;
                    if (!$checker($closeCode)) {
                        return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid close code');
                    }

                    if (!$this->checkUtf8(substr($bin, 2))) {
                        return $this->newCloseFrame(Frame::CLOSE_BAD_PAYLOAD, 'Ratchet detected an invalid UTF-8 payload in the close reason');
                    }

                    return $frame;
                    break;
                case Frame::OP_PING:
                case Frame::OP_PONG:
                    break;
                default:
                    return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid OP code');
                    break;
            }

            return $frame;
        }

        if (Frame::OP_CONTINUE === $frame->getOpcode() && 0 === count($this->messageBuffer)) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected the first frame of a message was a continue');
        }

        if (count($this->messageBuffer) > 0 && Frame::OP_CONTINUE !== $frame->getOpcode()) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected invalid OP code when expecting continue frame');
        }

        return $frame;
    }
public function frameCheck ( FrameInterface $ frame ) { if ( false !== $ frame -> getRsv1 ( ) || false !== $ frame -> getRsv2 ( ) || false !== $ frame -> getRsv3 ( ) ) { return $ this -> newCloseFrame ( Frame :: CLOSE_PROTOCOL , 'Ratchet detected an invalid reserve code' ) ; } if ( $ this -> checkForMask && ! $ frame -> isMasked ( ) ) { return $ this -> newCloseFrame ( Frame :: CLOSE_PROTOCOL , 'Ratchet detected an incorrect frame mask' ) ; } $ opcode = $ frame -> getOpcode ( ) ; if ( $ opcode > 2 ) { if ( $ frame -> getPayloadLength ( ) > 125 || ! $ frame -> isFinal ( ) ) { return $ this -> newCloseFrame ( Frame :: CLOSE_PROTOCOL , 'Ratchet detected a mismatch between final bit and indicated payload length' ) ; } switch ( $ opcode ) { case Frame :: OP_CLOSE : $ closeCode = 0 ; $ bin = $ frame -> getPayload ( ) ; if ( empty ( $ bin ) ) { return $ this -> newCloseFrame ( Frame :: CLOSE_NORMAL ) ; } if ( strlen ( $ bin ) === 1 ) { return $ this -> newCloseFrame ( Frame :: CLOSE_PROTOCOL , 'Ratchet detected an invalid close code' ) ; } if ( strlen ( $ bin ) >= 2 ) { list ( $ closeCode ) = array_merge ( unpack ( 'n*' , substr ( $ bin , 0 , 2 ) ) ) ; } $ checker = $ this -> closeFrameChecker ; if ( ! $ checker ( $ closeCode ) ) { return $ this -> newCloseFrame ( Frame :: CLOSE_PROTOCOL , 'Ratchet detected an invalid close code' ) ; } if ( ! $ this -> checkUtf8 ( substr ( $ bin , 2 ) ) ) { return $ this -> newCloseFrame ( Frame :: CLOSE_BAD_PAYLOAD , 'Ratchet detected an invalid UTF-8 payload in the close reason' ) ; } return $ frame ; break ; case Frame :: OP_PING : case Frame :: OP_PONG : break ; default : return $ this -> newCloseFrame ( Frame :: CLOSE_PROTOCOL , 'Ratchet detected an invalid OP code' ) ; break ; } return $ frame ; } if ( Frame :: OP_CONTINUE === $ frame -> getOpcode ( ) && 0 === count ( $ this -> messageBuffer ) ) { return $ this -> newCloseFrame ( Frame :: CLOSE_PROTOCOL , 'Ratchet detected the first frame of a message was a continue' ) ; } if ( count ( $ this -> messageBuffer ) > 0 && Frame :: OP_CONTINUE !== $ frame -> getOpcode ( ) ) { return $ this -> newCloseFrame ( Frame :: CLOSE_PROTOCOL , 'Ratchet detected invalid OP code when expecting continue frame' ) ; } return $ frame ; }
Check a frame to be added to the current message buffer
@param \Ratchet\RFC6455\Messaging\FrameInterface|FrameInterface $frame
@return \Ratchet\RFC6455\Messaging\FrameInterface|FrameInterface
Check a frame to be added to the current message buffer