hrabo/ares-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hrabo/ares-bundle

Composer 安装命令:

composer require hrabo/ares-bundle

包简介

Symfony bundle for ARES (Administrativní registr ekonomických subjektů) REST API integration.

README 文档

README

Symfony bundle integrating the official ARES (Administrativní registr ekonomických subjektů) REST API.

The bundle focuses on:

  • Company detail by IČO from ARES “core” and/or individual datasets (RES, VR, RŽP, ROS, RCNS, RPSH, CEÚ, RŠ, SZR, NRPZS).
  • Configurable retries (HTTP client retry strategy + Retry-After support).
  • Configurable rate limiting (token bucket limiter) to avoid API blocking.
  • Standardized output (DTOs + toArray()).

API documentation:

Installation

composer require hrabo/ares-bundle

Enable the bundle (if not using Flex auto-discovery):

// config/bundles.php
return [
    // ...
    Hrabo\AresBundle\HraboAresBundle::class => ['all' => true],
];

Configuration

Create config/packages/hrabo_ares.yaml:

hrabo_ares:
  base_uri: 'https://ares.gov.cz/ekonomicke-subjekty-v-be/rest/'
  timeout_seconds: 10

  retry:
    max_retries: 3
    delay_ms: 250
    multiplier: 2.0
    max_delay_ms: 5000
    jitter: 0.1
    status_codes: [0, 429, 500, 502, 503, 504]

  rate_limit:
    enabled: true
    # Token bucket limiter:
    limit: 10
    interval: '1 second'
    burst: 20
    wait: true
    key: 'ares-outgoing' # all workers share this key via cache.app

  datasets:
    # Default datasets used by findCompanyByIco() when not provided explicitly:
    - ares
    - res
    - vr
    - rzp
    - ros
    - rcns
    - rpsh
    - ceu
    - rs
    - szr
    - nrpzs

Notes:

  • rate_limit.key is stored via cache.app and shared across workers/servers if cache.app uses a shared backend (Redis, Memcached, ...).
  • For maximum safety against ARES blocking, prefer a shared cache backend for cache.app (Redis).

Usage

1) Aggregate lookup by IČO across datasets

use Hrabo\AresBundle\Client\AresClientInterface;

final class SomeService
{
    public function __construct(private AresClientInterface $ares) {}

    public function run(): void
    {
        $result = $this->ares->findCompanyByIco('00006947'); // or '6947'
        $best = $result->company; // NormalizedCompany|null

        // Array for storage/export:
        $payload = $result->toArray();
    }
}

2) Single dataset detail (GET {ico})

use Hrabo\AresBundle\Enum\Dataset;

$datasetResult = $ares->getEconomicSubject('6947', Dataset::RES);

if ($datasetResult->isOk()) {
    $company = $datasetResult->company; // NormalizedCompany
    $raw = $datasetResult->raw;         // array
}

3) Search (POST vyhledat)

use Hrabo\AresBundle\Enum\Dataset;

$search = $ares->searchEconomicSubjects(Dataset::ARES, [
    'start' => 0,
    'pocet' => 10,
    'obchodniJmeno' => 'Ministerstvo financí',
]);

// $search is raw ARES response array.

4) Codebooks (POST vyhledat)

$codebooks = $ares->searchCodebooks([
    'start' => 0,
    'pocet' => 50,
    'kodCiselniku' => 'PravniForma',
]);

5) Standardized addresses (POST vyhledat)

$addresses = $ares->searchStandardizedAddresses([
    'start' => 0,
    'pocet' => 10,
    'textovaAdresa' => 'Letenská 525/15, Praha 1',
]);

Error handling contract

  • Input validation:
    • Invalid IČO causes an InvalidArgumentException from IcoNormalizer::normalize().
  • GET (company detail):
    • getEconomicSubject() and findCompanyByIco() do not throw on HTTP/API failures.
    • They always return DatasetResult entries with status:
      • ok (HTTP 200)
      • not_found (HTTP 404)
      • error (transport issues, invalid responses, non-200/404)
  • POST endpoints (search/codebooks/addresses):
    • searchEconomicSubjects(), searchCodebooks(), searchStandardizedAddresses() throw AresApiException on non-200 responses or invalid responses.
  • Rate limiting:
    • If rate limiting is enabled and wait=false, the client may throw AresRateLimitExceededException.

Standardized output

  • CompanyLookupResult contains:
    • icoCanonical (8 digits, left padded with zeros)
    • company (first successful NormalizedCompany in chosen dataset order)
    • datasets map: dataset code → DatasetResult

Development

Quality checks (PHPCS + PHPStan)

This project uses:

  • PHPCS (Symfony coding standard) for code style
  • PHPStan for static analysis
# run everything (style + static analysis)
composer check

# style only
composer phpcs

# auto-fix style (what can be fixed automatically)
composer phpcbf

# static analysis only
composer phpstan

Config files:

  • PHPCS ruleset: phpcs.xml
  • PHPStan config: phpstan.neon

Tests

composer install
vendor/bin/phpunit

Code style (phpcs/phpcbf)

# show violations
vendor/bin/phpcs

# auto-fix what can be fixed
vendor/bin/phpcbf

The ruleset is in phpcs.xml and uses the Symfony PHP_CodeSniffer standard.

Versioning

This is an initial bundle skeleton intended to be extended inside your application. PRs welcome.

hrabo/ares-bundle 适用场景与选型建议

hrabo/ares-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 hrabo/ares-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hrabo/ares-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 hrabo/ares-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-04