[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/notification/client/ -> PhabricatorNotificationClient.php (source)

   1  <?php
   2  
   3  final class PhabricatorNotificationClient {
   4  
   5    const EXPECT_VERSION = 6;
   6  
   7    public static function getServerStatus() {
   8      $uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
   9      $uri = new PhutilURI($uri);
  10  
  11      $uri->setPath('/status/');
  12  
  13      list($body) = id(new HTTPSFuture($uri))
  14        ->setTimeout(3)
  15        ->resolvex();
  16  
  17      $status = json_decode($body, true);
  18      if (!is_array($status)) {
  19        throw new Exception(
  20          pht(
  21            'Expected JSON response from notification server, received: %s',
  22            $body));
  23      }
  24  
  25      return $status;
  26    }
  27  
  28    public static function tryToPostMessage(array $data) {
  29      if (!PhabricatorEnv::getEnvConfig('notification.enabled')) {
  30        return;
  31      }
  32  
  33      try {
  34        self::postMessage($data);
  35      } catch (Exception $ex) {
  36        // Just ignore any issues here.
  37        phlog($ex);
  38      }
  39    }
  40  
  41    private static function postMessage(array $data) {
  42      $server_uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
  43      $server_uri = id(new PhutilURI($server_uri))
  44        ->setPath('/');
  45  
  46      id(new HTTPSFuture($server_uri, json_encode($data)))
  47        ->setMethod('POST')
  48        ->setTimeout(1)
  49        ->resolvex();
  50    }
  51  
  52  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1