PHPackages                             klitsche/ffigen - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. klitsche/ffigen

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

klitsche/ffigen
===============

FFI binding generator

v0.8.1(3y ago)168.0k21MITPHPPHP ^7.4 || ^8.0

Since May 8Pushed 3y ago2 watchersCompare

[ Source](https://github.com/klitsche/ffigen)[ Packagist](https://packagist.org/packages/klitsche/ffigen)[ Docs](https://klitsche.github.io/ffigen/)[ RSS](/packages/klitsche-ffigen/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (11)Used By (1)

ffigen - a FFI bindings generator for PHP
=========================================

[](#ffigen---a-ffi-bindings-generator-for-php)

[![Build Status](https://github.com/klitsche/ffigen/actions/workflows/test.yml/badge.svg)](https://github.com/klitsche/ffigen/actions/workflows/test.yml)[![Test Coverage](https://camo.githubusercontent.com/df5d6d774d45865b6f7fde2a674710d8cb2b6f41e26f57b5e1a69d33693ea768/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f37346261313331616237336335386463323836342f746573745f636f766572616765)](https://codeclimate.com/github/klitsche/ffigen/test_coverage)[![Maintainability](https://camo.githubusercontent.com/f513086f7b5ca3e78b8acd769ad6d790433038a46ed2f5cfdd302a736f2760b4/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f37346261313331616237336335386463323836342f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/klitsche/ffigen/maintainability)[![Packagist Version](https://camo.githubusercontent.com/92cac77f28deffe7d0a893d5ae7171a1be339dbb4f7879cd858fce33acfe8b86/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6c6974736368652f66666967656e)](https://packagist.org/packages/klitsche/ffigen)

`ffigen` is a simple cli helper to quickly generate and update low level PHP FFI bindings for C libraries.

It generates two PHP files out of provided C header file(s):

- `constants.php` - holding constant values
- `Methods.php` - holding function bindings as static methods plus phpdoc in a trait

It is heavily inspired by [FFIMe](https://github.com/ircmaxell/FFIMe) and depends on [PHPCParser](https://github.com/ircmaxell/php-c-parser) by ircmaxell.

**WIP**: Expect breaking changes along all 0.\* pre-releases.

Requirements
------------

[](#requirements)

- PHP ^7.4 || ^8.0
- For examples: FFI extension must be available and enabled

Quick Start
-----------

[](#quick-start)

Install in your project:

```
composer require --dev klitsche/ffigen

```

Install a c library (eg. uuid).

Add a config file to your project root:

```
.ffigen.yml

```

Tweak this config file (example):

```
headerFiles:
  - uuid/uuid.h
libraryFile: libuuid.so.1
parserClass: Klitsche\FFIGen\Examples\UUID\FFIGen\Parser
outputPath: ./
excludeConstants:
  - /^(?!(FFI|UUID)_).*/
excludeMethods:
namespace: Klitsche\FFIGen\Examples\UUID
```

Optional: add your own Parser class to customize pre oder post processing logic (example):

```
