Mike42\Escpos\PrintBuffers\PrintBuffer::setPrinter PHP Method

setPrinter() public method

Used by Escpos to hook up one-to-one link between buffers and printers.
public setPrinter ( Printer $printer = null )
$printer Mike42\Escpos\Printer New printer
    public function setPrinter(Printer $printer = null);

Usage Example

Beispiel #1
0
 /**
  * Attach a different print buffer to the printer. Buffers are responsible for handling text output to the printer.
  *
  * @param PrintBuffer $buffer The buffer to use.
  * @throws InvalidArgumentException Where the buffer is already attached to a different printer.
  */
 public function setPrintBuffer(PrintBuffer $buffer)
 {
     if ($buffer === $this->buffer) {
         return;
     }
     if ($buffer->getPrinter() != null) {
         throw new InvalidArgumentException("This buffer is already attached to a printer.");
     }
     if ($this->buffer !== null) {
         $this->buffer->setPrinter(null);
     }
     $this->buffer = $buffer;
     $this->buffer->setPrinter($this);
 }