Visitor management app with SSO, kiosk, badges, reports, and Gitea CI deploy to frontdesk.ladill.com. Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Printers;
|
|
|
|
use App\Contracts\Printers\PrinterDriverInterface;
|
|
use App\Models\Visit;
|
|
use InvalidArgumentException;
|
|
|
|
class PrinterManager
|
|
{
|
|
/** @var array<string, PrinterDriverInterface> */
|
|
protected array $drivers = [];
|
|
|
|
public function __construct()
|
|
{
|
|
$this->register(new PdfPrinterDriver);
|
|
$this->register(new ZebraPrinterDriver);
|
|
$this->register(new BrotherPrinterDriver);
|
|
$this->register(new DymoPrinterDriver);
|
|
}
|
|
|
|
public function register(PrinterDriverInterface $driver): void
|
|
{
|
|
$this->drivers[$driver->name()] = $driver;
|
|
}
|
|
|
|
public function driver(?string $name = null): PrinterDriverInterface
|
|
{
|
|
$name = $name ?? config('frontdesk.printers.default_driver', 'pdf');
|
|
|
|
if (! isset($this->drivers[$name])) {
|
|
throw new InvalidArgumentException("Unknown printer driver: {$name}");
|
|
}
|
|
|
|
return $this->drivers[$name];
|
|
}
|
|
|
|
public function renderBadge(Visit $visit, ?string $driver = null): array
|
|
{
|
|
return $this->driver($driver)->renderBadge($visit);
|
|
}
|
|
}
|