예제 #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;
 }
예제 #2
0
 public function writeCommand(WritableStream $stream, Command $command) : Generator
 {
     yield from $stream->write($command->name());
     foreach ($command->args() as $arg) {
         yield from $stream->write(' ' . $arg);
     }
     yield from $stream->write("\r\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'));
 }