debug option to print curl requests
[shpub.git] / src / shpub / Command / Reply.php
1 <?php
2 namespace shpub;
3
4 class Command_Reply
5 {
6     /**
7      * @var Config
8      */
9     protected $cfg;
10
11     public function __construct($cfg)
12     {
13         $this->cfg = $cfg;
14     }
15
16     public function run($url, $text)
17     {
18         $url = Validator::url($url, 'url');
19         if ($url === false) {
20             exit(10);
21         }
22
23         $body = http_build_query(
24             [
25                 'h'           => 'entry',
26                 'content'     => $text,
27                 'in-reply-to' => $url,
28             ]
29         );
30
31         $req = new Request($this->cfg->host, $this->cfg);
32         $res = $req->send($body);
33         $postUrl = $res->getHeader('Location');
34         echo "Reply created at server\n";
35         echo $postUrl . "\n";
36     }
37 }
38 ?>