forked from NativePHP/laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClipboard.php
62 lines (47 loc) · 1.34 KB
/
Clipboard.php
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
54
55
56
57
58
59
60
61
62
<?php
namespace Native\Laravel;
use Native\Laravel\Client\Client;
class Clipboard
{
public function __construct(protected Client $client) {}
public function clear()
{
$this->client->delete('clipboard');
}
public function text($text = null): string
{
if (is_null($text)) {
return $this->client->get('clipboard/text')->json('text');
}
$this->client->post('clipboard/text', [
'text' => $text,
]);
return $text;
}
public function html($html = null): string
{
if (is_null($html)) {
return $this->client->get('clipboard/html')->json('html');
}
$this->client->post('clipboard/html', [
'html' => $html,
]);
return $html;
}
public function image($image = null): ?string
{
if (is_null($image)) {
return $this->client->get('clipboard/image')->json('image');
}
$dataUri = $image;
if (is_string($image) && file_exists($image)) {
$type = pathinfo($image, PATHINFO_EXTENSION);
$data = file_get_contents($image);
$dataUri = "data:image/{$type};base64,".base64_encode($data);
}
$this->client->post('clipboard/image', [
'image' => $dataUri,
]);
return $image;
}
}