diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2013-11-22 21:32:06 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2013-11-22 21:32:06 +0100 |
| commit | f47ddf0758f120dfb26f03fb36be5cd897a10f23 (patch) | |
| tree | 9b64102a66eff570eee85c382688a2f1d423beb4 /src/phorkie/Notificator.php | |
| parent | 934246267dc4089dc0952bbe8412f32fd7346739 (diff) | |
| download | phorkie-f47ddf0758f120dfb26f03fb36be5cd897a10f23.tar.gz phorkie-f47ddf0758f120dfb26f03fb36be5cd897a10f23.zip | |
first work on remote fork notifications with linkback (webmention/pingback)
Diffstat (limited to 'src/phorkie/Notificator.php')
| -rw-r--r-- | src/phorkie/Notificator.php | 49 |
1 files changed, 18 insertions, 31 deletions
diff --git a/src/phorkie/Notificator.php b/src/phorkie/Notificator.php index 3ef5c81..dc6a6af 100644 --- a/src/phorkie/Notificator.php +++ b/src/phorkie/Notificator.php @@ -6,6 +6,21 @@ namespace phorkie; */ class Notificator { + protected $notificators = array(); + + public function __construct() + { + $this->loadNotificators(); + } + + protected function loadNotificators() + { + foreach ($GLOBALS['phorkie']['cfg']['notificator'] as $type => $config) { + $class = '\\phorkie\\Notificator_' . ucfirst($type); + $this->notificators[] = new $class($config); + } + } + /** * A repository has been created */ @@ -31,40 +46,12 @@ class Notificator } /** - * Call webhook URLs with our payload + * Call all notificator plugins */ protected function send($event, Repository $repo) { - if (count($GLOBALS['phorkie']['cfg']['webhooks']) == 0) { - return; - } - - /* slightly inspired by - https://help.github.com/articles/post-receive-hooks */ - $payload = (object) array( - 'event' => $event, - 'author' => array( - 'name' => $_SESSION['name'], - 'email' => $_SESSION['email'] - ), - 'repository' => array( - 'name' => $repo->getTitle(), - 'url' => $repo->getLink('display', null, true), - 'description' => $repo->getDescription(), - 'owner' => $repo->getOwner() - ) - ); - foreach ($GLOBALS['phorkie']['cfg']['webhooks'] as $url) { - $req = new \HTTP_Request2($url); - $req->setMethod(\HTTP_Request2::METHOD_POST) - ->setHeader('Content-Type: application/vnd.phorkie.webhook+json') - ->setBody(json_encode($payload)); - try { - $response = $req->send(); - //FIXME log response codes != 200 - } catch (HTTP_Request2_Exception $e) { - //FIXME log exceptions - } + foreach ($this->notificators as $notificator) { + $notificator->send($event, $repo); } } } |
