mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
remove users collection and used code
This commit is contained in:
@@ -10,9 +10,7 @@
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/Client.php",
|
||||
"src/Collection.php",
|
||||
"src/UsersCollection.php"
|
||||
]
|
||||
"src/Collection.php"
|
||||
},
|
||||
"require": {
|
||||
"php": "^8.1|^8.2",
|
||||
|
||||
@@ -2,28 +2,16 @@
|
||||
|
||||
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 users()
|
||||
{
|
||||
return new UsersCollection($this->url, 'records');
|
||||
}
|
||||
|
||||
public function collection(string $collection)
|
||||
public function collection(string $collection): Collection
|
||||
{
|
||||
return new Collection($this->url ,$collection);
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ class Collection
|
||||
/**
|
||||
* @param int $batch
|
||||
* @param array $queryParams
|
||||
* @return mixed
|
||||
* @return array
|
||||
*/
|
||||
public function getFullList(int $batch = 200, array $queryParams = [])
|
||||
public function getFullList(int $batch = 200, array $queryParams = []): array
|
||||
{
|
||||
$getParams = !empty($queryParams) ? http_build_query($queryParams) : "";
|
||||
$response = $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records?" . $getParams, 'GET');
|
||||
@@ -50,7 +50,7 @@ class Collection
|
||||
* @param array $queryParams
|
||||
* @return array
|
||||
*/
|
||||
public function getFirstListItem(string $filter, array $queryParams = [])
|
||||
public function getFirstListItem(string $filter, array $queryParams = []): array
|
||||
{
|
||||
$queryParams['perPage'] = 1;
|
||||
$getParams = !empty($queryParams) ? http_build_query($queryParams) : "";
|
||||
@@ -63,7 +63,7 @@ class Collection
|
||||
* @param array $queryParams
|
||||
* @return void
|
||||
*/
|
||||
public function create(array $bodyParams = [], array $queryParams = [])
|
||||
public function create(array $bodyParams = [], array $queryParams = []): void
|
||||
{
|
||||
$this->doRequest($this->url . "/api/collections/" . $this->collection . "/records", 'POST', json_encode($bodyParams));
|
||||
}
|
||||
@@ -74,7 +74,7 @@ class Collection
|
||||
* @param array $queryParams
|
||||
* @return void
|
||||
*/
|
||||
public function update(string $recordId, array $bodyParams = [], array $queryParams = [])
|
||||
public function update(string $recordId, array $bodyParams = [], array $queryParams = []): void
|
||||
{
|
||||
// Todo bodyParams equals json, currently workaround
|
||||
$this->doRequest($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'PATCH', json_encode($bodyParams));
|
||||
@@ -85,7 +85,7 @@ class Collection
|
||||
* @param array $queryParams
|
||||
* @return void
|
||||
*/
|
||||
public function delete(string $recordId, array $queryParams = [])
|
||||
public function delete(string $recordId, array $queryParams = []): void
|
||||
{
|
||||
$this->doRequest($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'DELETE');
|
||||
}
|
||||
@@ -96,7 +96,7 @@ class Collection
|
||||
* @param string $method
|
||||
* @return bool|string
|
||||
*/
|
||||
public function doRequest(string $url, string $method, $bodyParams = [])
|
||||
public function doRequest(string $url, string $method, $bodyParams = []): string
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
@@ -126,7 +126,7 @@ class Collection
|
||||
* @param array $queryParams
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOne(string $recordId, array $queryParams = [])
|
||||
public function getOne(string $recordId, array $queryParams = []): array
|
||||
{
|
||||
$output = $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'GET');
|
||||
return json_decode($output, JSON_FORCE_OBJECT);
|
||||
@@ -137,7 +137,7 @@ class Collection
|
||||
* @param string $password
|
||||
* @return void
|
||||
*/
|
||||
public function authAsAdmin(string $email, string $password)
|
||||
public function authAsAdmin(string $email, string $password): void
|
||||
{
|
||||
$bodyParams['identity'] = $email;
|
||||
$bodyParams['password'] = $password;
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?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