Exemplo n.º 1
0
 protected function fetchArticle(Command $command, ClientContext $context) : Generator
 {
     // Current article?
     if ($command->argCount() === 0) {
         if (!$context->getCursor()->valid()) {
             yield from $context->writeResponse(new Response(412, 'No newsgroup selected'));
             return;
         }
         return $context->getCursor()->getArticle();
     } elseif (is_numeric($command->arg(0))) {
         $number = (int) $command->arg(0);
         if (!$context->getCursor()->valid()) {
             yield from $context->writeResponse(new Response(412, 'No newsgroup selected'));
             return;
         }
         if (!(yield from $context->getCursor()->seek($number))) {
             yield from $context->writeResponse(new Response(423, 'No article with that number'));
             return;
         }
         return $context->getCursor()->getArticle();
     } else {
         $article = (yield from $context->getAccessLayer()->getArticleById($command->arg(0)));
         if (!$article) {
             yield from $context->writeResponse(new Response(430, 'No article with that message-id'));
             return;
         }
     }
     return $article;
 }
Exemplo n.º 2
0
 public function handle(Command $command, ClientContext $context) : Generator
 {
     // Make sure we have a valid cursor.
     if (!$context->getCursor()->valid()) {
         yield from $context->writeResponse(new Response(412, 'No newsgroup selected'));
         return;
     }
     // Try to move to the next article.
     if (!(yield from $context->getCursor()->next())) {
         yield from $context->writeResponse(new Response(421, 'No next article in this group'));
         return;
     }
     // Spit out the current article info.
     $article = $context->getCursor()->getArticle();
     yield from $context->writeResponse(new Response(223, '%d %s Article found', $article->number(), $article->id()));
 }
Exemplo n.º 3
0
 public function handle(Command $command, ClientContext $context) : Generator
 {
     if ($command->argCount() !== 1) {
         yield from $context->writeResponse(new Response(501, 'Invalid number of arguments'));
         return;
     }
     try {
         $name = $command->arg(0);
         $cursor = (yield from $context->getAccessLayer()->getGroupCursor($name));
         $context->setCursor($cursor);
     } catch (NotFoundException $e) {
         yield from $context->writeResponse(new Response(411, 'No such newsgroup'));
         return;
     }
     $group = $context->getCursor()->getGroup();
     yield from $context->writeResponse(new Response(211, $group->count() . ' ' . $group->lowWaterMark() . ' ' . $group->highWaterMark() . ' ' . $group->name() . ' Group successfully selected'));
 }