mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
implement doReqeust for dublicated code on request curl
This commit is contained in:
@@ -37,7 +37,8 @@ class Collection
|
||||
* @param array $queryParams
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFullList(int $batch = 200, array $queryParams = []){
|
||||
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);
|
||||
@@ -59,7 +60,8 @@ class Collection
|
||||
* @param array $queryParams
|
||||
* @return void
|
||||
*/
|
||||
public function getFirstListItem(string $filter, array $queryParams = []){
|
||||
public function getFirstListItem(string $filter, array $queryParams = [])
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +70,8 @@ class Collection
|
||||
* @param array $queryParams
|
||||
* @return void
|
||||
*/
|
||||
public function create(array $bodyParams = [], array $queryParams = []){
|
||||
public function create(array $bodyParams = [], array $queryParams = [])
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
if (self::$token != '') {
|
||||
@@ -94,7 +97,8 @@ 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 = [])
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
if (self::$token != '') {
|
||||
@@ -119,7 +123,8 @@ class Collection
|
||||
* @param array $queryParams
|
||||
* @return void
|
||||
*/
|
||||
public function delete(string $recordId, array $queryParams = []){
|
||||
public function delete(string $recordId, array $queryParams = [])
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
if (self::$token != '') {
|
||||
@@ -139,10 +144,12 @@ class Collection
|
||||
|
||||
/**
|
||||
* @param string $recordId
|
||||
* @param array $queryParams
|
||||
* @return mixed
|
||||
* @param string $url
|
||||
* @param string $method
|
||||
* @return bool|string
|
||||
*/
|
||||
public function getOne(string $recordId, array $queryParams = []){
|
||||
public function doRequest(string $recordId, string $url, string $method)
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
if (self::$token != '') {
|
||||
@@ -153,12 +160,23 @@ class Collection
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $this->url . "/api/collections/".$this->collection."/records/".$recordId);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $recordId
|
||||
* @param array $queryParams
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOne(string $recordId, array $queryParams = [])
|
||||
{
|
||||
$output = $this->doRequest($recordId, $this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'GET');
|
||||
return json_decode($output, JSON_FORCE_OBJECT);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user