Part of the h4kuna PHP libraries, see the overview of all packages.
More information about versions is in changelog.
Use the QR code or the sponsor button, which links to my Revolut.
Thank you :)
Requires PHP 8.0 or newer. The best way to install h4kuna/ares is using Composer:
composer require h4kuna/ares
# optional, default implementation of PSR-7, PSR-17 and PSR-18 used by AresFactory
composer require guzzlehttp/guzzleWithout Guzzle, pass your own PSR-18 client and PSR-17 factories to the AresFactory constructor.
The library downloads information about a subject by its identification number (IČO).
Load data by one identification number. Shorter numbers are padded with leading zeros to 8 digits.
use h4kuna\Ares;
$ares = (new Ares\AresFactory())->create();
try {
$response = $ares->loadBasic('87744473');
/* @var $response Ares\Ares\Core\Data */
var_dump($response);
} catch (Ares\Exception\IdentificationNumberNotFoundException $e) {
// the identification number does not exist, log it or ignore it
} catch (Ares\Exception\AdisResponseException $e) {
// validation by ADIS failed, but ARES returned the data
/* @var $response Ares\Ares\Core\Data */
$response = $e->data;
$response->adis === null; // true
var_dump($e->getMessage());
} catch (Ares\Exception\ServerResponseException $e) {
// no response from server or broken json
}Load data by many identification numbers. The ARES service accepts at most 100 items per request, the library splits the input into chunks and removes duplicates. The result is a Generator that keeps the keys of the input array and contains only the subjects that exist.
use h4kuna\Ares;
/** @var Ares\Ares $ares */
$numbers = ['one' => '25596641', 'two' => '26713250', 'three' => '27082440', 'four' => '11111111'];
try {
foreach ($ares->loadBasicMulti($numbers) as $name => $r) {
var_dump($name, $r->company);
}
} catch (Ares\Exception\ResultException | Ares\Exception\ServerResponseException $e) {
// error response, no response from server or broken json
}Choose an endpoint from the class Sources.
SERVICE_*- other available endpointsCORE- the main endpoint, used by the method$ares->loadBasic()DIAL- code lists (dials), for examplePravniFormaSER_NO_*- not supported
Runnable examples are in bin.
use h4kuna\Ares;
/** @var Ares\Ares $ares */
$result = $ares->getAresClient()->useEndpoint(Ares\Ares\Sources::SERVICE_VR, '27082440');
var_dump($result);You can find the parameters kodCiselniku and zdrojCiselniku in the JSON file AresRestApi-verejne_v*.json, for example ciselnikKod: PravniForma, zdroj: res.
use h4kuna\Ares;
/** @var Ares\Ares $ares */
$result = $ares->getAresClient()->searchEndpoint(Ares\Ares\Sources::DIAL, [
'kodCiselniku' => 'PravniForma',
'zdrojCiselniku' => 'res',
])->ciselniky[0]->polozkyCiselniku;
foreach ($result as $item) {
var_dump($item);
}use h4kuna\Ares;
/** @var Ares\Ares $ares */
try {
// returns a list of data boxes of the subject
foreach ($ares->loadDataBox('87744473') as $dataBox) {
var_dump($dataBox->ISDS);
}
} catch (Ares\Exception\ResultException | Ares\Exception\ServerResponseException $e) {
// catch error
}Supports the basic VAT number check. The VAT number must start with the country code, or pass an instance of Ares\Vies\ViesEntity.
use h4kuna\Ares;
/** @var Ares\Ares $ares */
try {
$response = $ares->checkVatVies('CZ27082440');
var_dump($response->valid); // true / false
} catch (Ares\Exception\ServerResponseException $e) {
// service error, for example MS_UNAVAILABLE
}