stitch-digital/nametodomain-php-sdk
最新稳定版本:1.0.2
Composer 安装命令:
composer require stitch-digital/nametodomain-php-sdk
包简介
An SDK to easily work with the Name To Domain API
关键字:
README 文档
README
This package is the official PHP SDK for the Name To Domain API, built with Saloon v3.
use NameToDomain\PhpSdk\NameToDomain; // Single resolution (sync) $result = NameToDomain::make($token)->resolve( company: 'Stitch Digital', country: 'GB' ); // Batch enrichment (async) $job = NameToDomain::make($token)->enrichBatch( items: [ ['company' => 'Stripe', 'country' => 'US'], ['company' => 'Spotify', 'country' => 'SE'], ] );
Behind the scenes, the SDK uses Saloon to make the HTTP requests.
Installation
composer require stitch-digital/nametodomain-php-sdk
To get started, we highly recommend reading the Name To Domain API documentation.
Quick Start
use NameToDomain\PhpSdk\NameToDomain; // Single resolution (sync) $result = NameToDomain::make($token)->resolve( company: 'Stitch Digital', country: 'GB' ); // Batch enrichment (async) $job = NameToDomain::make($token)->enrichBatch( items: [ ['company' => 'Stripe', 'country' => 'US'], ['company' => 'Spotify', 'country' => 'SE'], ] ); // Check batch job status and get results $batchResult = NameToDomain::make($token)->enrichBatchJob(jobId: $job->id); // Or iterate over all batch items (paginated) $items = NameToDomain::make($token)->enrichBatchJobItems(jobId: $job->id)->collect()->all();
Usage
To authenticate, you'll need an API token. You can create one in the API Dashboard at Name To Domain.
use NameToDomain\PhpSdk\NameToDomain; $client = NameToDomain::make('your-api-token');
Setting a timeout
By default, the SDK waits 10 seconds for a response. Override via the constructor (apiToken, baseUrl, requestTimeout):
$client = new \NameToDomain\PhpSdk\NameToDomain( 'your-api-token', 'https://nametodomain.dev/api/v1', 30 );
Handling errors
The SDK will throw an exception if the API returns an error. For validation errors, the SDK will throw a ValidationException.
try { $client->resolve(company: '', country: 'US'); } catch (\NameToDomain\PhpSdk\Exceptions\ValidationException $exception) { $exception->getMessage(); // returns a string describing the errors $exception->getErrors(); // returns an array with all validation errors $exception->getErrorsForField('company'); // get errors for a specific field }
For all other errors, the SDK will throw a \NameToDomain\PhpSdk\Exceptions\NameToDomainException.
try { $client->enrichJob(jobId: 'invalid-id'); } catch (\NameToDomain\PhpSdk\Exceptions\NameToDomainException $exception) { $exception->getMessage(); $exception->response; // access the Saloon Response object for debugging }
Resolve
The resolve endpoint allows you to resolve a single company name to its official website domain with a confidence score.
Resolve a company
You can use the resolve method to resolve a company name and country code to its domain.
$result = NameToDomain::make($token)->resolve( company: 'Stitch Digital', country: 'GB' );
The response includes the original input and the resolution result. If no reliable match is found, the domain and confidence will be null.
Resolve with emails
You can optionally pass email addresses for disambiguation:
$result = NameToDomain::make($token)->resolve( company: 'Stripe', country: 'US', emails: ['support@stripe.com', 'sales@stripe.com'] );
Domain enrichment
Domain enrichment runs asynchronously and returns richer data (favicon, trust signals, web metadata, company classification, email provider hints, etc.). There are single-company and batch flows.
Enrich a single company
Create an enrichment job for one company. Poll enrichJob(jobId) for the result.
$job = NameToDomain::make($token)->enrich( company: 'Stripe', country: 'US', emails: ['support@stripe.com'], identifier: 'stripe-001' ); // Poll for result $result = NameToDomain::make($token)->enrichJob($job->id); // When completed, $result->output is a JobItem with the enriched data
Enrich a single company with idempotency key
You can include an idempotency key to safely retry requests:
$job = NameToDomain::make($token)->enrich( company: 'Stripe', country: 'US', idempotencyKey: 'my-unique-idempotency-key' );
Enrich multiple companies (batch)
Create a batch enrichment job. Each item may include company, country, and optionally emails and identifier.
$job = NameToDomain::make($token)->enrichBatch( items: [ ['company' => 'Stripe', 'country' => 'US', 'emails' => ['support@stripe.com'], 'identifier' => 'stripe-001'], ['company' => 'Spotify', 'country' => 'SE', 'identifier' => 'spotify-001'], ] );
Enrich batch with idempotency key
$job = NameToDomain::make($token)->enrichBatch( items: [['company' => 'Stripe', 'country' => 'US']], idempotencyKey: 'my-unique-idempotency-key' );
Get a single enrich job
Use enrichJob to get a single-company enrichment job. The output field is only present when the job is completed.
$result = NameToDomain::make($token)->enrichJob('01HQJXK8N3YWVF6BCMPG42X1TZ'); // $result->job and $result->output (JobItem or null)
Get a batch enrich job
Use enrichBatchJob to get a batch job with one page of output and pagination (when completed):
$result = NameToDomain::make($token)->enrichBatchJob('01HQJXK8N3YWVF6BCMPG42X1TZ', page: 1, perPage: 50); // $result->job, $result->output (JobItem[]), $result->pagination
Get batch enrich job items (paginated)
The enrichBatchJobItems method returns a Saloon Paginator over all JobItem DTOs across pages.
Iterating over items
$paginator = NameToDomain::make($token)->enrichBatchJobItems(jobId: $jobId); foreach ($paginator->items() as $item) { if ($item->result && $item->result['domain']) { echo "{$item->input['company']}: {$item->result['domain']}\n"; } }
Using Laravel Collections
$items = NameToDomain::make($token) ->enrichBatchJobItems(jobId: $jobId) ->collect() ->all();
Custom pagination
$paginator = NameToDomain::make($token)->enrichBatchJobItems( jobId: $jobId, page: 2, perPage: 100 );
Job item structure
Each JobItem includes:
id,identifier(client-supplied, if provided)input(company, country, email_domains)status,result,errorMessage,processedAt
The result array can contain company_normalized, domain, confidence, and for enrichment: favicon_url, trust, web_metadata, company_classification, email_provider_hints.
Pagination
The SDK uses Saloon's pagination plugin. The enrichBatchJobItems() method returns a Paginator that yields JobItem DTOs across pages. See Saloon pagination documentation for items(), collect(), and advanced usage.
Using Saloon requests directly
You can use the request classes directly for full control:
use NameToDomain\PhpSdk\NameToDomain; use NameToDomain\PhpSdk\Requests\Resolve\ResolveRequest; $client = NameToDomain::make('your-api-token'); $request = new ResolveRequest('Stripe', 'US'); $response = $client->send($request)->dto();
Security
If you discover any security related issues, please email support@nametodomain.dev instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
stitch-digital/nametodomain-php-sdk 适用场景与选型建议
stitch-digital/nametodomain-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sdk」 「domain」 「nametodomain」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 stitch-digital/nametodomain-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stitch-digital/nametodomain-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 stitch-digital/nametodomain-php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Build a domain-oriented application on Laravel Framework
A PSR-7 compatible library for making CRUD API endpoints
Command bus implementation: Commands and domain events
A module manager for Zend Framework which can be used to create configs per domain.
DDD auth basic class
raxon/example see https://raxon.org for detailed usage
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-16