mirror of
https://github.com/rclone/rclone.git
synced 2026-01-08 19:43:58 +00:00
librclone: add PHP bindings and test program
This commit is contained in:
committed by
GitHub
parent
9b76434ad5
commit
f1166757ba
53
librclone/php/rclone.php
Normal file
53
librclone/php/rclone.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
PHP interface to librclone.so, using FFI ( Foreign Function Interface )
|
||||
|
||||
Create an rclone object
|
||||
|
||||
$rc = new Rclone( __DIR__ . '/librclone.so' );
|
||||
|
||||
Then call rpc calls on it
|
||||
|
||||
$rc->rpc( "config/listremotes", "{}" );
|
||||
|
||||
When finished, close it
|
||||
|
||||
$rc->close();
|
||||
*/
|
||||
|
||||
class Rclone {
|
||||
|
||||
protected $rclone;
|
||||
private $out;
|
||||
|
||||
public function __construct( $libshared )
|
||||
{
|
||||
$this->rclone = \FFI::cdef("
|
||||
struct RcloneRPCResult {
|
||||
char* Output;
|
||||
int Status;
|
||||
};
|
||||
extern void RcloneInitialize();
|
||||
extern void RcloneFinalize();
|
||||
extern struct RcloneRPCResult RcloneRPC(char* method, char* input);
|
||||
extern void RcloneFreeString(char* str);
|
||||
", $libshared);
|
||||
$this->rclone->RcloneInitialize();
|
||||
}
|
||||
|
||||
public function rpc( $method, $input ): array
|
||||
{
|
||||
$this->out = $this->rclone->RcloneRPC( $method, $input );
|
||||
$response = [
|
||||
'output' => \FFI::string( $this->out->Output ),
|
||||
'status' => $this->out->Status
|
||||
];
|
||||
$this->rclone->RcloneFreeString( $this->out->Output );
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function close( ): void
|
||||
{
|
||||
$this->rclone->RcloneFinalize();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user