PHP code example of vasildakov / speedy
1. Go to this page and download the library: Download vasildakov/speedy library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vasildakov / speedy example snippets
// configuration
$configuration = new Configuration(
username: $_ENV['SPEEDY_USERNAME'],
password: $_ENV['SPEEDY_PASSWORD'],
language: $_ENV['SPEEDY_LANGUAGE']
);
use GuzzleHttp\Client;
use Laminas\Diactoros\RequestFactory;
$client = new Client(); // PSR-18 HTTP Client
$factory = new RequestFactory(); // PSR-17 HTTP Factory
$speedy = new Speedy($configuration, $client, $factory);
use Nyholm\Psr7\Factory\Psr17Factory;
use Symfony\Component\HttpClient\Psr18Client;
$client = new Psr18Client(); // PSR-18 HTTP Client
$factory = new Psr17Factory(); // PSR-17 HTTP Factory
$speedy = new Speedy($configuration, $client, $factory);
// use an array
$request = new GetContractClientsRequest(clientSystemId: "1234567");
$json = $speedy->getContractClient($request);
$array = json_decode($json, true);
$json = $speedy->getContractClient($request); # json
$serializer = (new SerializerFactory())(); # JMS\Serializer\SerializerInterface
$response = $serializer->deserialize(
data: $json,
type: GetContractClientsResponse::class,
format: 'json'
); # GetContractClientsResponse
$decorator = new SpeedyModelDecorator(
new Speedy($configuration, $client, $factory)
);
/** @var GetContractClientsResponse $response */
$response = $decorator->getContractClient(new GetContractClientsRequest());
// @var ArrayCollection $collection
$collection = $response->getClients();
foreach ($collection as $client) {
dump($client); # Model\Client
dump($client->getClientName());
dump($client->getAddress()); # Model\Address
dump($client->getAddress()->getSiteName()); # string
dump($client->getAddress()->getPostcode()); # string
}