Examples for presentation.

This commit is contained in:
giedrius
2024-11-19 13:57:03 +02:00
commit 41f2b5eec1
23 changed files with 3351 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
<?php
namespace Example\VeryGood;
use GuzzleHttp\Client;
class ApiClient
{
private Client $client;
public function __construct(Client $client)
{
$this->client = $client;
}
/**
* @return Product[]
*/
public function getProducts(string $filter): array {
$response = $this->client->request('GET', 'api_endpoint/products', [
'query' => ['filter'=>$filter]
]);
$json = $response->getBody()->getContents();
$data = json_decode($json, true);
return array_map( fn($element)=> (new Product())->setData($element), $data);
}
}