|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Mediapart Selligent Client API |
|
5
|
|
|
* |
|
6
|
|
|
* CC BY-NC-SA <https://github.com/mediapart/selligent> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Mediapart\Selligent; |
|
13
|
|
|
|
|
14
|
|
|
use Psr\Log\LogLevel; |
|
15
|
|
|
use Psr\Log\LoggerInterface; |
|
16
|
|
|
use Psr\Log\LoggerAwareInterface; |
|
17
|
|
|
use Mediapart\Selligent\Broadcast\Campaign; |
|
18
|
|
|
use Mediapart\Selligent\Request\CreateCampaign; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
class Broadcast implements LoggerAwareInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var \XMLWriter |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $writer; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \SoapClient |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $client; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var LoggerInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $logger = null; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param \SoapClient $client |
|
42
|
|
|
* @param string $list |
|
|
|
|
|
|
43
|
|
|
* @param string $campaign |
|
|
|
|
|
|
44
|
|
|
*/ |
|
45
|
3 |
|
public function __construct(\SoapClient $client) |
|
46
|
|
|
{ |
|
47
|
3 |
|
$this->writer = new \XMLWriter(); |
|
48
|
3 |
|
$this->client = $client; |
|
49
|
3 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritDoc} |
|
53
|
|
|
*/ |
|
54
|
2 |
|
public function setLogger(LoggerInterface $logger) |
|
55
|
|
|
{ |
|
56
|
2 |
|
$this->logger = $logger; |
|
57
|
2 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param Campaign $campaign |
|
61
|
|
|
* @return CreateCampaignResponse |
|
62
|
|
|
*/ |
|
63
|
3 |
|
public function triggerCampaign(Campaign $campaign) |
|
64
|
|
|
{ |
|
65
|
3 |
|
$request = new CreateCampaign($this->writer); |
|
66
|
3 |
|
$response = $this->client->CreateCampaign([ |
|
67
|
3 |
|
'Xml' => $request->basedOn($campaign) |
|
68
|
|
|
]); |
|
69
|
|
|
|
|
70
|
3 |
|
if ($this->logger) { |
|
71
|
|
|
|
|
72
|
2 |
|
if (Response::SUCCESSFUL !== $response->getCode()) { |
|
73
|
1 |
|
$level = LogLevel::ERROR; |
|
74
|
1 |
|
$message = 'triggerCampaign has failed'; |
|
75
|
|
|
} else { |
|
76
|
1 |
|
$level = LogLevel::INFO; |
|
77
|
1 |
|
$message = 'triggerCampaign with success'; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
2 |
|
$this->logger->log( |
|
81
|
2 |
|
$level, |
|
82
|
2 |
|
$message, |
|
83
|
|
|
[ |
|
84
|
|
|
'campaign' => [ |
|
85
|
2 |
|
'name' => $campaign->getName(), |
|
86
|
2 |
|
'status' => $campaign->getStatus(), |
|
|
|
|
|
|
87
|
2 |
|
'stdate' => $campaign->getStartDate()->format(\DateTime::RFC850), |
|
88
|
|
|
], |
|
89
|
|
|
'response' => [ |
|
90
|
2 |
|
'code' => $response->getCode(), |
|
91
|
2 |
|
'error' => $response->getError(), |
|
92
|
2 |
|
'result' => $response->getXml(), |
|
93
|
|
|
], |
|
94
|
|
|
] |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
3 |
|
return $response; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.