From b612b8ecff3c6f1565a1541ed952a494ee062f49 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 23 Jul 2022 19:18:51 +0200 Subject: [PATCH] First commit --- .gitignore | 2 ++ LICENSE | 21 ++++++++++++++ README.md | 9 ++++++ composer.json | 20 +++++++++++++ src/Ioctl.php | 29 +++++++++++++++++++ src/IoctlFunctions.php | 28 ++++++++++++++++++ src/PlatformSpecific/BasePlatformSpecific.php | 12 ++++++++ .../DarwinPlatformSpecific.php | 11 +++++++ .../LinuxPlatformSpecific.php | 11 +++++++ src/PlatformSpecific/NonePlatformSpecific.php | 8 +++++ src/PlatformSpecific/PlatformSpecific.php | 9 ++++++ src/RuntimeException.php | 8 +++++ src/header.h | 1 + 13 files changed, 169 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 composer.json create mode 100644 src/Ioctl.php create mode 100644 src/IoctlFunctions.php create mode 100644 src/PlatformSpecific/BasePlatformSpecific.php create mode 100644 src/PlatformSpecific/DarwinPlatformSpecific.php create mode 100644 src/PlatformSpecific/LinuxPlatformSpecific.php create mode 100644 src/PlatformSpecific/NonePlatformSpecific.php create mode 100644 src/PlatformSpecific/PlatformSpecific.php create mode 100644 src/RuntimeException.php create mode 100644 src/header.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88e99d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor +composer.lock \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..06cfc1b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Pierre Pélisset + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..64d07d1 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# php-ioctl + +This package is a basic port of Ioctl Unix API for PHP using FFI. + +## Installation +php-ioctl require PHP8.0 and php-ffi enabled. To install this package, use composer to require package `ppelisset/ioctl`. + +## Documentation +`Ioctl\Ioctl::ioctl` - control device \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..21bb09e --- /dev/null +++ b/composer.json @@ -0,0 +1,20 @@ +{ + "name": "ppelisset/ioctl", + "description": "Port of Unix ioctl API with PHP FFI", + "license": "MIT", + "authors": [ + { + "name": "Pierre Pélisset", + "email": "ppelisset@hotmail.fr" + } + ], + "require": { + "php": ">=8.0", + "ext-ffi": "*" + }, + "autoload": { + "psr-4": { + "Ioctl\\": "src/" + } + } +} diff --git a/src/Ioctl.php b/src/Ioctl.php new file mode 100644 index 0000000..2524c78 --- /dev/null +++ b/src/Ioctl.php @@ -0,0 +1,29 @@ +ioctl($fd, $request, ...$values); + } + + private static function getFFI(): FFI + { + if (is_null(self::$ffi)) { + self::createFFI(); + } + return self::$ffi; + } + + private static function createFFI(): void + { + self::$ffi = FFI::load(__DIR__ . "/header.h"); + } +} \ No newline at end of file diff --git a/src/PlatformSpecific/BasePlatformSpecific.php b/src/PlatformSpecific/BasePlatformSpecific.php new file mode 100644 index 0000000..de573fd --- /dev/null +++ b/src/PlatformSpecific/BasePlatformSpecific.php @@ -0,0 +1,12 @@ +