$ show overtrue/pinyin
This is a mature PHP library for converting Chinese characters (simplified and traditional) to pinyin romanization. It provides a clean facade (`Pinyin` class) with static methods for common conversions (sentence, phrase, name, heteronym, permalink, abbreviation) and supports multiple output tone styles (symbol, number, none). The architecture employs the strategy pattern via a `ConverterFactory` that selects among three converter implementations: `MemoryOptimizedConverter` (~400KB memory), `CachedConverter` (~4MB, faster), and `SmartConverter` (adaptive). An abstract base class (`AbstractConverter`) handles shared preprocessing, tone formatting, and dictionary loading. The library includes a CLI tool (`bin/pinyin`) for command-line use, comprehensive test coverage, static analysis at PHPStan level 9, and a data generation pipeline (`bin/build`) that downloads and patches dictionary data from external sources. The dictionary is split across multiple PHP array files in `data/`, covering characters, surnames, and multi-word phrases with polyphone disambiguation. The codebase is well-structured, follows modern PHP practices (8.1+ enums, typed properties), and is actively maintained with CI and dependabot.
The LLM identified 3 files worth highlighting for reuse:
A standalone utility class implementing ArrayAccess, Countable, IteratorAggregate, JsonSerializable, and Stringable. Provides fluent methods like `map`, `join`, `filter`, and `toArray`. It is self-contained (no internal dependencies) and can be extracted into any PHP project needing a lightweight, immutable-like collection with array syntax and JSON serialization. Demonstrates clean implementation of multiple PHP interfaces with minimal boilerplate.
A PHP 8.1 backed enum defining three tone styles: Symbol, None, and Number. It is a simple, self-contained component that encapsulates the tone style logic. Could be reused in any project requiring similar enum-based configuration. Demonstrates proper use of modern PHP enums with string backing.
A clean, minimal interface defining the contract for pinyin converters. It declares methods for converting sentences, phrases, names, and characters, with options for heteronym handling and tone styles. This interface is the cornerstone of the strategy pattern used in the library and could serve as a template for any conversion service that needs multiple interchangeable implementations. It is self-contained and has no dependencies.