1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Entity\Device; |
6
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
7
|
|
|
use ControleOnline\Entity\Spool; |
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
9
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface |
|
|
|
|
10
|
|
|
as Security; |
11
|
|
|
|
12
|
|
|
class PrintService |
13
|
|
|
{ |
14
|
|
|
private $initialSpace = 8; |
15
|
|
|
private $totalChars = 48; |
16
|
|
|
private $text = ''; |
17
|
|
|
|
18
|
|
|
public function __construct( |
19
|
|
|
private EntityManagerInterface $entityManager, |
20
|
|
|
private FileService $fileService, |
21
|
|
|
private StatusService $statusService, |
22
|
|
|
private DeviceService $deviceService, |
23
|
|
|
private Security $security |
24
|
|
|
) {} |
25
|
|
|
|
26
|
|
|
public function addLine($prefix = '', $suffix = '', $delimiter = ' ') |
27
|
|
|
{ |
28
|
|
|
$initialSpace = str_repeat(" ", $this->initialSpace); |
29
|
|
|
$count = $this->totalChars - $this->initialSpace - strlen($prefix) - strlen($suffix); |
30
|
|
|
if ($count > 0) |
31
|
|
|
$delimiter = str_repeat($delimiter, $count); |
32
|
|
|
$this->text .= $initialSpace . $prefix . $delimiter . $suffix . "\n"; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function makePrintDone(Spool $spool): Spool |
36
|
|
|
{ |
37
|
|
|
$status = $this->statusService->discoveryStatus('closed', 'done', 'print'); |
38
|
|
|
$spool->setStatus($status); |
39
|
|
|
$this->entityManager->persist($spool); |
40
|
|
|
$this->entityManager->flush(); |
41
|
|
|
return $spool; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function generatePrintData(Device $device, People $provider): Spool |
45
|
|
|
{ |
46
|
|
|
$printer = null; |
47
|
|
|
$device_config = $this->deviceService->discoveryDeviceConfig($device, $provider); |
48
|
|
|
if (isset($device_config['printer'])) |
49
|
|
|
$printer = $this->deviceService->discoveryDevice($device_config['printer']); |
50
|
|
|
|
51
|
|
|
$content = [ |
52
|
|
|
"operation" => "PRINT_TEXT", |
53
|
|
|
"styles" => [[]], |
54
|
|
|
"value" => [$this->text] |
55
|
|
|
]; |
56
|
|
|
|
57
|
|
|
$printData = $this->addToSpool($printer ?? $device, json_encode($content)); |
58
|
|
|
|
59
|
|
|
if ($printer != $device) |
60
|
|
|
$x = ''; |
|
|
|
|
61
|
|
|
|
62
|
|
|
return $printData; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function addToSpool(Device $printer, string $content): Spool |
66
|
|
|
{ |
67
|
|
|
$user = $this->security->getToken()->getUser(); |
68
|
|
|
$status = $this->statusService->discoveryStatus('open', 'open', 'print'); |
69
|
|
|
$file = $this->fileService->addFile($user->getPeople(), $content, 'print', 'print', 'text', 'txt'); |
70
|
|
|
|
71
|
|
|
$spool = new Spool(); |
72
|
|
|
$spool->setDevice($printer); |
73
|
|
|
$spool->setStatus($status); |
74
|
|
|
$spool->setFile($file); |
75
|
|
|
$spool->setUser($user); |
76
|
|
|
$this->entityManager->persist($spool); |
77
|
|
|
$this->entityManager->flush(); |
78
|
|
|
|
79
|
|
|
return $spool; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths