Skip to content

Commit a4605f0

Browse files
authored
Merge pull request #103 from NativePHP/printer-support
Printer support
2 parents bf94123 + 4af05cb commit a4605f0

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/DataObjects/Printer.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

src/System.php

Lines changed: 28 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,31 @@ 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(): array
30+
{
31+
$printers = $this->client->get('system/printers')->json('printers');
32+
33+
return collect($printers)->map(function ($printer) {
34+
return new Printer(
35+
data_get($printer, 'name'),
36+
data_get($printer, 'displayName'),
37+
data_get($printer, 'description'),
38+
data_get($printer, 'status'),
39+
data_get($printer, 'isDefault'),
40+
data_get($printer, 'options'),
41+
);
42+
})->toArray();
43+
}
44+
45+
public function print(string $html, Printer $printer = null): void
46+
{
47+
$this->client->post('system/print', [
48+
'html' => $html,
49+
'printer' => $printer->name ?? '',
50+
]);
51+
}
2452
}

0 commit comments

Comments
 (0)