1
|
|
|
<?php |
2
|
|
|
namespace Cassandra\Request; |
3
|
|
|
use Cassandra\Protocol\Frame; |
4
|
|
|
|
5
|
|
|
class Startup extends Request{ |
6
|
|
|
|
7
|
|
|
protected $opcode = Frame::OPCODE_STARTUP; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* |
11
|
|
|
* @var array |
12
|
|
|
*/ |
13
|
|
|
protected $_options = []; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* STARTUP |
17
|
|
|
* |
18
|
|
|
* Initialize the connection. The server will respond by either a READY message |
19
|
|
|
* (in which case the connection is ready for queries) or an AUTHENTICATE message |
20
|
|
|
* (in which case credentials will need to be provided using CREDENTIALS). |
21
|
|
|
* |
22
|
|
|
* This must be the first message of the connection, except for OPTIONS that can |
23
|
|
|
* be sent before to find out the options supported by the server. Once the |
24
|
|
|
* connection has been initialized, a client should not send any more STARTUP |
25
|
|
|
* message. |
26
|
|
|
* |
27
|
|
|
* Possible options are: |
28
|
|
|
* - "CQL_VERSION": the version of CQL to use. This option is mandatory and |
29
|
|
|
* currenty, the only version supported is "3.0.0". Note that this is |
30
|
|
|
* different from the protocol version. |
31
|
|
|
* - "COMPRESSION": the compression algorithm to use for frames (See section 5). |
32
|
|
|
* This is optional, if not specified no compression will be used. |
33
|
|
|
* |
34
|
|
|
* @param array $options |
35
|
|
|
*/ |
36
|
|
|
public function __construct(array $options = []) { |
37
|
|
|
$this->_options = $options; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getBody(){ |
41
|
|
|
$body = pack('n', count($this->_options)); |
42
|
|
|
foreach ($this->_options as $name => $value) { |
43
|
|
|
$body .= pack('n', strlen($name)) . $name; |
44
|
|
|
$body .= pack('n', strlen($value)) . $value; |
45
|
|
|
} |
46
|
|
|
return $body; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|