diff --git a/composer.json b/composer.json index 0a172f8..f6d4a5f 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,7 @@ "autoload": { "classmap": [ "src/Client.php", - "src/Collection.php", - "src/UsersCollection.php" - ] + "src/Collection.php" }, "require": { "php": "^8.1|^8.2", diff --git a/src/Client.php b/src/Client.php index e601786..e8472ec 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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); } diff --git a/src/Collection.php b/src/Collection.php index 124c81a..d9d1894 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -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; diff --git a/src/UsersCollection.php b/src/UsersCollection.php deleted file mode 100644 index ff40b72..0000000 --- a/src/UsersCollection.php +++ /dev/null @@ -1,29 +0,0 @@ -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'); - } -}