File: rclone.php

package info (click to toggle)
rclone 1.69.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 45,716 kB
  • sloc: sh: 1,115; xml: 857; python: 754; javascript: 612; makefile: 299; ansic: 101; php: 74
file content (53 lines) | stat: -rw-r--r-- 1,244 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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();
    }
}