How sof3/pharynx works
Purpose and entry points
Pharynx is a PHP CLI packager that recompiles PHP sources into a PSR-0-compatible directory tree and optionally a PHAR. Its primary executable flow starts at pharynx, dispatches through src/Main.php, and is assembled into distributable form by build.php.
A companion GitHub Action invokes the tool from gh-action/action.yml and gh-action/src/index.ts.
CLI orchestration
src/Main.php owns command execution: parse options, derive input/output settings, invoke source processing, copy requested assets, and choose directory versus PHAR output. src/Args.php represents command-line options including source roots, file mappings, output paths, packing, Composer inference, verbosity, and virion antigens.
Key paths: pharynx, src/Main.php, src/Args.php.
Source discovery and output assembly
Source roots passed with -s (or inferred through -i / Composer) are traversed and emitted beneath a configured output source-root path, defaulting to src. Explicit -f NAME:PATH mappings copy files or directories into named output locations.
src/Files.php provides filesystem-level operations used to construct the staged directory output. The staged tree is the boundary between source transformation and final packaging.
Key paths: src/Files.php, src/Main.php.
PHP recompilation pipeline
src/Processor.php is the central transformation stage. It processes PHP source files and rewrites them for PSR-0 output semantics rather than simply archiving original files. src/PhpFile.php models/processes individual PHP files, while src/PhpToken.php supplies token-level parsing/rewrite support.
This pipeline consumes source-root PHP files and produces rewritten files in the staged output tree.
Key paths: src/Processor.php, src/PhpFile.php, src/PhpToken.php.
Namespace/class path model
src/PsrItem.php represents PSR-oriented source items used by the recompilation logic to map PHP declarations and references into PSR-0-compatible layout. This is the semantic boundary of the packager: PHP code is analyzed and reorganized before PHAR creation.
Key paths: src/PsrItem.php, src/Processor.php.
Virion shading
Optional -a antigens trigger dependency shading for PocketMine “virion” libraries. src/Virion/VirionProcessor.php is the specialized transformation layer for this operation, integrated into the broader processing pipeline so bundled dependencies avoid naming collisions.
Key paths: src/Virion/VirionProcessor.php, src/Processor.php, src/Main.php.
Packaging, runtime, and integrations
The runtime is PHP, with Composer dependency metadata in composer.json. Final output can remain a directory (-o) or be packed as a PHAR (-p), requiring PHP’s PHAR support at execution/build time. Composer mode (-c) reads an already-installed project’s Composer context to infer source paths and virion dependencies.
Terminal interaction and verbose reporting are handled by src/Terminal.php. The PocketMine plugin-development integration consists of bootstrap and launch wrappers in plugin-dev/bootstrap-plugin-dev.php, plugin-dev/start.sh, and plugin-dev/start.cmd.
Key paths: src/Terminal.php, plugin-dev/bootstrap-plugin-dev.php, gh-action/action.yml.
Main entry points: Main.php Main · Processor.php Processor · pharynx pharynx · PhpFile.php PhpFile
Components 18
CLI
Recompilation
- Source roots · Explicit, inferred, or Composer-derived source paths.
- Processor · Rewrites PHP sources for PSR-0 output semantics.
src/Processor.php - PhpFile
src/PhpFile.php - PhpToken
src/PhpToken.php - PsrItem · Maps declarations and references into PSR-0 layout.
src/PsrItem.php - VirionProcessor · Optionally shades virion dependencies to prevent collisions.
src/Virion/VirionProcessor.php
Output
Integrations
- Composer context · Provides inferred source paths and virion dependencies in Composer mode.
composer.json - GitHub Action
gh-action/action.yml - Action runner
gh-action/src/index.ts - Plugin-dev bootstrap
plugin-dev/bootstrap-plugin-dev.php
Connections 21
- pharynx → Main: dispatches
- Main → Args: parses
- Main → Terminal: reports through
- Args → Source roots: selects
- Composer context → Args: infers inputs for -c
- Main → Processor: invokes
- Source roots → Processor: PHP files
- Processor → PhpFile: processes
- PhpFile → PhpToken: uses
- PhpFile → PsrItem: maps via
- Main → VirionProcessor: enables with -a
- VirionProcessor → Processor: integrates shading
- Processor → Files: emits rewritten files
- Main → Files: copies -f assets
- Files → Staged output tree: constructs
- Main → Directory or PHAR: chooses directory or -p
- Staged output tree → Directory or PHAR: packages
- build.php → pharynx: builds distributable
- GitHub Action → Action runner: runs
- Action runner → pharynx: invokes
- Plugin-dev bootstrap → pharynx: bootstraps for development