mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
update phpDocs
This commit is contained in:
@@ -2,27 +2,50 @@
|
|||||||
|
|
||||||
namespace Pb;
|
namespace Pb;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Collection
|
class Collection
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
private string $collection;
|
private string $collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
private string $url;
|
private string $url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
private static string $token = '';
|
private static string $token = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $url
|
||||||
|
* @param string $collection
|
||||||
|
*/
|
||||||
public function __construct(string $url, string $collection)
|
public function __construct(string $url, string $collection)
|
||||||
{
|
{
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->collection = $collection;
|
$this->collection = $collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFullList(int $batch = 200, array $queryParams = []){
|
/**
|
||||||
|
* @param int $batch
|
||||||
|
* @param array $queryParams
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
@@ -32,71 +55,119 @@ class Collection
|
|||||||
return json_decode($output, JSON_FORCE_OBJECT);
|
return json_decode($output, JSON_FORCE_OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFirstListItem(string $filter, array $queryParams = []){
|
/**
|
||||||
|
* @param string $filter
|
||||||
}
|
* @param array $queryParams
|
||||||
|
* @return void
|
||||||
public function create(array $bodyParams = [],array $queryParams = []){
|
*/
|
||||||
|
public function getFirstListItem(string $filter, array $queryParams = [])
|
||||||
|
{
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/" . $this->collection . "/records?perPage=&page=1");
|
||||||
if(self::$token != ''){
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
$output = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
return json_decode($output, JSON_FORCE_OBJECT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $bodyParams
|
||||||
|
* @param array $queryParams
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function create(array $bodyParams = [], array $queryParams = [])
|
||||||
|
{
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
if (self::$token != '') {
|
||||||
|
$headers = array(
|
||||||
|
'Content-Type:application/json',
|
||||||
|
'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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(string $recordId, array $bodyParams = [],array $queryParams = []){
|
/**
|
||||||
|
* @param string $recordId
|
||||||
|
* @param array $bodyParams
|
||||||
|
* @param array $queryParams
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
public function delete(string $recordId, array $queryParams = []){
|
|
||||||
|
/**
|
||||||
|
* @param string $recordId
|
||||||
|
* @param array $queryParams
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function delete(string $recordId, array $queryParams = []):void
|
||||||
|
{
|
||||||
$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);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOne(string $recordId, array $queryParams = []){
|
/**
|
||||||
|
* @param string $recordId
|
||||||
|
* @param array $queryParams
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function getOne(string $recordId, array $queryParams = [])
|
||||||
|
{
|
||||||
|
// Todo: implibment logic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $email
|
||||||
|
* @param string $password
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function authAsAdmin(string $email, string $password)
|
public function authAsAdmin(string $email, string $password)
|
||||||
{
|
{
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|||||||
Reference in New Issue
Block a user