Skip to content

refactor: migrate FFI layer to Lib singleton with instance methods - #25

Merged
CodeWithKyrian merged 1 commit into
mainfrom
refactor/ffi-lib-singleton-and-instance-methods
Jun 1, 2026
Merged

CodeWithKyrian merged 1 commit into
mainfrom
refactor/ffi-lib-singleton-and-instance-methods

Conversation

@CodeWithKyrian

Copy link
Copy Markdown
Contributor

This PR replaces the old Bindings interface + static helpers FFI pattern with a singleton Lib class that uses @method annotations and __call() forwarding for a cleaner, more idiomatic PHP developer experience.

Motivation and Context

The old architecture had a separate Bindings interface listing all ~140 C function signatures for IDE autocompletion, plus a Lib class with static helper methods. Lib::get() returned a raw \FFI typed as Bindings&\FFI, which wasn't a natural PHP API surface. All helpers were static, making the codebase harder to navigate and refactor.

What's Changed

  • Lib is now a proper singleton with @method PHPDoc annotations (replacing Bindings.php, which was deleted)
  • Lib::get() returns a Lib instance with full IDE autocomplete via @method
  • All C function calls forward through __call() to the underlying \FFI instance
  • checkStatus, getLastError, createCArray, readSizeTArray (renamed from extractShapeFromPointer) converted to instance methods
  • createShapeArray and createOutputMetadataBuffers removed and inlined at all call sites
  • All caller variables renamed from $ffi to $lib to reflect the Lib type
  • Updated static analysis instructions in AGENTS.md and CONTRIBUTING.md

Breaking Changes

None. All public APIs remain identical; this is purely an internal refactor.

@CodeWithKyrian
CodeWithKyrian force-pushed the refactor/ffi-lib-singleton-and-instance-methods branch from 6f3fb7e to 5853681 Compare June 1, 2026 14:28
@CodeWithKyrian
CodeWithKyrian merged commit ee3fdd1 into main Jun 1, 2026
14 checks passed
@CodeWithKyrian
CodeWithKyrian deleted the refactor/ffi-lib-singleton-and-instance-methods branch June 1, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant