1 | <?php |
||
29 | class JobService { |
||
30 | |||
31 | /** |
||
32 | * |
||
33 | * @var ILogger |
||
34 | */ |
||
35 | private $logger; |
||
36 | |||
37 | /** |
||
38 | * |
||
39 | * @var RedisService |
||
40 | */ |
||
41 | private $redisService; |
||
42 | |||
43 | /** |
||
44 | * |
||
45 | * @var OcrJobMapper |
||
46 | */ |
||
47 | private $jobMapper; |
||
48 | |||
49 | /** |
||
50 | * |
||
51 | * @var View |
||
52 | */ |
||
53 | private $view; |
||
54 | |||
55 | /** |
||
56 | * |
||
57 | * @var String |
||
58 | */ |
||
59 | private $userId; |
||
60 | |||
61 | /** |
||
62 | * |
||
63 | * @var IL10N |
||
64 | */ |
||
65 | private $l10n; |
||
66 | |||
67 | /** |
||
68 | * |
||
69 | * @var FileService |
||
70 | */ |
||
71 | private $fileService; |
||
72 | |||
73 | /** |
||
74 | * |
||
75 | * @var ITempManager |
||
76 | */ |
||
77 | private $tempM; |
||
78 | |||
79 | /** |
||
80 | * |
||
81 | * @var AppConfigService |
||
82 | */ |
||
83 | private $appConfigService; |
||
84 | |||
85 | /** |
||
86 | * |
||
87 | * @var PHPUtil |
||
88 | */ |
||
89 | private $phpUtil; |
||
90 | |||
91 | /** |
||
92 | * JobService constructor. |
||
93 | * |
||
94 | * @param IL10N $l10n |
||
95 | * @param ILogger $logger |
||
96 | * @param string $userId |
||
97 | * @param View $view |
||
98 | * @param RedisService $queueService |
||
99 | * @param OcrJobMapper $mapper |
||
100 | * @param FileService $fileService |
||
101 | * @param AppConfigService $appConfigService |
||
102 | * @param PHPUtil $phpUtil |
||
103 | */ |
||
104 | 4 | public function __construct(IL10N $l10n, ILogger $logger, $userId, View $view, ITempManager $tempManager, RedisService $queueService, OcrJobMapper $mapper, FileService $fileService, AppConfigService $appConfigService, PHPUtil $phpUtil) { |
|
116 | |||
117 | /** |
||
118 | * Processes and prepares the files for OCR. |
||
119 | * Sends the stuff to the client in order to OCR async. |
||
120 | * |
||
121 | * @param string[] $languages |
||
122 | * @param array $files |
||
123 | * @return string |
||
124 | */ |
||
125 | public function process($languages, $files) { |
||
167 | |||
168 | /** |
||
169 | * Delete an ocr job for a given id and userId. |
||
170 | * |
||
171 | * @param |
||
172 | * $jobId |
||
173 | * @param string $userId |
||
174 | * @return OcrJob |
||
175 | */ |
||
176 | public function deleteJob($jobId, $userId) { |
||
201 | |||
202 | /** |
||
203 | * Gets all job objects for a specific user. |
||
204 | * |
||
205 | * @param string $userId |
||
206 | * @return array |
||
207 | */ |
||
208 | public function getAllJobsForUser($userId) { |
||
227 | |||
228 | /** |
||
229 | * The function checks if there are finished jobs to process finally. |
||
230 | * @throws NotFoundException |
||
231 | */ |
||
232 | public function checkForFinishedJobs() { |
||
244 | |||
245 | /** |
||
246 | * The function the worker will call in order to set the jobs status. |
||
247 | * The worker should call it automatically after each processing step. |
||
248 | * |
||
249 | * @param integer $jobId |
||
250 | * @param boolean $error |
||
251 | * @param string $log |
||
252 | */ |
||
253 | public function jobFinished($jobId, $error, $log) { |
||
269 | |||
270 | /** |
||
271 | * Finishes all Processed files by copying them to the right path and deleteing the temp files. |
||
272 | * Returns the number of processed files. |
||
273 | * |
||
274 | * @return array |
||
275 | */ |
||
276 | public function handleProcessed() { |
||
298 | |||
299 | /** |
||
300 | * Handles all failed orders of ocr processing queue and returns the job objects. |
||
301 | * |
||
302 | * @return array |
||
303 | */ |
||
304 | public function handleFailed() { |
||
322 | |||
323 | /** |
||
324 | * Gives a temp file name back depending on the type of the OCR. |
||
325 | * Later in the worker this file is used as an output. |
||
326 | * |
||
327 | * @param integer $type |
||
328 | * @return string |
||
329 | */ |
||
330 | private function getTempFile($type) { |
||
342 | |||
343 | /** |
||
344 | * Takes care of transforming an incoming finished job into a php readable object. |
||
345 | * |
||
346 | * @param string $job |
||
347 | * @throws NotFoundException |
||
348 | * @return mixed |
||
349 | */ |
||
350 | private function transformJob($job) { |
||
358 | |||
359 | /** |
||
360 | * Checks if the given languages are supported or not. |
||
361 | * |
||
362 | * @param string[] $languages |
||
363 | * @return boolean |
||
364 | */ |
||
365 | private function checkForAcceptedLanguages($languages) { |
||
373 | |||
374 | /** |
||
375 | * Checks if the process should be initiated without any language specified. |
||
376 | * |
||
377 | * @param string[] $languages |
||
378 | * @return boolean |
||
379 | */ |
||
380 | private function noLanguage($languages) { |
||
387 | |||
388 | /** |
||
389 | * Handle the possible thrown Exceptions from all methods of this class. |
||
390 | * |
||
391 | * @param Exception $e |
||
392 | * @throws Exception |
||
393 | * @throws NotFoundException |
||
394 | */ |
||
395 | private function handleException($e) { |
||
401 | } |
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.