[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/metamta/contentsource/ -> PhabricatorContentSource.php (source)

   1  <?php
   2  
   3  final class PhabricatorContentSource {
   4  
   5    const SOURCE_UNKNOWN  = 'unknown';
   6    const SOURCE_WEB      = 'web';
   7    const SOURCE_EMAIL    = 'email';
   8    const SOURCE_CONDUIT  = 'conduit';
   9    const SOURCE_MOBILE   = 'mobile';
  10    const SOURCE_TABLET   = 'tablet';
  11    const SOURCE_FAX      = 'fax';
  12    const SOURCE_CONSOLE  = 'console';
  13    const SOURCE_HERALD   = 'herald';
  14    const SOURCE_LEGACY   = 'legacy';
  15    const SOURCE_DAEMON   = 'daemon';
  16    const SOURCE_LIPSUM   = 'lipsum';
  17    const SOURCE_PHORTUNE = 'phortune';
  18  
  19    private $source;
  20    private $params = array();
  21  
  22    private function __construct() {
  23      // <empty>
  24    }
  25  
  26    public static function newForSource($source, array $params) {
  27      $obj = new PhabricatorContentSource();
  28      $obj->source = $source;
  29      $obj->params = $params;
  30  
  31      return $obj;
  32    }
  33  
  34    public static function newFromSerialized($serialized) {
  35      $dict = json_decode($serialized, true);
  36      if (!is_array($dict)) {
  37        $dict = array();
  38      }
  39  
  40      $obj = new PhabricatorContentSource();
  41      $obj->source = idx($dict, 'source', self::SOURCE_UNKNOWN);
  42      $obj->params = idx($dict, 'params', array());
  43  
  44      return $obj;
  45    }
  46  
  47    public static function newConsoleSource() {
  48      return self::newForSource(
  49        PhabricatorContentSource::SOURCE_CONSOLE,
  50        array());
  51    }
  52  
  53    public static function newFromRequest(AphrontRequest $request) {
  54      return self::newForSource(
  55        PhabricatorContentSource::SOURCE_WEB,
  56        array(
  57          'ip' => $request->getRemoteAddr(),
  58        ));
  59    }
  60  
  61    public static function newFromConduitRequest(ConduitAPIRequest $request) {
  62      return self::newForSource(
  63        PhabricatorContentSource::SOURCE_CONDUIT,
  64        array());
  65    }
  66  
  67    public static function getSourceNameMap() {
  68      return array(
  69        self::SOURCE_WEB      => pht('Web'),
  70        self::SOURCE_EMAIL    => pht('Email'),
  71        self::SOURCE_CONDUIT  => pht('Conduit'),
  72        self::SOURCE_MOBILE   => pht('Mobile'),
  73        self::SOURCE_TABLET   => pht('Tablet'),
  74        self::SOURCE_FAX      => pht('Fax'),
  75        self::SOURCE_CONSOLE  => pht('Console'),
  76        self::SOURCE_LEGACY   => pht('Legacy'),
  77        self::SOURCE_HERALD   => pht('Herald'),
  78        self::SOURCE_DAEMON   => pht('Daemons'),
  79        self::SOURCE_LIPSUM   => pht('Lipsum'),
  80        self::SOURCE_UNKNOWN  => pht('Old World'),
  81        self::SOURCE_PHORTUNE => pht('Phortune'),
  82      );
  83    }
  84  
  85    public function serialize() {
  86      return json_encode(array(
  87        'source' => $this->getSource(),
  88        'params' => $this->getParams(),
  89      ));
  90    }
  91  
  92    public function getSource() {
  93      return $this->source;
  94    }
  95  
  96    public function getParams() {
  97      return $this->params;
  98    }
  99  
 100    public function getParam($key, $default = null) {
 101      return idx($this->params, $key, $default);
 102    }
 103  
 104  }


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