mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
add logic for get One and get First, update phpDocs
This commit is contained in:
@@ -37,15 +37,14 @@ class Collection
|
|||||||
* @param array $queryParams
|
* @param array $queryParams
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getFullList(int $batch = 200, array $queryParams = [])
|
public function getFullList(int $batch = 200, array $queryParams = []){
|
||||||
{
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/" . $this->collection . "/records");
|
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/".$this->collection."/records");
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
if (self::$token != '') {
|
if(self::$token != ''){
|
||||||
$headers = array(
|
$headers = array(
|
||||||
'Content-Type:application/json',
|
'Content-Type:application/json',
|
||||||
'Authorization: ' . self::$token
|
'Authorization: '.self::$token
|
||||||
);
|
);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
}
|
}
|
||||||
@@ -60,22 +59,8 @@ class Collection
|
|||||||
* @param array $queryParams
|
* @param array $queryParams
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function getFirstListItem(string $filter, array $queryParams = [])
|
public function getFirstListItem(string $filter, array $queryParams = []){
|
||||||
{
|
|
||||||
$ch = curl_init();
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/" . $this->collection . "/records?perPage=&page=1");
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
if (self::$token != '') {
|
|
||||||
$headers = array(
|
|
||||||
'Content-Type:application/json',
|
|
||||||
'Authorization: ' . self::$token
|
|
||||||
);
|
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
||||||
}
|
|
||||||
$output = curl_exec($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
return json_decode($output, JSON_FORCE_OBJECT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,23 +68,23 @@ class Collection
|
|||||||
* @param array $queryParams
|
* @param array $queryParams
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function create(array $bodyParams = [], array $queryParams = [])
|
public function create(array $bodyParams = [], array $queryParams = []){
|
||||||
{
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
if (self::$token != '') {
|
if(self::$token != ''){
|
||||||
$headers = array(
|
$headers = array(
|
||||||
'Content-Type:application/json',
|
'Content-Type:application/json',
|
||||||
'Authorization: ' . self::$token
|
'Authorization: '.self::$token
|
||||||
);
|
);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/" . $this->collection . "/records");
|
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/".$this->collection."/records");
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($bodyParams));
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($bodyParams));
|
||||||
$output = curl_exec($ch);
|
$output = curl_exec($ch);
|
||||||
|
var_dump($output);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,23 +94,23 @@ class Collection
|
|||||||
* @param array $queryParams
|
* @param array $queryParams
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function update(string $recordId, array $bodyParams = [], array $queryParams = [])
|
public function update(string $recordId, array $bodyParams = [], array $queryParams = []){
|
||||||
{
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
if (self::$token != '') {
|
if(self::$token != ''){
|
||||||
$headers = array(
|
$headers = array(
|
||||||
'Content-Type:application/json',
|
'Content-Type:application/json',
|
||||||
'Authorization: ' . self::$token
|
'Authorization: '.self::$token
|
||||||
);
|
);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/" . $this->collection . "/records/" . $recordId);
|
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/".$this->collection."/records/".$recordId);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($bodyParams));
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($bodyParams));
|
||||||
$output = curl_exec($ch);
|
$output = curl_exec($ch);
|
||||||
|
var_dump($output);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,19 +119,18 @@ class Collection
|
|||||||
* @param array $queryParams
|
* @param array $queryParams
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function delete(string $recordId, array $queryParams = []):void
|
public function delete(string $recordId, array $queryParams = []){
|
||||||
{
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
if (self::$token != '') {
|
if(self::$token != ''){
|
||||||
$headers = array(
|
$headers = array(
|
||||||
'Content-Type:application/json',
|
'Content-Type:application/json',
|
||||||
'Authorization: ' . self::$token
|
'Authorization: '.self::$token
|
||||||
);
|
);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/" . $this->collection . "/records/" . $recordId);
|
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/".$this->collection."/records/".$recordId);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
||||||
$output = curl_exec($ch);
|
$output = curl_exec($ch);
|
||||||
@@ -156,11 +140,26 @@ class Collection
|
|||||||
/**
|
/**
|
||||||
* @param string $recordId
|
* @param string $recordId
|
||||||
* @param array $queryParams
|
* @param array $queryParams
|
||||||
* @return void
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getOne(string $recordId, array $queryParams = [])
|
public function getOne(string $recordId, array $queryParams = []){
|
||||||
{
|
$ch = curl_init();
|
||||||
// Todo: implibment logic
|
|
||||||
|
if(self::$token != ''){
|
||||||
|
$headers = array(
|
||||||
|
'Content-Type:application/json',
|
||||||
|
'Authorization: '.self::$token
|
||||||
|
);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/".$this->collection."/records/".$recordId);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||||
|
$output = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
return json_decode($output, JSON_FORCE_OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user