示例#1
0
 public function handle(Command $command, ClientContext $context) : Generator
 {
     if (!$context->getAccessLayer()->isPostingAllowed()) {
         yield from $context->writeResponse(new Response(440, 'Posting not permitted'));
         return;
     }
     yield from $context->writeResponse(new Response(340, 'Send article to be posted'));
     $data = (yield from $context->readData());
     $article = Article::parse($data);
     try {
         yield from $context->getAccessLayer()->postArticle($article);
         yield from $context->writeResponse(new Response(240, 'Article received OK'));
     } catch (\Throwable $e) {
         yield from $context->writeResponse(new Response(441, 'Posting failed'));
     }
 }
示例#2
0
 /**
  * Gets an article by its number in the current newsgroup.
  */
 public function getArticleByNumber(int $number) : Generator
 {
     yield from $this->sendCommand(new Command('ARTICLE', (string) $number));
     $data = (yield from $this->encoder->readData($this->stream));
     return Article::parse($data);
 }