|
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
|
|
|
class ListCommand extends Command |
|
19
|
|
|
{ |
|
20
|
|
|
const KEYWORD_ACTIVE = 'ACTIVE'; |
|
21
|
|
|
const KEYWORD_ACTIVE_TIMES = 'ACTIVE.TIMES'; |
|
22
|
|
|
const KEYWORD_DISTRIB_PATS = 'DISTRIB.PATS'; |
|
23
|
|
|
const KEYWORD_HEADERS = 'HEADERS'; |
|
24
|
|
|
const KEYWORD_NEWSGROUPS = 'NEWSGROUPS'; |
|
25
|
|
|
const KEYWORD_OVERVIEW_FMT = 'OVERVIEW.FMT'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $keyword; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $arguments; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Constructor. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $keyword |
|
41
|
|
|
* @param string $arguments |
|
42
|
|
|
*/ |
|
43
|
6 |
|
public function __construct($keyword = null, $arguments = null) |
|
44
|
|
|
{ |
|
45
|
6 |
|
$this->keyword = $keyword; |
|
46
|
6 |
|
$this->arguments = $arguments; |
|
47
|
|
|
|
|
48
|
6 |
|
parent::__construct(true); |
|
49
|
6 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function __invoke() |
|
55
|
|
|
{ |
|
56
|
1 |
|
return trim(sprintf('LIST %s %s', $this->keyword, $this->arguments)); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param MultiLineResponse $response |
|
61
|
|
|
* |
|
62
|
|
|
* @return array |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function onListFollows(MultiLineResponse $response) |
|
65
|
|
|
{ |
|
66
|
1 |
|
$lines = $response->getLines(); |
|
67
|
1 |
|
$totalLines = count($lines); |
|
68
|
|
|
|
|
69
|
1 |
|
$result = []; |
|
70
|
|
|
|
|
71
|
1 |
|
for ($i = 0; $i < $totalLines; ++$i) { |
|
72
|
1 |
|
list($name, $high, $low, $status) = explode(' ', $lines[$i]); |
|
73
|
|
|
|
|
74
|
1 |
|
$result[$i] = [ |
|
75
|
1 |
|
'name' => $name, |
|
76
|
1 |
|
'high' => $high, |
|
77
|
1 |
|
'low' => $low, |
|
78
|
1 |
|
'status' => $status, |
|
79
|
|
|
]; |
|
80
|
1 |
|
} |
|
81
|
|
|
|
|
82
|
1 |
|
return $result; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
1 |
|
public function onInvalidKeyword(Response $response) |
|
86
|
|
|
{ |
|
87
|
1 |
|
throw new RuntimeException('Invalid keyword, or unexpected argument for keyword.', $response->getStatusCode()); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
1 |
|
public function onError(Response $response) |
|
91
|
|
|
{ |
|
92
|
1 |
|
throw new RuntimeException('Error retrieving group list', $response->getStatusCode()); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|