From 98ae821c596281de85fa3b37382568c12704f4a7 Mon Sep 17 00:00:00 2001 From: Martz Date: Sat, 18 Feb 2023 19:21:13 +0100 Subject: [PATCH] update phpDocs --- src/Collection.php | 123 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 97 insertions(+), 26 deletions(-) diff --git a/src/Collection.php b/src/Collection.php index 33313cb..a739f77 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -2,27 +2,50 @@ namespace Pb; +/** + * + */ class Collection { + /** + * @var string + */ private string $collection; + + /** + * @var string + */ private string $url; + + /** + * @var string + */ private static string $token = ''; - + /** + * @param string $url + * @param string $collection + */ public function __construct(string $url, string $collection) { $this->url = $url; $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(); - 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); - if(self::$token != ''){ + if (self::$token != '') { $headers = array( 'Content-Type:application/json', - 'Authorization: '.self::$token + 'Authorization: ' . self::$token ); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } @@ -32,71 +55,119 @@ class Collection return json_decode($output, JSON_FORCE_OBJECT); } - public function getFirstListItem(string $filter, array $queryParams = []){ - - } - - public function create(array $bodyParams = [],array $queryParams = []){ + /** + * @param string $filter + * @param array $queryParams + * @return void + */ + public function getFirstListItem(string $filter, array $queryParams = []) + { $ch = curl_init(); - - if(self::$token != ''){ + curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/" . $this->collection . "/records?perPage=&page=1"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + if (self::$token != '') { $headers = array( '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_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_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($bodyParams)); $output = curl_exec($ch); - var_dump($output); 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(); - if(self::$token != ''){ + if (self::$token != '') { $headers = array( 'Content-Type:application/json', - 'Authorization: '.self::$token + 'Authorization: ' . self::$token ); 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_CUSTOMREQUEST, 'PATCH'); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($bodyParams)); $output = curl_exec($ch); - var_dump($output); 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(); - if(self::$token != ''){ + if (self::$token != '') { $headers = array( 'Content-Type:application/json', - 'Authorization: '.self::$token + 'Authorization: ' . self::$token ); 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_CUSTOMREQUEST, 'DELETE'); $output = curl_exec($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) { $ch = curl_init();