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 
15 
19 abstract class Base implements MessageInterface
20 {
22  protected $user;
23 
25  protected $service;
26 
28  protected $method;
29 
42  public function __construct($user, $service, $method)
43  {
44  if (!is_string($user)) {
45  throw new \InvalidArgumentException();
46  }
47  if (!is_string($service)) {
48  throw new \InvalidArgumentException();
49  }
50  if (!is_string($method)) {
51  throw new \InvalidArgumentException();
52  }
53 
54  $this->user = $user;
55  $this->service = $service;
56  $this->method = $method;
57  }
58 
59  public static function getMessageId()
60  {
61  return 50;
62  }
63 
64  public function serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
65  {
66  $encoder->encodeString($this->user);
67  $encoder->encodeString($this->service);
68  $encoder->encodeString($this->method);
69  return $this;
70  }
71 
88  protected static function unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
89  {
90  throw new \RuntimeException();
91  }
92 
93  final public static function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
94  {
95  $reflector = new \ReflectionClass(get_called_class());
96  $args = array_merge(
97  array(
98  $decoder->decodeString(),
99  $decoder->decodeString(),
100  $decoder->decodeString()
101  ),
102  static::unserializeSub($decoder)
103  );
104  return $reflector->newInstanceArgs($args);
105  }
106 
113  public function getUserName()
114  {
115  return $this->user;
116  }
117 
125  public function getServiceName()
126  {
127  return $this->service;
128  }
129 
136  public function getMethodName()
137  {
138  return $this->method;
139  }
140 }
__construct($user, $service, $method)
Definition: Base.php:42
static unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
Definition: Base.php:93
$user
User being authenticated.
Definition: Base.php:22
serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
Definition: Base.php:64
static unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
Definition: Base.php:88
$service
Service to start after authentication.
Definition: Base.php:25