1 | <?php |
||
30 | class JobService { |
||
31 | |||
32 | /** |
||
33 | * |
||
34 | * @var ILogger |
||
35 | */ |
||
36 | private $logger; |
||
37 | |||
38 | /** |
||
39 | * |
||
40 | * @var RedisService |
||
41 | */ |
||
42 | private $redisService; |
||
43 | |||
44 | /** |
||
45 | * |
||
46 | * @var OcrJobMapper |
||
47 | */ |
||
48 | private $jobMapper; |
||
49 | |||
50 | /** |
||
51 | * |
||
52 | * @var View |
||
53 | */ |
||
54 | private $view; |
||
55 | |||
56 | /** |
||
57 | * |
||
58 | * @var String |
||
59 | */ |
||
60 | private $userId; |
||
61 | |||
62 | /** |
||
63 | * |
||
64 | * @var IL10N |
||
65 | */ |
||
66 | private $l10n; |
||
67 | |||
68 | /** |
||
69 | * |
||
70 | * @var FileService |
||
71 | */ |
||
72 | private $fileService; |
||
73 | |||
74 | /** |
||
75 | * |
||
76 | * @var ITempManager |
||
77 | */ |
||
78 | private $tempM; |
||
79 | |||
80 | /** |
||
81 | * |
||
82 | * @var AppConfigService |
||
83 | */ |
||
84 | private $appConfigService; |
||
85 | |||
86 | /** |
||
87 | * |
||
88 | * @var PHPUtil |
||
89 | */ |
||
90 | private $phpUtil; |
||
91 | |||
92 | /** |
||
93 | * JobService constructor. |
||
94 | * |
||
95 | * @param IL10N $l10n |
||
96 | * @param ILogger $logger |
||
97 | * @param string $userId |
||
98 | * @param View $view |
||
99 | * @param RedisService $queueService |
||
100 | * @param OcrJobMapper $mapper |
||
101 | * @param FileService $fileService |
||
102 | * @param AppConfigService $appConfigService |
||
103 | * @param PHPUtil $phpUtil |
||
104 | */ |
||
105 | 4 | public function __construct(IL10N $l10n, ILogger $logger, $userId, View $view, ITempManager $tempManager, |
|
119 | |||
120 | /** |
||
121 | * Processes and prepares the files for OCR. |
||
122 | * Sends the stuff to the client in order to OCR async. |
||
123 | * |
||
124 | * @param string[] $languages |
||
125 | * @param array $files |
||
126 | * @return string |
||
127 | */ |
||
128 | public function process($languages, $files) { |
||
168 | |||
169 | /** |
||
170 | * Delete an ocr job for a given id and userId. |
||
171 | * |
||
172 | * @param |
||
173 | * $jobId |
||
174 | * @param string $userId |
||
175 | * @return OcrJob |
||
176 | */ |
||
177 | public function deleteJob($jobId, $userId) { |
||
202 | |||
203 | /** |
||
204 | * Gets all job objects for a specific user. |
||
205 | * |
||
206 | * @param string $userId |
||
207 | * @return array |
||
208 | */ |
||
209 | public function getAllJobsForUser($userId) { |
||
227 | |||
228 | /** |
||
229 | * The function checks if there are finished jobs to process finally. |
||
230 | * |
||
231 | * @throws NotFoundException |
||
232 | */ |
||
233 | public function checkForFinishedJobs() { |
||
248 | |||
249 | /** |
||
250 | * The function the worker will call in order to set the jobs status. |
||
251 | * The worker should call it automatically after each processing step. |
||
252 | * |
||
253 | * @param integer $jobId |
||
254 | * @param boolean $error |
||
255 | * @param string $log |
||
256 | */ |
||
257 | public function jobFinished($jobId, $error, $log) { |
||
273 | |||
274 | /** |
||
275 | * Finishes all Processed files by copying them to the right path and deleteing the temp files. |
||
276 | * Returns the number of processed files. |
||
277 | * |
||
278 | * @return array |
||
279 | */ |
||
280 | public function handleProcessed() { |
||
303 | |||
304 | /** |
||
305 | * Handles all failed orders of ocr processing queue and returns the job objects. |
||
306 | * |
||
307 | * @return array |
||
308 | */ |
||
309 | public function handleFailed() { |
||
328 | |||
329 | /** |
||
330 | * Gives a temp file name back depending on the type of the OCR. |
||
331 | * Later in the worker this file is used as an output. |
||
332 | * |
||
333 | * @param integer $type |
||
334 | * @return string |
||
335 | */ |
||
336 | private function getTempFile($type) { |
||
348 | |||
349 | /** |
||
350 | * Takes care of transforming an incoming finished job into a php readable object. |
||
351 | * |
||
352 | * @param string $job |
||
353 | * @throws NotFoundException |
||
354 | * @return mixed |
||
355 | */ |
||
356 | private function transformJob($job) { |
||
364 | |||
365 | /** |
||
366 | * Checks if the given languages are supported or not. |
||
367 | * |
||
368 | * @param string[] $languages |
||
369 | * @return boolean |
||
370 | */ |
||
371 | private function checkForAcceptedLanguages($languages) { |
||
379 | |||
380 | /** |
||
381 | * Checks if the process should be initiated without any language specified. |
||
382 | * |
||
383 | * @param string[] $languages |
||
384 | * @return boolean |
||
385 | */ |
||
386 | private function noLanguage($languages) { |
||
393 | |||
394 | /** |
||
395 | * Handle the possible thrown Exceptions from all methods of this class. |
||
396 | * |
||
397 | * @param Exception $e |
||
398 | * @throws Exception |
||
399 | * @throws NotFoundException |
||
400 | */ |
||
401 | private function handleException($e) { |
||
408 | } |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.