定制 estratos/namesilo-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

estratos/namesilo-api

Composer 安装命令:

composer require estratos/namesilo-api

包简介

NameSilo API Bundle for Symfony - Enterprise-grade domain registrar integration

README 文档

README

PHP Version Symfony Version License

Enterprise-grade NameSilo API integration bundle for Symfony 7.4+ applications.

Overview

This bundle provides a complete, enterprise-ready integration with the NameSilo API for Symfony applications. It implements the contracts defined in estratos/domain-api-interface, making it pluggable into any application that uses the common domain provider interfaces.

Architecture

┌─────────────────────────────────────────────────┐ │ Domain API Interface Bundle │ │ (Contracts: DomainProviderInterface, etc.) │ └──────────────────┬──────────────────────────────┘ │ Implements ┌──────────────────▼──────────────────────────────┐ │ NameSilo Bundle │ │ - NameSiloClient (HTTP client) │ │ - Services (Domain, DNS, Contact, etc.) │ │ - ResponseMapper (JSON→DTO) │ │ - Events (DomainRegistered, etc.) │ └──────────────────┬──────────────────────────────┘ │ Uses ┌──────────────────▼──────────────────────────────┐ │ NameSilo API │ │ (https://www.namesilo.com/api/) │ └─────────────────────────────────────────────────┘

text

Features

  • Contract-Based Architecture - Implements domain-api-interface contracts
  • Full API Coverage - All NameSilo endpoints implemented
  • Immutable DTOs - Read-only data transfer objects
  • Strong Typing - PHP 8.3+ with strict_types
  • Event-Driven - Symfony events for domain operations
  • Comprehensive Logging - PSR-3 compliant with sensitive data masking
  • Retry Logic - Automatic retry with exponential backoff
  • Cache Support - Configurable caching for non-mutating operations
  • Error Handling - Specific exceptions for different scenarios
  • Sandbox Mode - Test integration without real transactions
  • 90%+ Test Coverage - Fully tested with PHPUnit

Installation

composer require estratos/namesilo-bundle
Configuration
1. Add to your .env file:
env
NAMESILO_API_KEY=your_api_key_here
NAMESILO_SANDBOX=false
2. Create config/packages/namesilo.yaml:
yaml
namesilo:
    api_key: '%env(NAMESILO_API_KEY)%'
    sandbox: '%env(bool:NAMESILO_SANDBOX)%'
    base_url: 'https://www.namesilo.com/api/'
    timeout: 30
    version: '1'
    response_type: 'json'
    
    logging:
        enabled: true
        level: 'info'
        mask_sensitive: true
    
    retry:
        max_retries: 3
        delay_ms: 1000
        http_codes: [429, 500, 502, 503, 504]
    
    cache:
        enabled: true
        ttl_seconds: 300
        cacheable_endpoints:
            - 'getPrices'
            - 'getAccountBalance'
            - 'listDomains'
    
    events:
        enabled: true
        events_to_dispatch:
            - 'domain_registered'
            - 'domain_renewed'
            - 'dns_record_added'
3. Register the bundle in config/bundles.php:
php
return [
    // ...
    Estratos\NameSiloBundle\NameSiloBundle::class => ['all' => true],
];
Usage Examples
Domain Registration
php
<?php

namespace App\Controller;

use Estratos\DomainApiInterface\Domain\DomainProviderInterface;
use Estratos\DomainApiInterface\Request\RegisterDomainRequest;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class DomainController extends AbstractController
{
    public function register(DomainProviderInterface $domainProvider)
    {
        // Check availability first
        $availability = $domainProvider->checkAvailability('example.com');
        
        if (!$availability->isAvailable()) {
            $this->addFlash('error', 'Domain is not available');
            return $this->redirectToRoute('domain_search');
        }
        
        $request = new RegisterDomainRequest(
            domain: 'example.com',
            years: 2,
            contactId: 'CONTACT_123',
            private: true,
            autoRenew: true,
            nameserver1: 'ns1.namesilo.com',
            nameserver2: 'ns2.namesilo.com'
        );
        
        try {
            $result = $domainProvider->register($request);
            
            if ($result->isSuccess()) {
                $this->addFlash('success', sprintf(
                    'Domain %s registered successfully. Order ID: %s',
                    $result->domain,
                    $result->orderId
                ));
            }
        } catch (InsufficientFundsException $e) {
            $this->addFlash('error', $e->getMessage());
        } catch (AuthenticationException $e) {
            $this->addFlash('error', 'Authentication failed. Check your API key.');
        }
    }
}
DNS Management
php
<?php

namespace App\Controller;

use Estratos\DomainApiInterface\DNS\DNSProviderInterface;
use Estratos\DomainApiInterface\Enum\RecordType;
use Estratos\DomainApiInterface\Request\AddDnsRecordRequest;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class DNSController extends AbstractController
{
    public function addRecord(DNSProviderInterface $dnsProvider)
    {
        $request = new AddDnsRecordRequest(
            domain: 'example.com',
            host: 'www',
            type: RecordType::A,
            value: '192.168.1.1',
            ttl: 3600
        );
        
        try {
            $record = $dnsProvider->addRecord($request);
            
            $this->addFlash('success', sprintf(
                'DNS record %s (%s) added successfully',
                $record->host,
                $record->type->value
            ));
            
            return $this->json($record);
        } catch (DNSException $e) {
            return $this->json(['error' => $e->getMessage()], 400);
        }
    }
}
Account Management
php
<?php

namespace App\Controller;

use Estratos\DomainApiInterface\Account\AccountProviderInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class AccountController extends AbstractController
{
    public function balance(AccountProviderInterface $accountProvider)
    {
        $balance = $accountProvider->getBalance();
        
        return $this->json([
            'balance' => $balance->balance,
            'currency' => $balance->currency,
            'available' => $balance->available,
            'reserved' => $balance->reserved,
        ]);
    }
    
    public function prices(AccountProviderInterface $accountProvider)
    {
        $prices = $accountProvider->getPrices();
        
        return $this->json([
            'currency' => $prices->currency,
            'prices' => $prices->prices,
        ]);
    }
}
Event Subscribers
php
<?php

namespace App\EventSubscriber;

use Estratos\NameSiloBundle\Event\DomainRegisteredEvent;
use Estratos\NameSiloBundle\Event\DomainRenewedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class DomainEventSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            DomainRegisteredEvent::class => 'onDomainRegistered',
            DomainRenewedEvent::class => 'onDomainRenewed',
        ];
    }
    
    public function onDomainRegistered(DomainRegisteredEvent $event): void
    {
        $domain = $event->getDomain();
        $orderId = $event->getOrderId();
        $registrationDate = $event->getRegistrationDate();
        $expirationDate = $event->getExpirationDate();
        
        // Send notification email
        // Log registration
        // Update database
    }
    
    public function onDomainRenewed(DomainRenewedEvent $event): void
    {
        $domain = $event->getDomain();
        $orderId = $event->getOrderId();
        $newExpirationDate = $event->getNewExpirationDate();
        
        // Update expiration date in database
        // Send renewal confirmation
    }
}
Error Handling
php
try {
    $result = $domainProvider->register($request);
} catch (AuthenticationException $e) {
    // Invalid API key or credentials
} catch (InsufficientFundsException $e) {
    // Not enough funds in account
    // $e->getRequiredAmount()
    // $e->getAvailableBalance()
} catch (InvalidDomainException $e) {
    // Invalid domain name format
    // $e->getErrors()
} catch (RateLimitException $e) {
    // Too many requests
    // $e->getRetryAfter()
} catch (ValidationException $e) {
    // Validation errors in request
    // $e->getErrors()
} catch (ApiException $e) {
    // General API error
    // $e->getEndpoint()
    // $e->getStatusCode()
    // $e->getRequestId()
}
Testing
bash
composer test
PHPStan Analysis
bash
composer phpstan
Code Style
bash
composer php-cs-fixer
composer php-cs-fixer-fix
License
MIT License. See the LICENSE file for details.

Contributing
Fork the repository

Create a feature branch

Write tests for your changes

Ensure all tests pass

Submit a pull request

estratos/namesilo-api 适用场景与选型建议

estratos/namesilo-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「api」 「bundle」 「provider」 「dns」 「domain」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 estratos/namesilo-api 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-26