1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the NNTP library. |
5
|
|
|
* |
6
|
|
|
* (c) Robin van der Vleuten <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Rvdv\Nntp\Command; |
13
|
|
|
|
14
|
|
|
use Rvdv\Nntp\Exception\RuntimeException; |
15
|
|
|
use Rvdv\Nntp\Response\Response; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* PostCommand |
19
|
|
|
* |
20
|
|
|
* @author thebandit |
21
|
|
|
*/ |
22
|
|
|
class PostArticleCommand extends Command implements CommandInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $groups; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $subject; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $body; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $from; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $headers; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Constructor. |
51
|
|
|
*/ |
52
|
8 |
|
public function __construct($groups, $subject, $body, $from, $headers) |
53
|
|
|
{ |
54
|
8 |
|
$this->groups = $groups; |
55
|
8 |
|
$this->subject = $subject; |
56
|
8 |
|
$this->body = $body; |
57
|
8 |
|
$this->from = $from; |
58
|
8 |
|
$this->headers = $headers; |
59
|
|
|
|
60
|
8 |
|
parent::__construct(array()); |
61
|
8 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
1 |
|
public function execute() |
67
|
|
|
{ |
68
|
1 |
|
$article = "From: ".$this->from."\r\n"; |
69
|
1 |
|
$article .= "Newsgroups: ".$this->groups."\r\n"; |
70
|
1 |
|
$article .= "Subject: ".$this->subject."\r\n"; |
71
|
1 |
|
$article .= "X-poster: php-nntp\r\n"; |
72
|
1 |
|
if ($this->headers !== null) { |
73
|
|
|
$article .= $this->headers."\r\n"; |
74
|
|
|
} |
75
|
1 |
|
$article .= "\r\n"; |
76
|
1 |
|
$article .= $this->body; |
77
|
|
|
|
78
|
1 |
|
return $article; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
2 |
|
public function getExpectedResponseCodes() |
85
|
|
|
{ |
86
|
|
|
return array( |
87
|
2 |
|
Response::ARTICLE_RECEIVED => 'onArticleReceived', |
88
|
2 |
|
Response::POSTING_FAILED => 'onPostingFailed', |
89
|
2 |
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
public function onArticleReceived(Response $response) |
|
|
|
|
93
|
|
|
{ |
94
|
1 |
|
return true; |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
public function onPostingFailed(Response $response) |
98
|
|
|
{ |
99
|
1 |
|
throw new RuntimeException(sprintf('Posting failed: %s', $response->getMessage()), $response->getStatusCode()); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.