[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/externals/restful/src/RESTful/ -> Page.php (source)

   1  <?php
   2  
   3  namespace RESTful;
   4  
   5  class Page
   6  {
   7      public $resource,
   8          $total,
   9          $items,
  10          $offset,
  11          $limit;
  12  
  13      private $_first_uri,
  14          $_previous_uri,
  15          $_next_uri,
  16          $_last_uri;
  17  
  18      public function __construct($resource, $uri, $data = null)
  19      {
  20          $this->resource = $resource;
  21          if ($data == null) {
  22              $client = $resource::getClient();
  23              $data = $client->get($uri)->body;
  24          }
  25          $this->total = $data->total;
  26          $this->items = array_map(
  27              function ($x) use ($resource) {
  28                  return new $resource($x);
  29              },
  30              $data->items);
  31          $this->offset = $data->offset;
  32          $this->limit = $data->limit;
  33          $this->_first_uri = property_exists($data, 'first_uri') ? $data->first_uri : null;
  34          $this->_previous_uri = property_exists($data, 'previous_uri') ? $data->previous_uri : null;
  35          $this->_next_uri = property_exists($data, 'next_uri') ? $data->next_uri : null;
  36          $this->_last_uri = property_exists($data, 'last_uri') ? $data->last_uri : null;
  37      }
  38  
  39      public function first()
  40      {
  41          return new Page($this->resource, $this->_first_uri);
  42      }
  43  
  44      public function next()
  45      {
  46          if (!$this->hasNext()) {
  47              return null;
  48          }
  49  
  50          return new Page($this->resource, $this->_next_uri);
  51      }
  52  
  53      public function hasNext()
  54      {
  55          return $this->_next_uri != null;
  56      }
  57  
  58      public function previous()
  59      {
  60          return new Page($this->resource, $this->_previous_uri);
  61      }
  62  
  63      public function hasPrevious()
  64      {
  65          return $this->_previous_uri != null;
  66      }
  67  
  68      public function last()
  69      {
  70          return new Page($this->resource, $this->_last_uri);
  71      }
  72  }


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