pssht  latest
SSH server library written in PHP
Base.php
1 <?php
2 
3 /*
4 * This file is part of pssht.
5 *
6 * (c) François Poirotte <clicky@erebot.net>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 
13 
18 {
20  protected $type;
21 
23  protected $wantReply;
24 
25 
36  public function __construct($channel, $type, $wantReply)
37  {
38  if (!is_string($type)) {
39  throw new \InvalidArgumentException();
40  }
41 
42  if (!is_bool($wantReply)) {
43  throw new \InvalidArgumentException();
44  }
45 
46  parent::__construct($channel);
47  $this->type = $type;
48  $this->wantReply = $wantReply;
49  }
50 
51  public static function getMessageId()
52  {
53  return 98;
54  }
55 
56  public function serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
57  {
58  parent::serialize($encoder);
59  $encoder->encodeString($this->type);
60  $encoder->encodeBoolean($this->wantReply);
61  return $this;
62  }
63 
80  protected static function unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
81  {
82  throw new \RuntimeException();
83  }
84 
85  final public static function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
86  {
87  $reflector = new \ReflectionClass(get_called_class());
88  $args = array_merge(
89  array(
90  $decoder->decodeUint32(), // channel
91  $decoder->decodeString(),
92  $decoder->decodeBoolean()
93  ),
94  static::unserializeSub($decoder)
95  );
96  return $reflector->newInstanceArgs($args);
97  }
98 
105  public function getType()
106  {
107  return $this->type;
108  }
109 
117  public function wantsReply()
118  {
119  return $this->wantReply;
120  }
121 }
$channel
Local channel identifier.
Definition: Base.php:20
$wantReply
Whether the sender of the message wants a reply or not.
Definition: Base.php:23
serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
Definition: Base.php:56
__construct($channel, $type, $wantReply)
Definition: Base.php:36
static unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
Definition: Base.php:85
static unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
Definition: Base.php:80