8000 Add print support · MasterRO94/nativephp-laravel@84bad16 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84bad16

Browse files
committed
Add print support
1 parent bf94123 commit 84bad16

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/DataObjects/Printer.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Native\Laravel\DataObjects;
4+
5+
class Printer
6+
{
7+
public function __construct(
8+
public string $name,
9+
public string $displayName,
10+
public string $description,
11+
public int $status,
12+
public bool $isDefault,
13+
public array $options
14+
)
15+
{
16+
17+
}
18+
}

src/System.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Native\Laravel;
44

55
use Native\Laravel\Client\Client;
6+
use Native\Laravel\DataObjects\Printer;
67

78
class System
89
{
@@ -21,4 +22,30 @@ public function promptTouchID(string $reason): bool
2122
'reason' => $reason,
2223
])->successful();
2324
}
25+
26+
/**
27+
* @return array<\Native\Laravel\DataObjects\Printer>
28+
*/
29+
public function printers(): ar 8000 ray
30+
{
31+
$printers = $this->client->get('system/printers')->json('printers');
32+
return collect($printers)->map(function ($printer) {
33+
return new Printer(
34+
data_get($printer, 'name'),
35+
data_get($printer, 'displayName'),
36+
data_get($printer, 'description'),
37+
data_get($printer, 'status'),
38+
data_get($printer, 'isDefault'),
39+
data_get($printer, 'options'),
40+
);
41+
})->toArray();
42+
}
43+
44+
public function print(string $html, Printer $printer = null): void
45+
{
46+
$this->client->post('system/print', [
47+
'html' => $html,
48+
'printer' => $printer->name ?? '',
49+
]);
50+
}
2451
}

0 commit comments

Comments
 (0)
0