1 | <?php |
||
25 | final class Buffer implements ConnectorInterface |
||
26 | { |
||
27 | private $ctrlCodes = [ |
||
28 | ' [NUL] ' => 0, //Nulo |
||
29 | ' [EOT] ' => 4, //EOT fim da transmissão |
||
30 | ' [ENQ] ' => 5, //ENQ colocar na fila Pedido de status 1 |
||
31 | ' [BEL] ' => 7, //BEL sinal sonoro |
||
32 | ' [HT] ' => 9, //tabulação horizontal |
||
33 | ' [LF] ' => 10, //Inicia a impressão e avança uma linha |
||
34 | ' [VT] ' => 11, //tabulação vertical |
||
35 | ' [FF] ' => 12, //avança pagina |
||
36 | ' [CR] ' => 13, //retorno de carro |
||
37 | ' [SO] ' => 14, //SO Inicia modo expandido |
||
38 | ' [SI] ' => 15, //Seleciona modo condensado |
||
39 | ' [DLE] ' => 16, //Data Link Escape |
||
40 | ' [DC1] ' => 17, //DC1 Inicia modo enfatizado |
||
41 | ' [DC2] ' => 18, //DC2 Cancela modo condensado |
||
42 | ' [DC3] ' => 19, //DC3 Cancela modo enfatizado |
||
43 | ' [DC4] ' => 20, //DC4 Controle de dispositivo 4 Inicia modo normal |
||
44 | ' [NAK] ' => 21, // NAK |
||
45 | ' [SYN] ' => 22, //Sincronismo |
||
46 | ' [CAN] ' => 24, //CAN Cancela linha enviada |
||
47 | ' [EM] ' => 25, //Avança 4 linhas |
||
48 | ' [ESC] ' => 27, //escape |
||
49 | ' [FS] ' => 28, //FS |
||
50 | ' [GS] ' => 29, //GS |
||
51 | ' [DEL] ' => 127 //Cancela último caracter |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * Buffer of accumulated raw data. |
||
56 | * @var array |
||
57 | */ |
||
58 | private $buffer = null; |
||
59 | |||
60 | /** |
||
61 | * Create new print connector |
||
62 | * and set $buffer property as empty array |
||
63 | */ |
||
64 | public function __construct() |
||
68 | 28 | ||
69 | /** |
||
70 | * Destruct print connection |
||
71 | */ |
||
72 | public function __destruct() |
||
76 | 27 | ||
77 | /** |
||
78 | * Send data to buffer porperty |
||
79 | * @param string $data |
||
80 | */ |
||
81 | public function write($data) |
||
85 | 26 | ||
86 | 26 | /** |
|
87 | * Read data form buffer |
||
88 | * @param int $len |
||
89 | * @return string|array |
||
90 | */ |
||
91 | public function read($len = null) |
||
95 | |||
96 | 1 | /** |
|
97 | * Finalize printer connection |
||
98 | * and clear buffer property |
||
99 | */ |
||
100 | public function close() |
||
104 | |||
105 | 29 | /** |
|
106 | 29 | * Return the accumulated raw data that has been sent to this buffer. |
|
107 | * |
||
108 | * @param bool $retArray Enable return as array, otherwise will return a string |
||
109 | * @return string|array |
||
110 | */ |
||
111 | public function getDataBinary($retArray = true) |
||
118 | |||
119 | 1 | /** |
|
120 | * Return the data buffer in base64-encoded for transmission over TCP/IP, |
||
121 | * specifically for use qz.io or other similar system. |
||
122 | * |
||
123 | * @param boolean $retArray Enable return as array, otherwise will return a string |
||
124 | * @return array|string |
||
125 | */ |
||
126 | public function getDataBase64($retArray = true) |
||
134 | |||
135 | 1 | /** |
|
136 | * Returns the buffer data in JSON format |
||
137 | * for use with the java ajax |
||
138 | * It must be tested because there may be binary data |
||
139 | * that can not travel on GET or POST requests over TCP/IP |
||
140 | * |
||
141 | * @param bool $retArray Enable return as array, otherwise will return a string |
||
142 | * @return string |
||
143 | */ |
||
144 | public function getDataJson($retArray = true) |
||
148 | |||
149 | 1 | /** |
|
150 | * getDataReadable |
||
151 | * Return buffer data converted into a readable string. |
||
152 | * For testing and debbuging only, this format should not be sent to printer |
||
153 | * @param bool $retArray Enable return as array, otherwise will return a string |
||
154 | * @return string|array |
||
155 | */ |
||
156 | public function getDataReadable($retArray = true) |
||
164 | 2 | ||
165 | 2 | /** |
|
166 | 2 | * Convert buffer content |
|
167 | * @param string $type |
||
168 | * @return array |
||
169 | */ |
||
170 | protected function convertBuffer($type) |
||
183 | |||
184 | /** |
||
185 | * Converts unprintable characters in screen-printing characters |
||
186 | * used for debugging purpose only |
||
187 | * |
||
188 | * @param string $input |
||
189 | * @return string |
||
190 | */ |
||
191 | protected function friendlyBinary($input) |
||
207 | } |
||
208 |