1
0
mirror of https://github.com/rclone/rclone.git synced 2024-12-23 07:29:35 +01:00
rclone/librclone/php/rclone.php

54 lines
1.2 KiB
PHP
Raw Normal View History

<?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();
}
}