Download the PHP package klitsche/ffigen without Composer
On this page you can find all versions of the php package klitsche/ffigen. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download klitsche/ffigen
More information about klitsche/ffigen
Files in klitsche/ffigen
Package ffigen
Short Description FFI binding generator
License MIT
Homepage https://klitsche.github.io/ffigen/
Informations about the package ffigen
ffigen - a FFI bindings generator for PHP
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 valuesMethods.php
- holding function bindings as static methods plus phpdoc in a trait
It is heavily inspired by FFIMe and depends on PHPCParser by ircmaxell.
WIP: Expect breaking changes along all 0.* pre-releases.
Requirements
- PHP ^7.4 || ^8.0
- For examples: FFI extension must be available and enabled
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):
Optional: add your own Parser class to customize pre oder post processing logic (example):
Do not forget to register the Parser namespace in your composer.json for autoloading (dev is okay):
Dump autoloading with
composer dump-autoload
Run ffigen to generate binding files
vendor/bin/ffigen
This generates the two files in the output path:
constants.php
- add this to your autoloadingMethods.php
- add this to your own class context and use it within your own high level php library
Do not forget to add constants.php
to your compose.json for autoloading:
Play with examples
Build docker image with preinstalled c libraries (uuid, snappy & librdkafka):
docker-compose build php74
Run uuid example
docker-compose run --rm php74 php bin/ffigen generate -c examples/UUID/.ffigen.yml
docker-compose run --rm php74 php examples/UUID/test.php
Run snappy example (see Snappy class for a simple high level example)
docker-compose run --rm php74 bin/ffigen generate -c examples/Snappy/.ffigen.yml
docker-compose run --rm php74 php examples/Snappy/test.php
Run rdkafka example (librdkafka 1.5.2 & mock cluster)
docker-compose run --rm php74 bin/ffigen generate -c examples/RdKafka/.ffigen.yml
docker-compose run --rm php74 php examples/RdKafka/test.php
Todos
- [x] Add travis
- [x] Add more tests
- [ ] Add documentation
- [ ] Add support for Windows, macOS
- [ ] Add more examples (and learn from them)
- [ ] Think about multi version support
- [ ] Think about custom interface / class generation for types
- [ ] Think about clang / cpp / readelf adapter (cpp defines only & clean file, clang -c11 ast-dump=json, readelf --dyn-syms)
All versions of ffigen with dependencies
ircmaxell/php-c-parser Version dev-master#fd8f5efefd0fcc6c5119d945694acaa3a6790ada
symfony/yaml Version ^5.0
symfony/filesystem Version ^5.0
symfony/console Version ^5.0
brick/varexporter Version ^0.3.2