/** * @param $name * @param $device * @param null $driver * @return bool * @throws InvalidPrinterDeviceException * @throws PrinterConfigurationFailed * @throws ExecutableNotFoundException * @throws InvalidPrinterDeviceException * @throws InvalidPrinterDriverException */ public function configure($name, $device, $driver = null) { try { $arguments = [$this->manager->getLpadminBinary(), '-p', $name, '-v', $device, '-E']; if ($driver) { $arguments = array_merge($arguments, ['-P', $driver]); } // in theory we don't need to check process output if it's succedded ProcessUtil::instance()->executeCommand($arguments); return true; } catch (ProcessFailedException $e) { $output = $e->getProcess()->getErrorOutput(); if (false !== strpos($output, 'lpadmin: Bad device-uri')) { throw new InvalidPrinterDeviceException(sprintf('"%s" is not valid device uri.', $device), 0, $e); } elseif (false !== strpos($output, 'Unable to open PPD')) { throw new InvalidPrinterDriverException(sprintf('"%s" is not valid driver.', $driver), 0, $e); } throw new PrinterConfigurationFailed('Printer configuration failed.', 0, $e); } }