add User Collection, adapt crud, refactor crud, add readme

This commit is contained in:
Martz
2023-02-05 20:06:44 +01:00
parent 1d1beef82a
commit c586b4b9ff
5 changed files with 105 additions and 13 deletions

View File

@@ -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);
}
}

View File

@@ -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
View 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');
}
}