PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.9.16
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.9.16
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / Services / Print_Format_Resolver.php

Print_Format_Resolver.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.9.16, at includes/Services/Print_Format_Resolver.php

66 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Print format resolver.
4 *
5 * Single source of truth for the wire format a print job uses, given a
6 * printer and a template. PrintNode chooses between PDF and raw ESC/POS based
7 * on the printer's configured format; other providers delegate to Provider.
8 *
9 * @package WCPOS\WooCommercePOS\Services
10 */
11
12 namespace WCPOS\WooCommercePOS\Services;
13
14 /**
15 * Print_Format_Resolver class.
16 */
17 class Print_Format_Resolver {
18 /**
19 * Resolve the wire format and HTTP content type for a print job.
20 *
21 * @param array $printer Printer configuration.
22 * @param array $template Template configuration.
23 *
24 * @return array{kind:string, content_type:string}
25 */
26 public function resolve( array $printer, array $template ): array {
27 $provider = (string) ( $printer['provider'] ?? '' );
28 $engine = (string) ( $template['engine'] ?? '' );
29
30 if ( 'printnode' === $provider ) {
31 if ( 'thermal' !== $engine ) {
32 return array(
33 'kind' => 'pdf',
34 'content_type' => 'application/pdf',
35 );
36 }
37
38 $format = (string) ( $printer['printnode_format'] ?? 'pdf' );
39 if ( 'raw' === $format ) {
40 return array(
41 'kind' => 'escpos',
42 'content_type' => 'application/octet-stream',
43 );
44 }
45
46 return array(
47 'kind' => 'pdf',
48 'content_type' => 'application/pdf',
49 );
50 }
51
52 $wire = Provider::wire_format( $provider, $engine );
53 if ( null === $wire ) {
54 return array(
55 'kind' => '',
56 'content_type' => '',
57 );
58 }
59
60 return array(
61 'kind' => $wire,
62 'content_type' => Provider::content_type( $provider ),
63 );
64 }
65 }
66