定制 laravel-liberu/php-gedcom 二次开发

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

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

laravel-liberu/php-gedcom

Composer 安装命令:

composer require laravel-liberu/php-gedcom

包简介

A GEDCOM file parser (read + write) for PHP 8.4+

README 文档

README

Latest Stable Version Tests

Requirements

  • php-gedcom 2.0+ requires PHP 8.3 (or later). GEDCOM 5.5.1 only
  • php-gedcom 3.0+ requires PHP 8.4 (or later). GEDCOM 5.5.1 only
  • php-gedcom 4.0+ requires PHP 8.4 (or later). GEDCOM 5.5.1, GEDCOM 7.0 and GEDCOM X with performance optimizations

Installation

There are two ways of installing php-gedcom.

Composer

To install php-gedcom in your project using composer, simply add the following require line to your project's composer.json file:

{
    "require": {
        "liberu-genealogy/php-gedcom": "2.0.*"
    }
}

Download and __autoload

If you are not using composer, you can download an archive of the source from GitHub and extract it into your project. You'll need to setup an autoloader for the files, unless you go through the painstaking process if requiring all the needed files one-by-one. Something like the following should suffice:

spl_autoload_register(function ($class) {
    $pathToGedcom = __DIR__ . '/library/'; // TODO FIXME

    if (!substr(ltrim($class, '\\'), 0, 7) == 'Gedcom\\') {
        return;
    }

    $class = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
    if (file_exists($pathToGedcom . $class)) {
        require_once($pathToGedcom . $class);
    }
});

Performance Optimizations (PHP 8.4+)

php-gedcom 4.0+ includes significant performance improvements leveraging PHP 8.4 features:

Key Optimizations

  • Streaming Parsers: Automatic streaming for large files (>100MB) to reduce memory usage
  • Intelligent Caching: LRU cache with file modification tracking and automatic invalidation
  • Property Hooks: Lazy initialization of parsers and generators using PHP 8.4 property hooks
  • Optimized JSON Processing: Enhanced JSON parsing with streaming support for large Gedcom X files
  • Memory Efficiency: Reduced memory footprint through optimized data structures

Performance Features

  • Caching System: Automatic caching of parsed files with configurable TTL and size limits
  • Large File Support: Streaming parsers handle files of any size without memory exhaustion
  • Format Detection: Fast file format detection with content analysis
  • Batch Operations: Optimized array operations using PHP 8.4 features

Benchmarking

Run performance benchmarks to measure improvements:

# Basic benchmark
php examples/cli/performance-benchmark.php sample.ged

# Full benchmark with streaming and report
php examples/cli/performance-benchmark.php large.ged --streaming --report

# Save baseline for comparison
php examples/cli/performance-benchmark.php test.ged --baseline

# Compare with baseline
php examples/cli/performance-benchmark.php test.ged --compare

Cache Configuration

use Gedcom\GedcomResource;

// Enable caching with custom configuration
$resource = new GedcomResource(
    cacheEnabled: true,
    cacheConfig: [
        'memory_items' => 2000,           // Max items in memory cache
        'cache_dir' => '/tmp/gedcom',     // Cache directory
        'ttl' => 7200                     // Cache TTL in seconds
    ]
);

// Get cache statistics
$stats = $resource->getCacheStats();
echo "Memory items: " . $stats['memory_items'] . "\n";

// Clear cache when needed
$resource->clearCache();

GEDCOM Format Support

php-gedcom 4.0+ supports both GEDCOM 5.5.1 and GEDCOM 7.0 formats. The library automatically detects the version when parsing and can write to either format.

Parsing GEDCOM Files

The parser automatically handles both GEDCOM 5.5.1 and 7.0 formats:

$parser = new \Gedcom\Parser();

// Parse a GEDCOM 5.5.1 file
$gedcom551 = $parser->parse('family_tree_551.ged');

// Parse a GEDCOM 7.0 file
$gedcom70 = $parser->parse('family_tree_70.ged');

// Check the version
$head = $gedcom70->getHead();
$gedc = $head->getGedc();
$version = $gedc->getVersion(); // Returns "7.0" or "5.5.1"

Writing GEDCOM Files

You can export to either format by specifying the format constant:

use Gedcom\Writer;

// Write as GEDCOM 5.5.1 (default)
$output551 = Writer::convert($gedcom, Writer::GEDCOM55);
file_put_contents('output_551.ged', $output551);

// Write as GEDCOM 7.0
$output70 = Writer::convert($gedcom, Writer::GEDCOM70);
file_put_contents('output_70.ged', $output70);

Version-Specific Features

The library handles version-specific features automatically:

Feature GEDCOM 5.5.1 GEDCOM 7.0
Unique Identifier _UID (custom tag) UID (standard tag)
Source Data Date Not supported DATE subfield
Source Data Text Not supported TEXT subfield

When writing to a specific format:

  • GEDCOM 5.5.1: Outputs _UID tags for unique identifiers
  • GEDCOM 7.0: Outputs UID tags for unique identifiers

The parser reads both tag types, ensuring compatibility when converting between versions.

Usage

To parse a GEDCOM file and load it into a collection of PHP Objects, simply instantiate a new Parser object and pass it the file name to parse. The resulting Gedcom object will contain all the information stored within the supplied GEDCOM file:

$parser = new \Gedcom\Parser();
$gedcom = $parser->parse('tmp.ged');

foreach ($gedcom->getIndi() as $individual) {
    $names = $individual->getName();
    if (!empty($names)) {
        $name = reset($names); // Get the first name object from the array
        echo $individual->getId() . ': ' . $name->getSurn() . ', ' . $name->getGivn() . PHP_EOL;
    }
}

Contributing

Pull requests are welcome, as are issues.

License

MIT License (see License.md). This means you must retain the copyright and permission notice is all copies, or substantial portions of this software.

Contributors

laravel-liberu/php-gedcom 适用场景与选型建议

laravel-liberu/php-gedcom 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.5k 次下载、GitHub Stars 达 76, 最近一次更新时间为 2023 年 05 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 76
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 76
  • Watchers: 3
  • Forks: 47
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-19