1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
* @package MW |
7
|
|
|
* @subpackage Process |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\MW\Process\Decorator; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Check avaiability of parallel processing |
16
|
|
|
* |
17
|
|
|
* If not available, execute the tasks one after another |
18
|
|
|
* |
19
|
|
|
* @package MW |
20
|
|
|
* @subpackage Process |
21
|
|
|
*/ |
22
|
|
|
class Check implements Iface |
23
|
|
|
{ |
24
|
|
|
private $object; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initializes the object |
29
|
|
|
* |
30
|
|
|
* @param Aimeos\MW\Process\Iface $object Parallel processing object |
|
|
|
|
31
|
|
|
*/ |
32
|
|
|
public function __construct( \Aimeos\MW\Process\Iface $object ) |
33
|
|
|
{ |
34
|
|
|
$this->object = $object; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Checks if processing tasks in parallel is available |
40
|
|
|
* |
41
|
|
|
* @return boolean True if available, false if not |
42
|
|
|
*/ |
43
|
|
|
public function isAvailable() |
44
|
|
|
{ |
45
|
|
|
return $this->object->isAvailable(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Starts a new task by executing the given anonymous function |
51
|
|
|
* |
52
|
|
|
* @param \Closure $fcn Anonymous function to execute |
53
|
|
|
* @param array $data List of parameters that is passed to the closure function |
54
|
|
|
* @param boolean $restart True if the task should be restarted if it fails (only once) |
55
|
|
|
* @return void |
|
|
|
|
56
|
|
|
* @throws \Aimeos\MW\Process\Exception If starting the new task failed |
57
|
|
|
*/ |
58
|
|
|
public function start( \Closure $fcn, array $data, $restart = false ) |
59
|
|
|
{ |
60
|
|
|
if( $this->object->isAvailable() === true ) { |
61
|
|
|
$this->object->start( $fcn, $data, $restart ); |
62
|
|
|
} else { |
63
|
|
|
call_user_func_array( $fcn, $data ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Waits for the running tasks until all have finished |
72
|
|
|
* |
73
|
|
|
* @return void |
|
|
|
|
74
|
|
|
*/ |
75
|
|
|
public function wait() |
76
|
|
|
{ |
77
|
|
|
if( $this->object->isAvailable() === true ) { |
78
|
|
|
$this->object->wait(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
} |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.