Search by

besmartand-pro / bsap-sensor-bundle

roszkiewiczjakub

Symfony integration for the BeSmartAnd.Pro Sensor PHP client.

Package info

github.com/BeSmartAnd-Pro/bsap-sensor-bundle

Type:symfony-bundle

pkg:composer/besmartand-pro/bsap-sensor-bundle

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-10-12 22:02 UTC

This package is auto-updated.

Last update: 2026-10-12 22:03:54 UTC


README

Integracja besmartand-pro/bsap-sensor-client z Symfony 7.4 i 8.x, dla PHP 8.4+. Bundle dodaje konfigurację, transport Symfony HttpClient i autowiring. Obsługa API i modele danych znajdują się w osobnej bibliotece klienta.

Instalacja

composer require besmartand-pro/bsap-sensor-bundle

Zarejestruj bundle w config/bundles.php:

return [
    BeSmartAndPro\BsapSensorBundle\BsapSensorBundle::class => ['all' => true],
];

Dodaj config/packages/bsap_sensor.yaml:

bsap_sensor:
    api_token: '%env(SENSOR_API_TOKEN)%'
    base_uri: 'https://sensor.besmartand.pro'
    timeout: 10.0
    http_client: 'http_client'

Tylko api_token jest wymagany. Pozostałe wartości powyżej są domyślne. Token umieść w zmiennej środowiskowej lub Symfony Secrets; nie zapisuj go w repozytorium.

http_client pozwala wskazać istniejący scoped HTTP client aplikacji. Bundle tworzy własną pochodną tego serwisu, ustawia timeout i maksymalny czas żądania, a także wyłącza przekierowania. Aplikacja powinna mieć włączony HttpClient FrameworkBundle, np. framework: { http_client: ~ }.

Użycie przez autowiring

use BeSmartAndPro\BsapSensorClient\SensorClientInterface;

final readonly class SensorHistoryService
{
    public function __construct(private SensorClientInterface $sensorClient)
    {
    }

    public function read(string $sensorId): array
    {
        return $this->sensorClient->getSensorHistory($sensorId);
    }
}

Można również wstrzyknąć konkretną klasę SensorClient. Interfejs i klasa wskazują ten sam serwis. Opis modeli, wyjątków i ograniczeń endpointu znajduje się w README biblioteki bsap-sensor-client.

Licencja MIT.