|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CybozuHttpBundle\Cybozu; |
|
4
|
|
|
|
|
5
|
|
|
use CybozuHttpBundle\Entity\CybozuAccountInterface; |
|
6
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @author ochi51 <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class Config |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var TokenStorageInterface |
|
16
|
|
|
*/ |
|
17
|
|
|
private $ts; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var CybozuAccountInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
private $user; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
private $certDir; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
private $logfile; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param TokenStorageInterface $ts |
|
36
|
|
|
* @param string|null $certDir |
|
37
|
|
|
* @param string|null $logfile |
|
38
|
|
|
*/ |
|
39
|
3 |
|
public function __construct(TokenStorageInterface $ts, $certDir = null, $logfile = null) |
|
40
|
|
|
{ |
|
41
|
3 |
|
$this->ts = $ts; |
|
42
|
3 |
|
$this->certDir = $certDir; |
|
43
|
3 |
|
$this->logfile = $logfile; |
|
44
|
|
|
|
|
45
|
3 |
|
$token = $ts->getToken(); |
|
46
|
3 |
|
if ($token && $token->getUser() instanceof CybozuAccountInterface) { |
|
47
|
2 |
|
$this->user = $token->getUser(); |
|
48
|
2 |
|
} |
|
49
|
3 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
3 |
|
public function getConfig() |
|
55
|
|
|
{ |
|
56
|
3 |
|
if ($this->user instanceof CybozuAccountInterface) { |
|
57
|
3 |
|
$config = $this->user->getCybozuHttpConfig(); |
|
58
|
3 |
|
$config['debug'] = $this->user->getDebugMode(); |
|
59
|
3 |
|
$config['logfile'] = $this->logfile; |
|
60
|
|
|
// This assumes to use KnpGaufretteBundle and VichUploaderBundle. |
|
61
|
|
|
// Entity has only key, so can't know directory. |
|
62
|
3 |
|
if (array_key_exists('cert_file', $config)) { |
|
63
|
3 |
|
$config['cert_file'] = $this->certDir . '/' . $config['cert_file']; |
|
64
|
3 |
|
} |
|
65
|
|
|
|
|
66
|
3 |
|
return $config; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
throw new \RuntimeException('User in token and this user done not implement CybozuAccountInterface.'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param CybozuAccountInterface $user |
|
74
|
|
|
* @return self |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function setUser(CybozuAccountInterface $user) |
|
77
|
|
|
{ |
|
78
|
1 |
|
$this->user = $user; |
|
79
|
|
|
|
|
80
|
1 |
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
} |