public function applyMask($maskingKey, $payload = null) {
        if (null === $payload) {
            if (!$this->isCoalesced()) {
                throw call_user_func($this->ufeg, 'Frame must be coalesced to apply a mask');
            }

            $payload = substr($this->data, $this->getPayloadStartingByte(), $this->getPayloadLength());
        }

        $len = strlen($payload);

        if (0 === $len) {
            return '';
        }

        return $payload ^ str_pad('', $len, $maskingKey, STR_PAD_RIGHT);

        // TODO: Remove this before publish - keeping methods here to compare performance (above is faster but need control against v0.3.3)

        $applied = '';
        for ($i = 0, $len = strlen($payload); $i < $len; $i++) {
            $applied .= $payload[$i] ^ $maskingKey[$i % static::MASK_LENGTH];
        }

        return $applied;
    }
public function applyMask($maskingKey, $payload = null) {
        if (null === $payload) {
            if (!$this->isCoalesced()) {
                throw call_user_func($this->ufeg, 'Frame must be coalesced to apply a mask');
            }

            $payload = substr($this->data, $this->getPayloadStartingByte(), $this->getPayloadLength());
        }

        $len = strlen($payload);

        if (0 === $len) {
            return '';
        }

        return $payload ^ str_pad('', $len, $maskingKey, STR_PAD_RIGHT);

        // TODO: Remove this before publish - keeping methods here to compare performance (above is faster but need control against v0.3.3)

        $applied = '';
        for ($i = 0, $len = strlen($payload); $i < $len; $i++) {
            $applied .= $payload[$i] ^ $maskingKey[$i % static::MASK_LENGTH];
        }

        return $applied;
    }
public function applyMask ( $ maskingKey , $ payload = null ) { if ( null === $ payload ) { if ( ! $ this -> isCoalesced ( ) ) { throw call_user_func ( $ this -> ufeg , 'Frame must be coalesced to apply a mask' ) ; } $ payload = substr ( $ this -> data , $ this -> getPayloadStartingByte ( ) , $ this -> getPayloadLength ( ) ) ; } $ len = strlen ( $ payload ) ; if ( 0 === $ len ) { return '' ; } return $ payload ^ str_pad ( '' , $ len , $ maskingKey , STR_PAD_RIGHT ) ; // TODO: Remove this before publish - keeping methods here to compare performance (above is faster but need control against v0.3.3) $ applied = '' ; for ( $ i = 0 , $ len = strlen ( $ payload ) ; $ i < $ len ; $ i ++ ) { $ applied .= $ payload [ $ i ] ^ $ maskingKey [ $ i % static :: MASK_LENGTH ] ; } return $ applied ; }
Apply a mask to a string or the payload of the instance
@param string $maskingKey   The 4 character masking key to be applied
@param string|null $payload A string to mask or null to use the payload
@throws \UnderflowException If using the payload but enough hasn't been buffered
@return string              The masked string
Apply a mask to a string or the payload of the instance