# woocommerce-pos/1.10.14/includes/Services/Print_Format_Resolver.php

WCPOS – Point of Sale (POS) plugin for WooCommerce, version 1.10.14. 71 lines.

- Page: https://pluginprobe.com/plugins/woocommerce-pos/1.10.14/code/includes/Services/Print_Format_Resolver.php
- Raw: https://pluginprobe.com/plugins/woocommerce-pos/1.10.14/raw/includes/Services/Print_Format_Resolver.php
- Modified: 2026-08-25T07:52:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/woocommerce-pos/1.10.14/code/includes/Services/Print_Format_Resolver.php#L10-L20`.

```php
<?php
/**
 * Print format resolver.
 *
 * Single source of truth for the wire format a print job uses, given a
 * printer and a template. PrintNode chooses between PDF and raw ESC/POS based
 * on the printer's configured format; other providers delegate to Provider.
 *
 * @package WCPOS\WooCommercePOS\Services
 */

namespace WCPOS\WooCommercePOS\Services;

/**
 * Print_Format_Resolver class.
 */
class Print_Format_Resolver {
	/**
	 * Resolve the wire format and HTTP content type for a print job.
	 *
	 * @param array $printer  Printer configuration.
	 * @param array $template Template configuration.
	 *
	 * @return array{kind:string, content_type:string}
	 */
	public function resolve( array $printer, array $template ): array {
		// Printer rows saved before the provider field existed have none; they
		// must behave as the default provider, not fall through every branch.
		$provider = Provider::normalize( \is_string( $printer['provider'] ?? null ) ? $printer['provider'] : null );
		$adapter  = Provider::adapter( $provider );
		if ( null === $adapter ) {
			return array(
				'kind' => '',
				'content_type' => '',
			);
		}

		return $adapter->format( $printer, $template );
	}

	/**
	 * Resolve the HTTP content type for a printer when no template is in hand.
	 *
	 * Two callers have a printer but no template to resolve against. The
	 * diagnostic builder always does — its payload is hand-built, not rendered
	 * from a template — and always gets the provider's declared type. The
	 * reprint path reaches it only when the source job's template can no longer
	 * be rendered on the printer, and even then only when the job carries no
	 * `pn_kind`; a job that has one keeps its stored content type instead, so
	 * the two halves cannot drift apart.
	 *
	 * PrintNode therefore reports its PDF default here even for a printer in raw
	 * mode, unlike resolve(), which sees the engine and can honour
	 * `printnode_format`. Neither caller can act on the difference: the
	 * diagnostic builder throws for PrintNode before it gets here, and the
	 * reprint path's `pn_kind` condition above keeps a raw job away from this
	 * answer. Prefer resolve() wherever a template is in hand — it answers both
	 * halves of the pairing at once.
	 *
	 * @param array $printer Printer configuration.
	 *
	 * @return string
	 */
	public function content_type_for_printer( array $printer ): string {
		$provider = Provider::normalize( \is_string( $printer['provider'] ?? null ) ? $printer['provider'] : null );
		$adapter  = Provider::adapter( $provider );

		return null === $adapter ? 'application/octet-stream' : $adapter->content_type();
	}
}

```
