|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaFourchette\AdobeCampaignClientBundle\Client; |
|
4
|
|
|
|
|
5
|
|
|
use LaFourchette\AdobeCampaignClientBundle\Exception\ConfigurationCreationException; |
|
6
|
|
|
use LaFourchette\AdobeCampaignClientBundle\Util\AdobeCampaignXmlLoader; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Create a Adobe Configuration object with security informations |
|
10
|
|
|
*/ |
|
11
|
|
|
class ConfigurationCreator |
|
12
|
|
|
{ |
|
13
|
|
|
const SOAP_MESSAGE_PAYLOAD = <<<EOT |
|
14
|
|
|
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:xtk:session"> |
|
15
|
|
|
<x:Header/> |
|
16
|
|
|
<x:Body> |
|
17
|
|
|
<urn:Logon> |
|
18
|
|
|
<urn:sessiontoken/> |
|
19
|
|
|
<urn:strLogin>%s</urn:strLogin> |
|
20
|
|
|
<urn:strPassword>%s</urn:strPassword> |
|
21
|
|
|
<urn:elemParameters/> |
|
22
|
|
|
</urn:Logon> |
|
23
|
|
|
</x:Body> |
|
24
|
|
|
</x:Envelope> |
|
25
|
|
|
EOT; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var ClientInstantiator |
|
29
|
|
|
*/ |
|
30
|
|
|
private $clientInstantiator; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var array Configuration informations |
|
34
|
|
|
*/ |
|
35
|
|
|
private $config; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param ClientInstantiator $clientInstantiator |
|
39
|
|
|
* @param array $config |
|
40
|
|
|
*/ |
|
41
|
3 |
|
public function __construct(ClientInstantiator $clientInstantiator, $config) |
|
42
|
|
|
{ |
|
43
|
3 |
|
$this->clientInstantiator = $clientInstantiator; |
|
44
|
3 |
|
$this->config = $config; |
|
45
|
3 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Create a Configuration object |
|
49
|
|
|
* |
|
50
|
|
|
* @return Configuration |
|
51
|
|
|
*/ |
|
52
|
3 |
|
public function create() |
|
53
|
|
|
{ |
|
54
|
3 |
|
$soapClient = $this->clientInstantiator->instantiateBasicClient(null, array( |
|
55
|
3 |
|
'location' => $this->config['base_uri'].Client::SOAP_ROUTER_PATH, |
|
56
|
3 |
|
'uri' => $this->config['base_uri'], |
|
57
|
|
|
'trace' => 1 |
|
58
|
3 |
|
)); |
|
59
|
|
|
|
|
60
|
|
|
try { |
|
61
|
3 |
|
$response = $soapClient->__doRequest( |
|
62
|
3 |
|
sprintf(self::SOAP_MESSAGE_PAYLOAD, $this->config['login'], $this->config['password']), |
|
63
|
3 |
|
$this->config['base_uri'].Client::SOAP_ROUTER_PATH, |
|
64
|
3 |
|
'xtk:session#Logon', |
|
65
|
|
|
1 |
|
66
|
3 |
|
); |
|
67
|
3 |
|
} catch(\Exception $e) { |
|
68
|
1 |
|
throw new ConfigurationCreationException($e->getMessage(), $e->getCode(), $e); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
2 |
|
if (null === $response) { |
|
72
|
1 |
|
throw new ConfigurationCreationException('Empty response received'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
$xmlResponse = AdobeCampaignXmlLoader::loadXml($response); |
|
76
|
|
|
|
|
77
|
1 |
|
$xmlSessionToken = $xmlResponse->xpath('/Envelope/Body/LogonResponse/pstrSessionToken'); |
|
78
|
1 |
|
$session = array_pop($xmlSessionToken)->__toString(); |
|
79
|
|
|
|
|
80
|
1 |
|
$xmlSecurityToken = $xmlResponse->xpath('/Envelope/Body/LogonResponse/pstrSecurityToken'); |
|
81
|
1 |
|
$security = array_pop($xmlSecurityToken)->__toString(); |
|
82
|
|
|
|
|
83
|
1 |
|
$configuration = new Configuration(); |
|
84
|
1 |
|
$configuration->setBaseUri($this->config['base_uri']); |
|
85
|
1 |
|
$configuration->setSecurity($security); |
|
86
|
1 |
|
$configuration->setSession($session); |
|
87
|
|
|
|
|
88
|
1 |
|
return $configuration; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|