public static function getPayload(string $packet)
    {
        $packet = trim($packet);
        $start = strpos($packet, '[');

        if ($start === false || substr($packet, -1) !== ']') {
            return null;
        }

        $data = substr($packet, $start, strlen($packet) - $start);
        $data = json_decode($data, true);

        if (is_null($data)) {
            return null;
        }

        return [
            'event' => $data[0],
            'data' => $data[1] ?? null,
        ];
    }
public static function getPayload(string $packet)
    {
        $packet = trim($packet);
        $start = strpos($packet, '[');

        if ($start === false || substr($packet, -1) !== ']') {
            return null;
        }

        $data = substr($packet, $start, strlen($packet) - $start);
        $data = json_decode($data, true);

        if (is_null($data)) {
            return null;
        }

        return [
            'event' => $data[0],
            'data' => $data[1] ?? null,
        ];
    }
public static function getPayload ( string $ packet ) { $ packet = trim ( $ packet ) ; $ start = strpos ( $ packet , '[' ) ; if ( $ start === false || substr ( $ packet , - 1 ) !== ']' ) { return null ; } $ data = substr ( $ packet , $ start , strlen ( $ packet ) - $ start ) ; $ data = json_decode ( $ data , true ) ; if ( is_null ( $ data ) ) { return null ; } return [ 'event' => $ data [ 0 ] , 'data' => $ data [ 1 ] ?? null , ] ; }
Get data packet from a raw payload.

@param string $packet

@return array|null
Get data packet from a raw payload .