mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
remove php docs from collection, add methods for token url collection
This commit is contained in:
@@ -22,7 +22,7 @@ class Collection
|
|||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public static string $token = '';
|
private static string $token = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $url
|
* @param string $url
|
||||||
@@ -41,12 +41,6 @@ class Collection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $start
|
|
||||||
* @param int $end
|
|
||||||
* @param array $queryParams
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getList(int $start = 1, int $end = 50, array $queryParams = []): array
|
public function getList(int $start = 1, int $end = 50, array $queryParams = []): array
|
||||||
{
|
{
|
||||||
$queryParams['perPage'] = $end;
|
$queryParams['perPage'] = $end;
|
||||||
@@ -56,12 +50,6 @@ class Collection
|
|||||||
return json_decode($response, JSON_FORCE_OBJECT);
|
return json_decode($response, JSON_FORCE_OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $recordId
|
|
||||||
* @param string $field
|
|
||||||
* @param string $filepath
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function upload(string $recordId, string $field, string $filepath): void
|
public function upload(string $recordId, string $field, string $filepath): void
|
||||||
{
|
{
|
||||||
$ch = curl_init($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId);
|
$ch = curl_init($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId);
|
||||||
@@ -91,11 +79,6 @@ class Collection
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $batch
|
|
||||||
* @param array $queryParams
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getFullList(array $queryParams, int $batch = 200): array
|
public function getFullList(array $queryParams, int $batch = 200): array
|
||||||
{
|
{
|
||||||
$queryParams = [... $queryParams, 'perPage' => $batch];
|
$queryParams = [... $queryParams, 'perPage' => $batch];
|
||||||
@@ -105,11 +88,6 @@ class Collection
|
|||||||
return json_decode($response, JSON_FORCE_OBJECT);
|
return json_decode($response, JSON_FORCE_OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $filter
|
|
||||||
* @param array $queryParams
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getFirstListItem(string $filter, array $queryParams = []): array
|
public function getFirstListItem(string $filter, array $queryParams = []): array
|
||||||
{
|
{
|
||||||
// TODO filter
|
// TODO filter
|
||||||
@@ -126,33 +104,17 @@ class Collection
|
|||||||
return $data['items'][0] ?? [];
|
return $data['items'][0] ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $bodyParams
|
|
||||||
* @param array $queryParams
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function create(array $bodyParams = [], array $queryParams = []): string
|
public function create(array $bodyParams = [], array $queryParams = []): string
|
||||||
{
|
{
|
||||||
return $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records", 'POST', $bodyParams);
|
return $this->doRequest($this->url . "/api/collections/" . $this->collection . "/records", 'POST', $bodyParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $recordId
|
|
||||||
* @param array $bodyParams
|
|
||||||
* @param array $queryParams
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function update(string $recordId, array $bodyParams = [], array $queryParams = []): void
|
public function update(string $recordId, array $bodyParams = [], array $queryParams = []): void
|
||||||
{
|
{
|
||||||
// Todo bodyParams equals json, currently workaround
|
// Todo bodyParams equals json, currently workaround
|
||||||
$this->doRequest($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'PATCH', $bodyParams);
|
$this->doRequest($this->url . "/api/collections/" . $this->collection . "/records/" . $recordId, 'PATCH', $bodyParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $recordId
|
|
||||||
* @param array $queryParams
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function delete(string $recordId, array $queryParams = []): void
|
public function delete(string $recordId, array $queryParams = []): void
|
||||||
{
|
{
|
||||||
// TODO params ?
|
// TODO params ?
|
||||||
@@ -178,11 +140,6 @@ class Collection
|
|||||||
return $response->getBody()->getContents() ?? '';
|
return $response->getBody()->getContents() ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $recordId
|
|
||||||
* @param array $queryParams
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getOne(string $recordId, array $queryParams = []): array
|
public function getOne(string $recordId, array $queryParams = []): array
|
||||||
{
|
{
|
||||||
// TODO params ?
|
// TODO params ?
|
||||||
@@ -203,4 +160,38 @@ class Collection
|
|||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getAuthToken(): string
|
||||||
|
{
|
||||||
|
return self::$token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function setAuthToken(string $token): void
|
||||||
|
{
|
||||||
|
self::$token = $token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrl(): string
|
||||||
|
{
|
||||||
|
return $this->url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUrl(string $url): Collection
|
||||||
|
{
|
||||||
|
$this->url = $url;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCollection(): string
|
||||||
|
{
|
||||||
|
return $this->collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCollection(string $collection): Collection
|
||||||
|
{
|
||||||
|
$this->collection = $collection;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class CollectionCreateTest extends TestCase
|
|||||||
|
|
||||||
public function testCreateCollectionItemAuthed(){
|
public function testCreateCollectionItemAuthed(){
|
||||||
$this->collection->authAsUser('admin@jmartz.de', 'rockt123?!');
|
$this->collection->authAsUser('admin@jmartz.de', 'rockt123?!');
|
||||||
self::assertNotEmpty($this->collection::$token);
|
self::assertNotEmpty($this->collection);
|
||||||
// $response = $this->collection->create(['name' => 'Hallo Welt']);
|
// $response = $this->collection->create(['name' => 'Hallo Welt']);
|
||||||
// var_dump($response);
|
// var_dump($response);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user