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\MultiLineResponse; |
16
|
|
|
use Rvdv\Nntp\Response\Response; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* HeadCommand. |
20
|
|
|
* |
21
|
|
|
* @author elabz |
22
|
|
|
*/ |
23
|
|
|
class HeadCommand extends Command implements CommandInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $article; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Constructor. |
32
|
|
|
* |
33
|
|
|
* @param string $article |
34
|
|
|
*/ |
35
|
|
|
public function __construct($article) |
36
|
|
|
{ |
37
|
|
|
$this->article = $article; |
38
|
|
|
|
39
|
|
|
parent::__construct(true); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function __invoke() |
46
|
|
|
{ |
47
|
|
|
return sprintf('HEAD %s', $this->article); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function onHeadFollows(MultiLineResponse $response) |
54
|
|
|
{ |
55
|
|
|
$headers = []; |
56
|
|
|
array_map(function ($line) use (&$headers) { |
57
|
|
|
preg_match('/^([^\:]+)\:\s*(.*)$/', $line, $matches); |
58
|
|
|
if (!empty($matches)) { |
59
|
|
|
$headers[$matches[1]] = trim($matches[2]); |
60
|
|
|
} |
61
|
|
|
}, $response->getLines()); |
62
|
|
|
|
63
|
|
|
return $headers; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function onNoNewsGroupCurrentSelected(Response $response) |
67
|
|
|
{ |
68
|
|
|
throw new RuntimeException('A group must be selected first before getting an article header.', $response->getStatusCode()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function onNoSuchArticleNumber(Response $response) |
72
|
|
|
{ |
73
|
|
|
throw new RuntimeException('No article with that number.', $response->getStatusCode()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function onNoSuchArticleId(Response $response) |
77
|
|
|
{ |
78
|
|
|
throw new RuntimeException('No article with that message-id.', $response->getStatusCode()); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|