Skip to content

Commit 7872e75

Browse files
committed
fixes #17 #18 AbstractAuthentication, fix Password constructor and add Rsa password capability
1 parent 981db54 commit 7872e75

File tree

4 files changed

+40
-43
lines changed

4 files changed

+40
-43
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
4+
namespace Jumper\Communicator\Authentication;
5+
6+
/**
7+
* Class AbstractAuthentication
8+
*
9+
* @package Jumper\Communicator\Authentication
10+
* @author Thibaud Leprêtre
11+
* @license MIT
12+
*/
13+
abstract class AbstractAuthentication
14+
{
15+
protected $user;
16+
17+
public function __construct($user)
18+
{
19+
$this->user = $user;
20+
}
21+
22+
public function getUser()
23+
{
24+
return $this->user;
25+
}
26+
}

src/Jumper/Communicator/Authentication/None.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@
1111
* @author Thibaud Leprêtre
1212
* @license MIT
1313
*/
14-
class None implements Authentication
14+
class None extends AbstractAuthentication implements Authentication
1515
{
16+
1617
/**
17-
* @var string user
18+
* @param string $user
1819
*/
19-
private $user;
20-
2120
public function __construct($user)
2221
{
23-
$this->user = $user;
22+
parent::__construct($user);
2423
}
2524

2625
/**
@@ -31,11 +30,4 @@ public function getAuthentication()
3130
return null;
3231
}
3332

34-
/**
35-
* @return string user
36-
*/
37-
public function getUser()
38-
{
39-
return $this->user;
40-
}
4133
}

src/Jumper/Communicator/Authentication/Password.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,30 @@
1111
* @author Thibaud Leprêtre
1212
* @license MIT
1313
*/
14-
class Password implements Authentication
14+
class Password extends AbstractAuthentication implements Authentication
1515
{
1616

17-
/**
18-
* @var string user
19-
*/
20-
private $user;
21-
2217
/**
2318
* @var string password
2419
*/
2520
private $password;
2621

2722
/**
2823
* @param string $user
29-
* @param $password
24+
* @param string $password
3025
*/
31-
public function _construct($user, $password)
26+
public function __construct($user, $password)
3227
{
33-
$this->user = $user;
28+
parent::__construct($user);
3429
$this->password = $password;
3530
}
3631

3732
/**
38-
* @return mixed
33+
* @return string
3934
*/
4035
public function getAuthentication()
4136
{
4237
return $this->password;
4338
}
4439

45-
/**
46-
* @return mixed
47-
*/
48-
public function getUser()
49-
{
50-
return $this->user;
51-
}
5240
}

src/Jumper/Communicator/Authentication/Rsa.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@
1212
* @author Thibaud Leprêtre
1313
* @license MIT
1414
*/
15-
class Rsa implements Authentication
15+
class Rsa extends AbstractAuthentication implements Authentication
1616
{
1717

18-
/**
19-
* @var string user
20-
*/
21-
private $user;
22-
2318
/**
2419
* @var string rsa key path
2520
*/
@@ -37,7 +32,7 @@ class Rsa implements Authentication
3732
*/
3833
public function __construct($user, $key, $password = null)
3934
{
40-
$this->user = $user;
35+
parent::__construct($user);
4136
$this->key = $key;
4237
$this->password = $password;
4338
}
@@ -49,14 +44,10 @@ public function getAuthentication()
4944
{
5045
$key = new RsaKey();
5146
$key->loadKey(file_get_contents($this->key));
47+
if (!isNull($this->password)) {
48+
$key->setPassword($this->password);
49+
}
5250
return $key;
5351
}
5452

55-
/**
56-
* @return string user
57-
*/
58-
public function getUser()
59-
{
60-
return $this->user;
61-
}
6253
}

0 commit comments

Comments
 (0)