From baa5f4bdb3e05df25ee5cb3b765108eb50710639 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Sun, 16 Jun 2019 02:05:36 +0200 Subject: [PATCH] Added printer enumeration --- examples/printers.php | 12 +++++++++++ src/PrinterList.php | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 examples/printers.php create mode 100644 src/PrinterList.php diff --git a/examples/printers.php b/examples/printers.php new file mode 100644 index 0000000..db16e1e --- /dev/null +++ b/examples/printers.php @@ -0,0 +1,12 @@ +$meta) { + printf("%s\n%s\n\n", $printer, json_encode($meta,JSON_PRETTY_PRINT)); +} + diff --git a/src/PrinterList.php b/src/PrinterList.php new file mode 100644 index 0000000..607fb32 --- /dev/null +++ b/src/PrinterList.php @@ -0,0 +1,49 @@ + $name, + 'description' => array_shift($meta), + ]; + foreach ($meta as $prop) { + if (strpos($prop, "=") === false) continue; + list($key,$value) = explode("=",$prop,2); + $props[$key] = $value; + } + self::$printers[$name] = $props; + } + } + } + + public function getIterator() + { + if (empty(self::$printers)) self::update(); + return new ArrayIterator(self::$printers); + } + + public function getPrinterNames() + { + if (empty(self::$printers)) self::update(); + return array_keys(self::$printers); + } +} \ No newline at end of file