tourze/ddns-bundle

DDNS动态域名解析服务模块

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/tourze/ddns-bundle

0.0.1 2025-05-26 13:09 UTC

This package is auto-updated.

Last update: 2025-10-31 19:54:33 UTC


README

Latest Version PHP Version License Total Downloads

English | 中文

DDNS (Dynamic DNS) service bundle for Symfony applications.

Features

  • Automatic DNS Updates: Automatically updates DNS records when entities are modified
  • Attribute-Based Configuration: Use PHP 8 attributes to mark domain and IP fields
  • Provider Agnostic: Support for multiple DNS providers through interfaces
  • Console Commands: Manual and scheduled DNS updates
  • Doctrine Integration: Seamless integration with Doctrine ORM events

Installation

composer require tourze/ddns-bundle

Dependencies

  • PHP 8.1 or higher
  • Symfony 6.4 or higher
  • Doctrine ORM

Quick Start

1. Register the Bundle

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

Usage

Using DDNS Attributes

Use #[DDNSDomain] and #[DdnsIp] attributes to mark domain and IP fields in your entities:

<?php

use DDNSBundle\Attribute\DDNSDomain;
use DDNSBundle\Attribute\DdnsIp;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class ServerNode
{
    #[ORM\Column(type: 'string')]
    #[DDNSDomain(provider: 'cloudflare')]
    private string $domain;

    #[ORM\Column(type: 'string')]
    #[DdnsIp(provider: 'cloudflare')]
    private string $ipAddress;

    // ... other fields and methods
}

Advanced Usage

Automatic DDNS Updates

When entities are created or updated, the system automatically:

  1. Checks if the entity contains DDNS attributes
  2. Extracts domain and IP address information
  3. Calls the corresponding DNS provider to update DNS records

Attribute Parameters

  • provider: Optional parameter to specify the DNS provider (e.g., 'cloudflare', 'aliyun', etc.)

Console Commands

ddns:provider:run

Runs DDNS provider update tasks. This command will:

  1. Iterate through all IP resolvers to get domain and IP mappings that need updating
  2. Check if each DNS provider supports the domain
  3. Update the corresponding DNS records
# Manually run DDNS update
php bin/console ddns:provider:run

This command is configured as a cron task and runs automatically every minute.

Configuration

The bundle automatically registers the following services:

  • DDNSAttributeProcessor: Attribute processor
  • DDNSUpdateService: DDNS update service
  • DDNSEntityListener: Entity change listener

Examples

See examples/ExampleEntity.php for a complete usage example.

How It Works

  1. Attribute Marking: Use #[DDNSDomain] and #[DdnsIp] attributes on entity fields
  2. Event Listening: Doctrine event listeners monitor entity creation and update events
  3. Attribute Parsing: Attribute processor extracts field values with DDNS attributes
  4. DNS Updates: Calls DNS provider interfaces to update DNS records

Contributing

Contributions are welcome! Please follow these guidelines:

  1. Issues: Report bugs or suggest features via GitHub Issues
  2. Pull Requests: Fork the repository and submit PRs with clear descriptions
  3. Code Style: Follow PSR-12 coding standards
  4. Testing: Ensure all tests pass and add tests for new features
  5. Documentation: Update documentation for any changes

References

Changelog

See CHANGELOG.md for details on version history and updates.

License

This bundle is licensed under the MIT License. See the LICENSE file for more information.