You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
636 B

<?php
namespace WebSocket\Message;
use WebSocket\BadOpcodeException;
class Factory
{
public function create(string $opcode, string $payload = ''): Message
{
switch ($opcode) {
case 'text':
return new Text($payload);
case 'binary':
return new Binary($payload);
case 'ping':
return new Ping($payload);
case 'pong':
return new Pong($payload);
case 'close':
return new Close($payload);
}
throw new BadOpcodeException("Invalid opcode '{$opcode}' provided");
}
}