nyoncode/laravel-ares 问题修复 & 功能扩展

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

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

nyoncode/laravel-ares

Composer 安装命令:

composer require nyoncode/laravel-ares

包简介

Laravel package for the Czech ARES business register API with caching, events, validation and artisan tooling.

README 文档

README

laravel-ares is a Laravel package for the Czech ARES business register API. It provides a typed client, a facade, configurable caching, lookup events, ICO validation, static analysis support, and an artisan command for diagnostics.

Features

  • Typed public API through AresClientInterface
  • Ares facade with convenience methods for common workflows
  • Structured domain objects instead of one large flat payload object
  • Configurable caching and HTTP timeouts
  • Events for successful and failed lookups
  • ICO normalization and checksum validation
  • Explicit exceptions for invalid ICO and missing companies
  • Subject indexing with database-backed autocomplete search
  • Pest test suite, PHPStan configuration, and GitHub Actions CI

Requirements

  • PHP 8.2+
  • Laravel 11, 12, or 13

Installation

Install the package with Composer:

composer require nyoncode/laravel-ares

Publish the configuration file if you want local overrides:

php artisan vendor:publish --tag=laravel-ares::config

Configuration

Key Default Description
api_url https://ares.gov.cz/ekonomicke-subjekty-v-be/rest Base URL for the ARES REST API
cache.enabled true Enable response caching; set to false to disable caching entirely
cache.ttl 86400 Cache lifetime for successful lookups in seconds
cache.store null Cache store to use (null = default store)
cache.prefix ares:v1:company: Prefix for ARES cache keys
log_channel stack Laravel log channel used for client errors
http_options.timeout 5.0 Request timeout in seconds
http_options.connect_timeout 3.0 Connection timeout in seconds
indexing.enabled true Enable subject indexing and search
indexing.auto_index true Automatically index subjects on successful lookup
indexing.stale_days 30 Number of days before a record is considered stale

Environment overrides:

  • ARES_API_URL
  • ARES_CACHE_ENABLED
  • ARES_CACHE_TTL
  • ARES_CACHE_STORE
  • ARES_CACHE_PREFIX
  • ARES_LOG_CHANNEL
  • ARES_HTTP_TIMEOUT
  • ARES_HTTP_CONNECT_TIMEOUT
  • ARES_INDEXING_ENABLED
  • ARES_AUTO_INDEX
  • ARES_STALE_DAYS

Usage

Use dependency injection when you want explicit contracts:

use NyonCode\Ares\Contracts\AresClientInterface;

final class CompanyLookupService
{
    public function __construct(
        private readonly AresClientInterface $ares,
    ) {}

    public function companyName(string $ic): ?string
    {
        return $this->ares->findCompany($ic)?->name;
    }
}

Use the facade for concise application code:

use NyonCode\Ares\Facades\Ares;

$normalizedIc = Ares::normalizeIc('27 074 358');
$company = Ares::findCompanyOrFail($normalizedIc);

dump($company->name);
dump($company->registeredOffice?->formatted);
dump($company->registration->naceCodes);

Public API:

  • findCompany(string $ic): ?CompanyData
  • findCompanyRaw(string $ic): ?array
  • findCompanyOrFail(string $ic): CompanyData
  • forgetCompany(string $ic): bool
  • isValidIc(string $ic): bool
  • normalizeIc(string $ic): string
  • search(string $query, int $limit = 10): Collection<SubjectData>

Domain Model

Successful lookups return NyonCode\Ares\Data\CompanyData:

final class CompanyData
{
    public readonly string $ic;
    public readonly string $name;
    public readonly ?string $dic;
    public readonly ?string $dicSkDph;
    public readonly ?AddressData $registeredOffice;
    public readonly ?DeliveryAddressData $deliveryAddress;
    public readonly RegistrationData $registration;
    public readonly array $rawData;
}

Related DTOs:

  • AddressData models the registered office
  • DeliveryAddressData models the mailing address
  • RegistrationData groups legal form, dates, source, file mark, NACE codes, and source statuses
  • RegistrationStatusData represents one registry source status
  • RegistrationSourceState is a typed enum for known ARES status values
  • SubjectData is a lightweight DTO for autocomplete search results (ic, name, city)

rawData remains available as an escape hatch for fields the package does not map yet.

Exceptions

The fail-fast API throws explicit domain exceptions:

  • NyonCode\Ares\Exceptions\InvalidIcException
  • NyonCode\Ares\Exceptions\CompanyNotFoundException

Malformed payloads are treated as failed lookups internally and surface through the failure event path.

Events

The package dispatches:

  • NyonCode\Ares\Events\CompanyLookupSucceeded
  • NyonCode\Ares\Events\CompanyLookupFailed

Subject Indexing and Autocomplete

The package can index looked-up subjects into a local database table for fast autocomplete search.

Run the migration after installing:

php artisan migrate

Search indexed subjects by name or IC:

// Search by company name
$results = Ares::search('Asseco');

// Search by IC prefix
$results = Ares::search('2707', 5);

// Using the global helper
$results = ares_search('Skoda');

Each result is a SubjectData with ic, name, and city properties.

Auto-indexing

When indexing.auto_index is enabled (default), every successful findCompany() call dispatches a queued job that indexes the subject automatically. No extra code needed.

Manual Indexing

# Index specific subjects
php artisan ares:index 27074358 25596641

# Refresh stale records (older than configured stale_days)
php artisan ares:index --refresh-stale

# Custom stale threshold and limit
php artisan ares:index --refresh-stale --stale-days=14 --limit=200

Schedule the refresh in your application's scheduler for automatic maintenance:

$schedule->command('ares:index --refresh-stale')->daily();

Artisan Commands

The package includes artisan commands for diagnostics and indexing:

# Test ARES API connectivity
php artisan ares:test 27074358

# Index subjects
php artisan ares:index 27074358

# Show indexing statistics
php artisan ares:index

# Refresh stale records
php artisan ares:index --refresh-stale

ares:test renders a compact company summary including DIC, source, dates, registered office, delivery address, and register metadata.

Quality Gates

Run the automated tests:

composer test

Run static analysis:

composer analyse

Run the formatter:

composer format

The repository includes a GitHub Actions workflow for:

  • PHP/Laravel compatibility matrix tests
  • PHPStan on the quality lane
  • Pint on the quality lane

Development Notes

  • Successful lookups are cached under the ares:v1:company:{ic} key format.
  • Invalid ICO values are rejected before any HTTP request is sent.
  • forgetCompany() invalidates cache entries using normalized ICO values.
  • Failed HTTP responses, malformed payloads, and transport exceptions all dispatch CompanyLookupFailed.
  • Auto-indexed subjects are stored in the ares_subjects table with a minimal footprint (ic, name, city, indexed_at).
  • Search uses LIKE queries with database indexes for fast prefix/substring matching.

License

The package is open-sourced under the MIT license.

nyoncode/laravel-ares 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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