Exemplo n.º 1
0
 public function testGetPrinter()
 {
     $printerProfileMock = $this->getMock(PrinterProfileInterface::class);
     $printerProfileMock->expects($this->any())->method('getName')->willReturn(true);
     $manager = new Manager();
     $printer = $manager->getPrinter($printerProfileMock);
     $this->assertInstanceOf(CUPSPrinter::class, $printer);
     $this->assertEquals($printerProfileMock, $printer->getPrinterProfile());
 }
Exemplo n.º 2
0
 /**
  * @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);
     }
 }
Exemplo n.º 3
0
 /**
  * @param PrintableFileInterface $printable
  * @param PrinterProfileInterface $printerProfile
  * @return array
  */
 protected function getProcessArguments(PrintableInterface $printable, PrinterProfileInterface $printerProfile)
 {
     return array_merge([$this->manager->getLprBinary()], $this->getOptionArgumentsByPrinterProfile($printerProfile), ['-P', $printerProfile->getName()]);
 }