automatically configure git paths (dir + public clone url)
[phorkie.git] / src / phorkie / Notificator.php
1 <?php
2 namespace phorkie;
3
4 /**
5  * Send out webhook callbacks when something happens
6  */
7 class Notificator
8 {
9     protected $notificators = array();
10
11     public function __construct()
12     {
13         $this->loadNotificators();
14     }
15
16     protected function loadNotificators()
17     {
18         foreach ($GLOBALS['phorkie']['cfg']['notificator'] as $type => $config) {
19             $class = '\\phorkie\\Notificator_' . ucfirst($type);
20             $this->notificators[] = new $class($config);
21         }
22     }
23
24     /**
25      * A repository has been created
26      */
27     public function create(Repository $repo)
28     {
29         $this->send('create', $repo);
30     }
31
32     /**
33      * A repository has been modified
34      */
35     public function edit(Repository $repo)
36     {
37         $this->send('edit', $repo);
38     }
39
40     /**
41      * A repository has been deleted
42      */
43     public function delete(Repository $repo)
44     {
45         $this->send('delete', $repo);
46     }
47
48     /**
49      * Call all notificator plugins
50      */
51     protected function send($event, Repository $repo)
52     {
53         foreach ($this->notificators as $notificator) {
54             $notificator->send($event, $repo);
55         }
56     }
57 }
58 ?>