Search by

uxf / energo-kalkulator-sdk

uxf

Package info

gitlab.com/uxf/energo-kalkulator-sdk

Issues

pkg:composer/uxf/energo-kalkulator-sdk

Statistics

Installs: 3 023

Dependents: 0

Suggesters: 0

Stars: 0

1.42.0 2026-11-11 13:53 UTC

README

Install

$ composer req uxf/energo-kalkulator-sdk
// bundles.php
return [
    UXFCoreBundle::class => ['all' => true];
    UXFHydratorBundle::class => ['all' => true];
    EnergokalkulatorBundle::class => ['all' => true];
];

Config

// packages/energo_kalkulator.php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->extension('energo_kalkulator', [
        'base_url' => 'https://xxx.com', // optional
        'api_key' => env('API_KEY'),
    ]);
};

Usage

use EnergoKalkulator\EnergoKalkulatorService;

class MagicService
{
    public function __construct(private readonly EnergoKalkulatorService $service)
    {
    } 

    public function run()
    {
        $data = $service->getGasEstimateWithPrepaid(
            currentPartner: 1,
            currentProduct: 1,
            distributor: 85,
            prepaid: 3333,
        );
    }
}

Errors

EnergokalkulatorException for every response other than 200. A 404 throws its subclass EnergokalkulatorNotFoundException (the record does not exist), so an existing catch (EnergokalkulatorException) keeps working.

GraphQL (uxf/graphql)

src/GraphQL has queries over the public catalog of Energokalkulátor: codebooks, partners, products, previews of the active products and FAQ. All query names start with energoKalkulator, all types with EnergoKalkulator (CooperationMethodEnum keeps its name). The types are the response objects of the SDK; only the fields without #[Ignore] go to the schema, the rest are internal data of Energokalkulátor. A new public property of a response object needs #[Ignore] unless it is meant to be public.

Nothing changes until the application turns it on:

// packages/uxf.php
$containerConfigurator->extension('uxf_graphql', [
    'sources' => [
        __DIR__ . '/../../src',
        __DIR__ . '/../../vendor/uxf/energo-kalkulator-sdk/src/GraphQL',
    ],
    'modifiers' => [
        EnergoKalkulator\GraphQL\EnergoKalkulatorSchemaModifier::class, // FileResponse as EnergoKalkulatorFile
    ],
]);

// packages/energo_kalkulator.php
$containerConfigurator->extension('energo_kalkulator', [
    'api_key' => env('API_KEY'),
    'graphql' => [                    // optional
        'http_client' => 'app.http_client.energo_kalkulator_graphql', // PSR-18 client of the queries only, e.g. a 5 s limit
        'cache_pool' => 'cache.user', // results are cached for 180 s, shared between requests
    ],
]);
  • Without the graphql config the queries use the default EnergoKalkulatorService and nothing is cached. With any of its keys they get an instance of their own, reset after every request (its memory cache must not outlive a request in a worker), on graphql.http_client or on the default PSR-18 client. Without graphql.cache_pool nothing is cached. The default service used by the rest of the application never changes.
  • Cache keys contain the installed SDK version, objects cached by another version are never read after a deploy.
  • Validity of a cached result follows UXF\Core\SystemProvider\Clock; 404 and errors are not cached.
  • A 404 of Energokalkulátor is the GraphQL error NOT_FOUND, any other failure (status, timeout, network) ENERGO_KALKULATOR_UNAVAILABLE. A query never returns an empty list instead of an error.
  • EnergoKalkulatorSchemaModifier implements getPriority() and getDefaultPriority() (uxf/graphql < 3.80).