mirror of
https://github.com/rclone/rclone.git
synced 2024-11-29 20:04:52 +01:00
54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
|
<?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();
|
||
|
}
|
||
|
}
|