6b3bc94cd336238cd2479af242b304b847804103
[shpub.git] / src / shpub / Command / Reply.php
1 <?php
2 namespace shpub;
3
4 class Command_Reply extends Command_AbstractProps
5 {
6     public static function opts(\Console_CommandLine $optParser)
7     {
8         $cmd = $optParser->addCommand('reply');
9         static::optsGeneric($cmd);
10         $cmd->addArgument(
11             'url',
12             [
13                 'optional'    => false,
14                 'description' => 'URL that is replied to',
15             ]
16         );
17         $cmd->addArgument(
18             'text',
19             [
20                 'optional'    => false,
21                 'multiple'    => true,
22                 'description' => 'Reply text',
23             ]
24         );
25     }
26
27     public function run(\Console_CommandLine_Result $cmdRes)
28     {
29         $url = Validator::url($cmdRes->args['url'], 'url');
30         if ($url === false) {
31             exit(10);
32         }
33
34         $req = new Request($this->cfg->host, $this->cfg);
35         $req->setType('entry');
36         $req->addProperty('content', implode(' ', $cmdRes->args['text']));
37         $req->addProperty('in-reply-to', $url);
38
39         $this->handleGenericOptions($cmdRes, $req);
40         $res = $req->send();
41
42         $postUrl = $res->getHeader('Location');
43         Log::info('Reply created at server');
44         Log::msg($postUrl);
45     }
46 }
47 ?>