forked from NativePHP/laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystem.php
90 lines (75 loc) · 2.37 KB
/
System.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace Native\Laravel;
use Native\Laravel\Client\Client;
use Native\Laravel\DataObjects\Printer;
use Native\Laravel\Support\Timezones;
class System
{
public function __construct(protected Client $client) {}
public function canPromptTouchID(): bool
{
return $this->client->get('system/can-prompt-touch-id')->json('result');
}
public function promptTouchID(string $reason): bool
{
return $this->client->post('system/prompt-touch-id', [
'reason' => $reason,
])->successful();
}
public function canEncrypt(): bool
{
return $this->client->get('system/can-encrypt')->json('result');
}
public function encrypt(string $string): ?string
{
return $this->client->post('system/encrypt', [
'string' => $string,
])->json('result');
}
public function decrypt(string $string): ?string
{
return $this->client->post('system/decrypt', [
'string' => $string,
])->json('result');
}
/**
* @return array<\Native\Laravel\DataObjects\Printer>
*/
public function printers(): array
{
$printers = $this->client->get('system/printers')->json('printers');
return collect($printers)->map(function ($printer) {
return new Printer(
data_get($printer, 'name'),
data_get($printer, 'displayName'),
data_get($printer, 'description'),
data_get($printer, 'status'),
data_get($printer, 'isDefault'),
data_get($printer, 'options'),
);
})->toArray();
}
public function print(string $html, ?Printer $printer = null): void
{
$this->client->post('system/print', [
'html' => $html,
'printer' => $printer->name ?? '',
]);
}
public function printToPDF(string $html): string
{
return $this->client->post('system/print-to-pdf', [
'html' => $html,
])->json('result');
}
public function timezone(): string
{
$timezones = new Timezones;
if (PHP_OS_FAMILY === 'Windows') {
$timezone = $timezones->translateFromWindowsString(exec('tzutil /g'));
} else {
$timezone = $timezones->translateFromAbbreviatedString(exec('date +%Z'));
}
return $timezone;
}
}