mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
23786784ef
Summary: Adds the Balanced PHP API to externals/. Ref T2787. Test Plan: Used in next diff. Reviewers: btrahan, chad Reviewed By: chad CC: aran, aurelijus Maniphest Tasks: T2787 Differential Revision: https://secure.phabricator.com/D5764
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace RESTful;
|
|
|
|
class Collection extends Itemization
|
|
{
|
|
public function __construct($resource, $uri, $data = null)
|
|
{
|
|
parent::__construct($resource, $uri, $data);
|
|
$this->_parseUri();
|
|
}
|
|
|
|
private function _parseUri()
|
|
{
|
|
$parsed = parse_url($this->uri);
|
|
$this->_uri = $parsed['path'];
|
|
if (array_key_exists('query', $parsed)) {
|
|
foreach (explode('&', $parsed['query']) as $param) {
|
|
$param = explode('=', $param);
|
|
$key = urldecode($param[0]);
|
|
$val = (count($param) == 1) ? null : urldecode($param[1]);
|
|
|
|
// size
|
|
if ($key == 'limit') {
|
|
$this->_size = $val;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function create($payload)
|
|
{
|
|
$class = $this->resource;
|
|
$client = $class::getClient();
|
|
$response = $client->post($this->uri, $payload);
|
|
|
|
return new $this->resource($response->body);
|
|
}
|
|
|
|
public function query()
|
|
{
|
|
return new Query($this->resource, $this->uri);
|
|
}
|
|
|
|
public function paginate()
|
|
{
|
|
return new Pagination($this->resource, $this->uri);
|
|
}
|
|
}
|