-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the NNTP library. | ||
* | ||
* (c) Robin van der Vleuten <robin@webstronauts.co> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rvdv\Nntp\Command; | ||
|
||
use Rvdv\Nntp\Exception\RuntimeException; | ||
use Rvdv\Nntp\Response\MultiLineResponse; | ||
use Rvdv\Nntp\Response\Response; | ||
|
||
/** | ||
* HeadCommand. | ||
* | ||
* @author elabz | ||
*/ | ||
class HeadCommand extends Command implements CommandInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $article; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param string $article | ||
*/ | ||
public function __construct($article) | ||
{ | ||
$this->article = $article; | ||
|
||
parent::__construct(true); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __invoke() | ||
{ | ||
return sprintf('HEAD %s', $this->article); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function onHeadFollows(MultiLineResponse $response) | ||
{ | ||
return array_reduce($response->getLines(), function ($headers, $line) { | ||
preg_match('/^([^\:]+)\:\s*(.*)$/', $line, $matches); | ||
if (!empty($matches)) { | ||
$headers[$matches[1]] = trim($matches[2]); | ||
} | ||
|
||
return $headers; | ||
}); | ||
} | ||
|
||
public function onNoNewsGroupCurrentSelected(Response $response) | ||
{ | ||
throw new RuntimeException('A group must be selected first before getting an article header.', $response->getStatusCode()); | ||
} | ||
|
||
public function onNoSuchArticleNumber(Response $response) | ||
{ | ||
throw new RuntimeException('No article with that number.', $response->getStatusCode()); | ||
} | ||
|
||
public function onNoSuchArticleId(Response $response) | ||
{ | ||
throw new RuntimeException('No article with that message-id.', $response->getStatusCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters