1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Hello\Models\Clients; |
4
|
|
|
|
5
|
|
|
use ByTIC\Hello\Utility\RandomHelper; |
6
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
7
|
|
|
use League\OAuth2\Server\Entities\Traits\ClientTrait; |
8
|
|
|
use League\OAuth2\Server\Entities\Traits\EntityTrait; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Token |
12
|
|
|
* @package ByTIC\Hello\Models\Clients |
13
|
|
|
*/ |
14
|
|
|
class Client extends \Nip\Records\Record implements ClientEntityInterface |
15
|
|
|
{ |
16
|
1 |
|
use ClientTrait; |
17
|
1 |
|
use EntityTrait; |
18
|
1 |
|
use Traits\ClientHasGrantsTrait; |
|
|
|
|
19
|
1 |
|
use Traits\ClientHasSecretTrait; |
20
|
1 |
|
use Traits\ClientHasRedirectTrait; |
21
|
|
|
|
22
|
20 |
|
public function __construct() |
23
|
|
|
{ |
24
|
20 |
|
$this->setIdentifier(RandomHelper::generateIdentifier()); |
25
|
20 |
|
$this->setSecret(RandomHelper::generateToken()); |
26
|
20 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @inheritDoc |
30
|
|
|
*/ |
31
|
10 |
|
public function writeData($data = false) |
32
|
|
|
{ |
33
|
10 |
|
parent::writeData($data); |
34
|
|
|
|
35
|
10 |
|
if (isset($data['grant_types']) && !empty($data['grant_types'])) { |
36
|
2 |
|
$this->initGrantsFromDb($data['grant_types']); |
37
|
|
|
} |
38
|
|
|
|
39
|
10 |
|
if (isset($data['identifier']) && !empty($data['identifier'])) { |
40
|
1 |
|
$this->initIdentifierFromDb($data['identifier']); |
41
|
|
|
} |
42
|
10 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritDoc |
46
|
|
|
*/ |
47
|
20 |
|
public function setIdentifier($identifier) |
48
|
|
|
{ |
49
|
20 |
|
$this->setDataValue('identifier', $identifier); |
|
|
|
|
50
|
20 |
|
$this->identifier = $identifier; |
51
|
20 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param null $data |
|
|
|
|
55
|
|
|
*/ |
56
|
1 |
|
public function initIdentifierFromDb($data = null) |
57
|
|
|
{ |
58
|
1 |
|
$data = $data === null ? $this->_data['identifier'] : $data; |
|
|
|
|
59
|
1 |
|
if (!empty($data)) { |
60
|
1 |
|
$this->setIdentifier($data); |
61
|
|
|
} |
62
|
1 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param mixed $name |
66
|
|
|
*/ |
67
|
4 |
|
public function setName($name) |
68
|
|
|
{ |
69
|
4 |
|
$this->name = $name; |
70
|
4 |
|
parent::setDataValue('name', $name); |
|
|
|
|
71
|
4 |
|
} |
72
|
|
|
} |
73
|
|
|
|