Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sirene Api Bundle Laravel Package

aldaflux/sirene-api-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle

    composer require aldaflux/sirene-api-bundle
    

    Enable the bundle in config/bundles.php:

    return [
        // ...
        AldaFlux\SireneApiBundle\AldaFluxSireneApiBundle::class => ['all' => true],
    ];
    
  2. Configure Credentials Add your INPI Sirene API credentials in config/packages/aldaflux_sirene_api.yaml:

    aldaflux_sirene_api:
        credentials:
            sirene_key: '%env(SIRENE_API_KEY)%'
            sirene_secret: '%env(SIRENE_API_SECRET)%'
    

    Store secrets in .env:

    SIRENE_API_KEY=your_api_key_here
    SIRENE_API_SECRET=your_api_secret_here
    
  3. First Use Case: Fetch a SIREN/SIRET Inject the SireneApiClient service and call a method (e.g., getCompanyBySiren):

    use AldaFlux\SireneApiBundle\Service\SireneApiClient;
    
    public function __construct(private SireneApiClient $sireneApi) {}
    
    public function getCompanyData(string $siren): array
    {
        return $this->sireneApi->getCompanyBySiren($siren);
    }
    

Implementation Patterns

Core Workflows

  1. Company Data Retrieval Use the bundle’s client methods for structured responses:

    // Get company by SIREN
    $company = $this->sireneApi->getCompanyBySiren('123456789');
    
    // Get company by SIRET
    $company = $this->sireneApi->getCompanyBySiret('12345678901234');
    
  2. Pagination & Advanced Queries Leverage the searchCompanies method for bulk operations:

    $results = $this->sireneApi->searchCompanies(
        criteria: ['siren' => '123456789'],
        limit: 10,
        offset: 0
    );
    
  3. Integration with Symfony Forms Validate SIREN/SIRET inputs using constraints:

    use AldaFlux\SireneApiBundle\Validator\Constraints\ValidSiren;
    
    #[Assert\All({
        new ValidSiren(),
    })]
    public array $companyIdentifiers;
    
  4. Caching Responses Decorate the client to cache API responses (e.g., using Symfony Cache):

    $cache = $this->container->get('cache.app');
    $decoratedClient = new CachedSireneApiClient(
        $this->sireneApi,
        $cache,
        3600 // TTL in seconds
    );
    

Gotchas and Tips

Pitfalls

  1. Rate Limiting The Sirene API enforces strict rate limits (e.g., 100 requests/hour). Implement exponential backoff in your client:

    try {
        $response = $this->sireneApi->getCompanyBySiren($siren);
    } catch (RateLimitExceededException $e) {
        sleep($e->getRetryAfter());
        retry();
    }
    
  2. Deprecated Endpoints The bundle may not cover all Sirene API endpoints. Check the official API docs and extend the client:

    // Extend the client to add custom endpoints
    class ExtendedSireneApiClient extends SireneApiClient
    {
        public function getCompanyHistory(string $siren): array
        {
            return $this->request('GET', "/companies/{$siren}/history");
        }
    }
    
  3. Error Handling The bundle throws SireneApiException for HTTP errors. Catch and log details:

    try {
        $data = $this->sireneApi->searchCompanies(...);
    } catch (SireneApiException $e) {
        $this->logger->error('Sirene API Error', [
            'status' => $e->getCode(),
            'message' => $e->getMessage(),
            'siren' => $siren,
        ]);
    }
    

Tips

  1. Environment-Specific Config Use Symfony’s parameter bags to switch credentials per environment:

    # config/packages/dev/aldaflux_sirene_api.yaml
    aldaflux_sirene_api:
        credentials:
            sirene_key: '%env(resolve:SIRENE_API_KEY_DEV)%'
    
  2. Testing Mock the client in tests using createMock:

    $mockClient = $this->createMock(SireneApiClient::class);
    $mockClient->method('getCompanyBySiren')
        ->willReturn(['siren' => '123456789', 'name' => 'Test Company']);
    $this->container->set(SireneApiClient::class, $mockClient);
    
  3. Logging API Calls Decorate the client to log requests/responses:

    class LoggingSireneApiClient implements SireneApiClientInterface
    {
        public function __construct(
            private SireneApiClient $decorated,
            private LoggerInterface $logger
        ) {}
    
        public function getCompanyBySiren(string $siren): array
        {
            $this->logger->info('Fetching SIREN data', ['siren' => $siren]);
            $response = $this->decorated->getCompanyBySiren($siren);
            $this->logger->debug('Response', $response);
            return $response;
        }
    }
    
  4. Webhook Integration Use the bundle to validate SIREN/SIRET data in webhook payloads:

    public function handleWebhook(array $payload): void
    {
        $siren = $payload['siren'];
        $this->sireneApi->validateSiren($siren); // Throws if invalid
        // Process payload...
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle