-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b612b8e
Showing
13 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php /** @noinspection PhpMultipleClassDeclarationsInspection */ | ||
|
||
namespace Ioctl; | ||
|
||
use FFI\CData; | ||
use Ioctl\PlatformSpecific\PlatformSpecific; | ||
|
||
final class Ioctl | ||
{ | ||
public const TIOCMBIS = PlatformSpecific::TIOCMBIS; | ||
public const TIOCMBIC = PlatformSpecific::TIOCMBIC; | ||
public const TIOCM_DTR = PlatformSpecific::TIOCM_DTR; | ||
public const TIOCM_RTS = PlatformSpecific::TIOCM_RTS; | ||
|
||
public static function has($attribute): bool | ||
{ | ||
return $attribute !== 0; | ||
} | ||
|
||
public static function attr(mixed $attribute, mixed $defaultValue): mixed | ||
{ | ||
return self::has($attribute) ? $attribute : $defaultValue; | ||
} | ||
|
||
public static function ioctl(int $fd, int $request, mixed ...$values): Ioctl | ||
{ | ||
return IoctlFunctions::ioctl($fd, $request, ...$values); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Ioctl; | ||
|
||
use FFI; | ||
|
||
final class IoctlFunctions | ||
{ | ||
private static FFI $ffi; | ||
|
||
public static function ioctl(int $fd, int $request, mixed ...$values) | ||
{ | ||
return self::getFFI()->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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Ioctl\PlatformSpecific; | ||
|
||
abstract class BasePlatformSpecific | ||
{ | ||
public const TIOCMBIS = 0; | ||
public const TIOCMBIC = 0; | ||
public const TIOCM_DTR = 0; | ||
public const TIOCM_RTS = 0; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Ioctl\PlatformSpecific; | ||
|
||
final class PlatformSpecific extends BasePlatformSpecific { | ||
public const TIOCMBIS = 0x8004746c; | ||
public const TIOCMBIC = 0x8004746b; | ||
public const TIOCM_DTR = 0x00000002; | ||
public const TIOCM_RTS = 0x00000004; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Ioctl\PlatformSpecific; | ||
|
||
final class PlatformSpecific extends BasePlatformSpecific | ||
{ | ||
public const TIOCMBIS = 0x00005416; | ||
public const TIOCMBIC = 0x00005417; | ||
public const TIOCM_DTR = 0x00000002; | ||
public const TIOCM_RTS = 0x00000004; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Ioctl\PlatformSpecific; | ||
|
||
final class PlatformSpecific extends BasePlatformSpecific | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
$platform = ucfirst(php_uname('s')); | ||
$platformSpecificFile = __DIR__ . "/" . $platform . "PlatformSpecific.php"; | ||
if (file_exists($platformSpecificFile)) { | ||
require_once $platformSpecificFile; | ||
} else { | ||
require_once __DIR__ . "/NonePlatformSpecific.php"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Ioctl; | ||
|
||
class RuntimeException extends \RuntimeException | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
int ioctl(int, unsigned long, ...); |