mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
add User Collection, adapt crud, refactor crud, add readme
This commit is contained in:
26
README.md
Normal file
26
README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
### Php Sdk for Pocketbase
|
||||
|
||||
#### Crud adapted from js-sdk to php
|
||||
|
||||
```
|
||||
// Returns a paginated records list.
|
||||
🔓 pb.collection(collectionIdOrName).getList(int $page = 1, int $perPage = 30, array $queryParams = []);
|
||||
|
||||
// Returns a list with all records batch fetched at once.
|
||||
🔓 pb.collection(collectionIdOrName).getFullList(int $batch = 200, array $queryParams = []);
|
||||
|
||||
// Returns the first found record matching the specified filter.
|
||||
🔓 pb.collection(collectionIdOrName).getFirstListItem(string $filter, array $queryParams = []);
|
||||
|
||||
// Returns a single record by its id.
|
||||
🔓 pb.collection(collectionIdOrName).getOne(string $recordId, array $queryParams = []);
|
||||
|
||||
// Creates (aka. register) a new record.
|
||||
🔓 pb.collection(collectionIdOrName).create(array $bodyParams = [], array $queryParams = []);
|
||||
|
||||
// Updates an existing record by its id.
|
||||
🔓 pb.collection(collectionIdOrName).update(string $recordId, array $bodyParams = [],array $queryParams = []);
|
||||
|
||||
// Deletes a single record by its id.
|
||||
🔓 pb.collection(collectionIdOrName).delete(string $recordId, array $queryParams = []);
|
||||
```
|
||||
@@ -10,7 +10,8 @@
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/Client.php",
|
||||
"src/Collection.php"
|
||||
"src/Collection.php",
|
||||
"src/UsersCollection.php"
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
|
||||
@@ -2,26 +2,29 @@
|
||||
|
||||
namespace Pb;
|
||||
|
||||
use UsersCollection;
|
||||
|
||||
class Client
|
||||
{
|
||||
private string $response;
|
||||
private string $url;
|
||||
private string $route;
|
||||
|
||||
public function __construct(string $url)
|
||||
{
|
||||
$this->response = '{}';
|
||||
$this->url = $url;
|
||||
$this->users = [];
|
||||
|
||||
}
|
||||
|
||||
public function collection(string $collection, int $page = 1)
|
||||
public function users()
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $this->url."/api/collections/".$collection."/records?page=".$page);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$collection = new Collection(curl_exec($ch));
|
||||
curl_close($ch);
|
||||
return new UsersCollection($this->url, 'records');
|
||||
}
|
||||
|
||||
return json_decode($collection, JSON_FORCE_OBJECT);
|
||||
public function collection($url,string $collection, int $page = 1)
|
||||
{
|
||||
return new Collection($this->url ,$collection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,47 @@ namespace Pb;
|
||||
|
||||
class Collection
|
||||
{
|
||||
private $json;
|
||||
private string $collection;
|
||||
private string $url;
|
||||
|
||||
public function __construct($data)
|
||||
|
||||
public function __construct(string $url, string $collection)
|
||||
{
|
||||
$this->json = $data;
|
||||
$this->url = $url;
|
||||
$this->collection = $collection;
|
||||
}
|
||||
|
||||
public function authWithPassword(){
|
||||
var_dump($this->json);
|
||||
public function getFullList(int $batch = 200, array $queryParams = []){
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/".$this->collection."/records");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = new Collection(curl_exec($ch));
|
||||
curl_close($ch);
|
||||
|
||||
return json_decode($output, JSON_FORCE_OBJECT);
|
||||
}
|
||||
|
||||
public function getFirstListItem(string $filter, array $queryParams = []){
|
||||
|
||||
}
|
||||
|
||||
public function create(array $bodyParams = [], array $queryParams = []){
|
||||
|
||||
}
|
||||
public function update(string $recordId, array $bodyParams = [],array $queryParams = []){
|
||||
|
||||
}
|
||||
public function delete(string $recordId, array $queryParams = []){
|
||||
|
||||
}
|
||||
|
||||
public function getOne(string $recordId, array $queryParams = []){
|
||||
|
||||
}
|
||||
|
||||
public function authWithPassword()
|
||||
{
|
||||
$data = json_decode($this->json, JSON_FORCE_OBJECT);
|
||||
var_dump($data);
|
||||
}
|
||||
}
|
||||
|
||||
29
src/UsersCollection.php
Normal file
29
src/UsersCollection.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
class UsersCollection
|
||||
{
|
||||
private string $url;
|
||||
private string $collection;
|
||||
|
||||
public function __construct(string $url, string $collection)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->collection = $collection;
|
||||
}
|
||||
|
||||
public function getList($page = 1, $perPage = 30)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/users/records");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return json_decode($output, JSON_FORCE_OBJECT);
|
||||
}
|
||||
|
||||
public function authWithPassword()
|
||||
{
|
||||
var_dump('try auth');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user