Skip to content

Commit

Permalink
Merge pull request #103 from NativePHP/printer-support
Browse files Browse the repository at this point in the history
Printer support
  • Loading branch information
mpociot committed Aug 1, 2023
2 parents bf94123 + 4af05cb commit a4605f0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/DataObjects/Printer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Native\Laravel\DataObjects;

class Printer
{
public function __construct(
public string $name,
public string $displayName,
public string $description,
public int $status,
public bool $isDefault,
public array $options
) {

}
}
28 changes: 28 additions & 0 deletions src/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Native\Laravel;

use Native\Laravel\Client\Client;
use Native\Laravel\DataObjects\Printer;

class System
{
Expand All @@ -21,4 +22,31 @@ public function promptTouchID(string $reason): bool
'reason' => $reason,
])->successful();
}

/**
* @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 ?? '',
]);
}
}

0 comments on commit a4605f0

Please sign in to comment.