automatically configure git paths (dir + public clone url)
[phorkie.git] / src / phorkie / Notificator / Linkback.php
1 <?php
2 namespace phorkie;
3
4 /**
5  * Send out linkbacks for the remote paste URL when it gets forked here
6  */
7 class Notificator_Linkback
8 {
9     protected $config;
10
11     public function __construct($config)
12     {
13         $this->config = $config;
14     }
15
16     /**
17      * Send linkback on "create" events to remote repositories
18      */
19     public function send($event, Repository $repo)
20     {
21         if ($this->config === false) {
22             return;
23         }
24
25         if ($event != 'create') {
26             return;
27         }
28
29         $origin = $repo->getConnectionInfo()->getOrigin();
30         if ($origin === null) {
31             return;
32         }
33         $originWebUrl = $origin->getWebUrl(true);
34         if ($originWebUrl === null) {
35             return;
36         }
37
38
39         $this->pbc = new \PEAR2\Services\Linkback\Client();
40         $req = $this->pbc->getRequest();
41         $req->setConfig(
42             array(
43                 'ssl_verify_peer' => false,
44                 'ssl_verify_host' => false
45             )
46         );
47         $this->pbc->setRequestTemplate($req);
48         $req->setHeader('user-agent', 'phorkie');
49         try {
50             $res = $this->pbc->send(
51                 $repo->getLink('display', null, true),
52                 $originWebUrl
53             );
54         } catch (\Exception $e) {
55             //FIXME: log errors
56         }
57     }
58 }
59 ?>