@@ -51,7 +51,7 @@ |
||
51 | 51 | |
52 | 52 | $jobs = array_filter( |
53 | 53 | $jobs, |
54 | - function ($job) use ($now) { |
|
54 | + function($job) use ($now) { |
|
55 | 55 | return $job->isDue($now); |
56 | 56 | } |
57 | 57 | ); |
@@ -4,129 +4,129 @@ |
||
4 | 4 | |
5 | 5 | class Manager |
6 | 6 | { |
7 | - /** |
|
8 | - * @var array |
|
9 | - */ |
|
10 | - protected $jobs = []; |
|
7 | + /** |
|
8 | + * @var array |
|
9 | + */ |
|
10 | + protected $jobs = []; |
|
11 | 11 | |
12 | - /** |
|
13 | - * For background jobs. |
|
14 | - * |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $processes = []; |
|
12 | + /** |
|
13 | + * For background jobs. |
|
14 | + * |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $processes = []; |
|
18 | 18 | |
19 | 19 | |
20 | 20 | |
21 | - public function add(Job $job) |
|
22 | - { |
|
23 | - $this->jobs[] = $job; |
|
24 | - } |
|
21 | + public function add(Job $job) |
|
22 | + { |
|
23 | + $this->jobs[] = $job; |
|
24 | + } |
|
25 | 25 | |
26 | - public function addCrontab(string $filename) |
|
27 | - { |
|
28 | - $crontab = new CrontabParser($filename); |
|
26 | + public function addCrontab(string $filename) |
|
27 | + { |
|
28 | + $crontab = new CrontabParser($filename); |
|
29 | 29 | |
30 | - $jobs = $crontab->getJobs(); |
|
30 | + $jobs = $crontab->getJobs(); |
|
31 | 31 | |
32 | - foreach ($jobs as $job) { |
|
33 | - $this->add($job); |
|
34 | - } |
|
35 | - } |
|
32 | + foreach ($jobs as $job) { |
|
33 | + $this->add($job); |
|
34 | + } |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @param \DateTime|string $now |
|
41 | - */ |
|
42 | - public function getDueJobs($now = null) : array |
|
43 | - { |
|
44 | - $jobs = $this->jobs; |
|
39 | + /** |
|
40 | + * @param \DateTime|string $now |
|
41 | + */ |
|
42 | + public function getDueJobs($now = null) : array |
|
43 | + { |
|
44 | + $jobs = $this->jobs; |
|
45 | 45 | |
46 | - $jobs = array_filter( |
|
47 | - $jobs, |
|
48 | - function ($job) use ($now) { |
|
49 | - return $job->isDue($now); |
|
50 | - } |
|
51 | - ); |
|
46 | + $jobs = array_filter( |
|
47 | + $jobs, |
|
48 | + function ($job) use ($now) { |
|
49 | + return $job->isDue($now); |
|
50 | + } |
|
51 | + ); |
|
52 | 52 | |
53 | - return $jobs; |
|
54 | - } |
|
53 | + return $jobs; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | - public function getAllJobs() : array |
|
59 | - { |
|
60 | - return $this->jobs; |
|
61 | - } |
|
58 | + public function getAllJobs() : array |
|
59 | + { |
|
60 | + return $this->jobs; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * Run all due jobs in the foreground. |
|
67 | - * |
|
68 | - * @param \DateTime|string $now |
|
69 | - */ |
|
70 | - public function runInForeground($now = null) : array |
|
71 | - { |
|
72 | - $jobs = $this->getDueJobs($now); |
|
65 | + /** |
|
66 | + * Run all due jobs in the foreground. |
|
67 | + * |
|
68 | + * @param \DateTime|string $now |
|
69 | + */ |
|
70 | + public function runInForeground($now = null) : array |
|
71 | + { |
|
72 | + $jobs = $this->getDueJobs($now); |
|
73 | 73 | |
74 | - $outputs = []; |
|
74 | + $outputs = []; |
|
75 | 75 | |
76 | - foreach ($jobs as $job) { |
|
77 | - $outputs[] = $job->runInForeground(); |
|
78 | - } |
|
76 | + foreach ($jobs as $job) { |
|
77 | + $outputs[] = $job->runInForeground(); |
|
78 | + } |
|
79 | 79 | |
80 | - return $outputs; |
|
81 | - } |
|
80 | + return $outputs; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Run all due jobs in the background. |
|
85 | - * |
|
86 | - * @param \DateTime|string $now |
|
87 | - */ |
|
88 | - public function runInBackground($now = null) : array |
|
89 | - { |
|
90 | - $jobs = $this->getDueJobs($now); |
|
83 | + /** |
|
84 | + * Run all due jobs in the background. |
|
85 | + * |
|
86 | + * @param \DateTime|string $now |
|
87 | + */ |
|
88 | + public function runInBackground($now = null) : array |
|
89 | + { |
|
90 | + $jobs = $this->getDueJobs($now); |
|
91 | 91 | |
92 | - foreach ($jobs as $job) { |
|
93 | - $this->processes[] = $job->runInBackground(); |
|
94 | - } |
|
92 | + foreach ($jobs as $job) { |
|
93 | + $this->processes[] = $job->runInBackground(); |
|
94 | + } |
|
95 | 95 | |
96 | - return $this->processes; |
|
97 | - } |
|
96 | + return $this->processes; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | 100 | |
101 | - /** |
|
102 | - * Wait for all jobs running in the background to finish. |
|
103 | - */ |
|
104 | - public function wait() |
|
105 | - { |
|
106 | - foreach ($this->processes as $process) { |
|
107 | - $process->wait(); |
|
108 | - } |
|
109 | - } |
|
101 | + /** |
|
102 | + * Wait for all jobs running in the background to finish. |
|
103 | + */ |
|
104 | + public function wait() |
|
105 | + { |
|
106 | + foreach ($this->processes as $process) { |
|
107 | + $process->wait(); |
|
108 | + } |
|
109 | + } |
|
110 | 110 | |
111 | 111 | |
112 | 112 | |
113 | - /** |
|
114 | - * Terminate all jobs running in the background. |
|
115 | - */ |
|
116 | - public function terminate() |
|
117 | - { |
|
118 | - foreach ($this->processes as $process) { |
|
119 | - $process->terminate(); |
|
120 | - } |
|
121 | - } |
|
113 | + /** |
|
114 | + * Terminate all jobs running in the background. |
|
115 | + */ |
|
116 | + public function terminate() |
|
117 | + { |
|
118 | + foreach ($this->processes as $process) { |
|
119 | + $process->terminate(); |
|
120 | + } |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Kill all jobs running in the background. |
|
125 | - */ |
|
126 | - public function kill() |
|
127 | - { |
|
128 | - foreach ($this->processes as $process) { |
|
129 | - $process->kill(); |
|
130 | - } |
|
131 | - } |
|
123 | + /** |
|
124 | + * Kill all jobs running in the background. |
|
125 | + */ |
|
126 | + public function kill() |
|
127 | + { |
|
128 | + foreach ($this->processes as $process) { |
|
129 | + $process->kill(); |
|
130 | + } |
|
131 | + } |
|
132 | 132 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | $command = $this->getCommand(); |
58 | 58 | |
59 | 59 | if ($this->getOutput()) { |
60 | - $command .= ' > ' . $this->getOutput() . ' 2>&1'; |
|
60 | + $command .= ' > '.$this->getOutput().' 2>&1'; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | return $command; |
@@ -6,63 +6,63 @@ |
||
6 | 6 | |
7 | 7 | class System extends Job |
8 | 8 | { |
9 | - /** |
|
10 | - * @var string |
|
11 | - */ |
|
12 | - protected $command; |
|
9 | + /** |
|
10 | + * @var string |
|
11 | + */ |
|
12 | + protected $command; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $output; |
|
14 | + /** |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $output; |
|
18 | 18 | |
19 | 19 | |
20 | 20 | |
21 | - public function __construct(string $expression, string $command, string $output = null) |
|
22 | - { |
|
23 | - parent::__construct($expression); |
|
21 | + public function __construct(string $expression, string $command, string $output = null) |
|
22 | + { |
|
23 | + parent::__construct($expression); |
|
24 | 24 | |
25 | - $this->command = $command; |
|
26 | - $this->output = $output; |
|
27 | - } |
|
25 | + $this->command = $command; |
|
26 | + $this->output = $output; |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | 30 | |
31 | - public function getCommand() : string |
|
32 | - { |
|
33 | - return $this->command; |
|
34 | - } |
|
31 | + public function getCommand() : string |
|
32 | + { |
|
33 | + return $this->command; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function getOutput() |
|
40 | - { |
|
41 | - return $this->output; |
|
42 | - } |
|
36 | + /** |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function getOutput() |
|
40 | + { |
|
41 | + return $this->output; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | 45 | |
46 | - private function buildCommand() : string |
|
47 | - { |
|
48 | - $command = $this->getCommand(); |
|
46 | + private function buildCommand() : string |
|
47 | + { |
|
48 | + $command = $this->getCommand(); |
|
49 | 49 | |
50 | - if ($this->getOutput()) { |
|
51 | - $command .= ' > ' . $this->getOutput() . ' 2>&1'; |
|
52 | - } |
|
50 | + if ($this->getOutput()) { |
|
51 | + $command .= ' > ' . $this->getOutput() . ' 2>&1'; |
|
52 | + } |
|
53 | 53 | |
54 | - return $command; |
|
55 | - } |
|
54 | + return $command; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function runInForeground() |
|
63 | - { |
|
64 | - return shell_exec( |
|
65 | - $this->buildCommand() |
|
66 | - ); |
|
67 | - } |
|
59 | + /** |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function runInForeground() |
|
63 | + { |
|
64 | + return shell_exec( |
|
65 | + $this->buildCommand() |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | } |
@@ -9,86 +9,86 @@ |
||
9 | 9 | */ |
10 | 10 | class Process |
11 | 11 | { |
12 | - /** |
|
13 | - * @var int |
|
14 | - */ |
|
15 | - protected $processID; |
|
12 | + /** |
|
13 | + * @var int |
|
14 | + */ |
|
15 | + protected $processID; |
|
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | - public function __construct(int $processID) |
|
20 | - { |
|
21 | - $this->processID = $processID; |
|
19 | + public function __construct(int $processID) |
|
20 | + { |
|
21 | + $this->processID = $processID; |
|
22 | 22 | |
23 | 23 | |
24 | 24 | |
25 | - register_shutdown_function( |
|
26 | - [ |
|
27 | - $this, |
|
28 | - "wait", |
|
29 | - ] |
|
30 | - ); |
|
31 | - } |
|
25 | + register_shutdown_function( |
|
26 | + [ |
|
27 | + $this, |
|
28 | + "wait", |
|
29 | + ] |
|
30 | + ); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | 34 | |
35 | - public function getProcessID() : int |
|
36 | - { |
|
37 | - return $this->processID; |
|
38 | - } |
|
35 | + public function getProcessID() : int |
|
36 | + { |
|
37 | + return $this->processID; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Determine if this process is currently running. Defunct/zombie processes |
|
44 | - * are ignored. |
|
45 | - */ |
|
46 | - public function isRunning() : bool |
|
47 | - { |
|
48 | - $result = shell_exec( |
|
49 | - sprintf( |
|
50 | - "ps %d | grep -v '<defunct>'", |
|
51 | - $this->getProcessID() |
|
52 | - ) |
|
53 | - ); |
|
42 | + /** |
|
43 | + * Determine if this process is currently running. Defunct/zombie processes |
|
44 | + * are ignored. |
|
45 | + */ |
|
46 | + public function isRunning() : bool |
|
47 | + { |
|
48 | + $result = shell_exec( |
|
49 | + sprintf( |
|
50 | + "ps %d | grep -v '<defunct>'", |
|
51 | + $this->getProcessID() |
|
52 | + ) |
|
53 | + ); |
|
54 | 54 | |
55 | - return (count(preg_split("/\n/", $result)) > 2); |
|
56 | - } |
|
55 | + return (count(preg_split("/\n/", $result)) > 2); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Wait for the process to finish. |
|
62 | - */ |
|
63 | - public function wait() |
|
64 | - { |
|
65 | - pcntl_waitpid( |
|
66 | - $this->getProcessID(), |
|
67 | - $status |
|
68 | - ); |
|
69 | - } |
|
60 | + /** |
|
61 | + * Wait for the process to finish. |
|
62 | + */ |
|
63 | + public function wait() |
|
64 | + { |
|
65 | + pcntl_waitpid( |
|
66 | + $this->getProcessID(), |
|
67 | + $status |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * Terminate the process. |
|
75 | - */ |
|
76 | - public function terminate() : bool |
|
77 | - { |
|
78 | - return posix_kill( |
|
79 | - $this->getProcessID(), |
|
80 | - SIGTERM |
|
81 | - ); |
|
82 | - } |
|
73 | + /** |
|
74 | + * Terminate the process. |
|
75 | + */ |
|
76 | + public function terminate() : bool |
|
77 | + { |
|
78 | + return posix_kill( |
|
79 | + $this->getProcessID(), |
|
80 | + SIGTERM |
|
81 | + ); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Kill the process. |
|
86 | - */ |
|
87 | - public function kill() : bool |
|
88 | - { |
|
89 | - return posix_kill( |
|
90 | - $this->getProcessID(), |
|
91 | - SIGKILL |
|
92 | - ); |
|
93 | - } |
|
84 | + /** |
|
85 | + * Kill the process. |
|
86 | + */ |
|
87 | + public function kill() : bool |
|
88 | + { |
|
89 | + return posix_kill( |
|
90 | + $this->getProcessID(), |
|
91 | + SIGKILL |
|
92 | + ); |
|
93 | + } |
|
94 | 94 | } |
@@ -7,70 +7,70 @@ |
||
7 | 7 | |
8 | 8 | abstract class Job extends Injectable |
9 | 9 | { |
10 | - /** |
|
11 | - * @var string |
|
12 | - */ |
|
13 | - protected $expression; |
|
10 | + /** |
|
11 | + * @var string |
|
12 | + */ |
|
13 | + protected $expression; |
|
14 | 14 | |
15 | 15 | |
16 | 16 | |
17 | - public function __construct(string $expression) |
|
18 | - { |
|
19 | - $this->expression = $expression; |
|
20 | - } |
|
17 | + public function __construct(string $expression) |
|
18 | + { |
|
19 | + $this->expression = $expression; |
|
20 | + } |
|
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - public function getExpression() : string |
|
25 | - { |
|
26 | - return $this->expression; |
|
27 | - } |
|
24 | + public function getExpression() : string |
|
25 | + { |
|
26 | + return $this->expression; |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @param \DateTime|string $datetime |
|
33 | - */ |
|
34 | - public function isDue($datetime = "now") : bool |
|
35 | - { |
|
36 | - $cronExpression = CronExpression::factory( |
|
37 | - $this->getExpression() |
|
38 | - ); |
|
31 | + /** |
|
32 | + * @param \DateTime|string $datetime |
|
33 | + */ |
|
34 | + public function isDue($datetime = "now") : bool |
|
35 | + { |
|
36 | + $cronExpression = CronExpression::factory( |
|
37 | + $this->getExpression() |
|
38 | + ); |
|
39 | 39 | |
40 | - return $cronExpression->isDue($datetime); |
|
41 | - } |
|
40 | + return $cronExpression->isDue($datetime); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @return mixed |
|
47 | - */ |
|
48 | - abstract public function runInForeground(); |
|
45 | + /** |
|
46 | + * @return mixed |
|
47 | + */ |
|
48 | + abstract public function runInForeground(); |
|
49 | 49 | |
50 | - /** |
|
51 | - * @throws Exception |
|
52 | - */ |
|
53 | - public function runInBackground() : Process |
|
54 | - { |
|
55 | - $processID = pcntl_fork(); |
|
50 | + /** |
|
51 | + * @throws Exception |
|
52 | + */ |
|
53 | + public function runInBackground() : Process |
|
54 | + { |
|
55 | + $processID = pcntl_fork(); |
|
56 | 56 | |
57 | - if ($processID == -1) { |
|
58 | - throw new Exception( |
|
59 | - "Failed to fork process." |
|
60 | - ); |
|
61 | - } |
|
57 | + if ($processID == -1) { |
|
58 | + throw new Exception( |
|
59 | + "Failed to fork process." |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | - // This is the child process. |
|
64 | - if ($processID == 0) { |
|
65 | - // @codeCoverageIgnoreStart |
|
66 | - $this->runInForeground(); |
|
63 | + // This is the child process. |
|
64 | + if ($processID == 0) { |
|
65 | + // @codeCoverageIgnoreStart |
|
66 | + $this->runInForeground(); |
|
67 | 67 | |
68 | - exit(0); |
|
69 | - // @codeCoverageIgnoreEnd |
|
70 | - } |
|
68 | + exit(0); |
|
69 | + // @codeCoverageIgnoreEnd |
|
70 | + } |
|
71 | 71 | |
72 | - $process = new Process($processID); |
|
72 | + $process = new Process($processID); |
|
73 | 73 | |
74 | - return $process; |
|
75 | - } |
|
74 | + return $process; |
|
75 | + } |
|
76 | 76 | } |
@@ -6,36 +6,36 @@ |
||
6 | 6 | |
7 | 7 | class Callback extends Job |
8 | 8 | { |
9 | - /** |
|
10 | - * @var callable |
|
11 | - */ |
|
12 | - protected $callback; |
|
9 | + /** |
|
10 | + * @var callable |
|
11 | + */ |
|
12 | + protected $callback; |
|
13 | 13 | |
14 | 14 | |
15 | 15 | |
16 | - public function __construct(string $expression, callable $callback) |
|
17 | - { |
|
18 | - parent::__construct($expression); |
|
16 | + public function __construct(string $expression, callable $callback) |
|
17 | + { |
|
18 | + parent::__construct($expression); |
|
19 | 19 | |
20 | - $this->callback = $callback; |
|
21 | - } |
|
20 | + $this->callback = $callback; |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | 24 | |
25 | - public function getCallback() : callable |
|
26 | - { |
|
27 | - return $this->callback; |
|
28 | - } |
|
25 | + public function getCallback() : callable |
|
26 | + { |
|
27 | + return $this->callback; |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @return mixed |
|
34 | - */ |
|
35 | - public function runInForeground() |
|
36 | - { |
|
37 | - $contents = call_user_func($this->callback); |
|
32 | + /** |
|
33 | + * @return mixed |
|
34 | + */ |
|
35 | + public function runInForeground() |
|
36 | + { |
|
37 | + $contents = call_user_func($this->callback); |
|
38 | 38 | |
39 | - return $contents; |
|
40 | - } |
|
39 | + return $contents; |
|
40 | + } |
|
41 | 41 | } |
@@ -7,60 +7,60 @@ |
||
7 | 7 | |
8 | 8 | class Phalcon extends Job |
9 | 9 | { |
10 | - /** |
|
11 | - * @var array|null |
|
12 | - */ |
|
13 | - protected $body; |
|
10 | + /** |
|
11 | + * @var array|null |
|
12 | + */ |
|
13 | + protected $body; |
|
14 | 14 | |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @param array|null $body |
|
19 | - * |
|
20 | - * @throws Exception |
|
21 | - */ |
|
22 | - public function __construct(string $expression, $body = null) |
|
23 | - { |
|
24 | - $di = $this->getDI(); |
|
25 | - if (!($di instanceof DiInterface)) { |
|
26 | - throw new Exception( |
|
27 | - "A dependency injection object is required to access internal services" |
|
28 | - ); |
|
29 | - } |
|
17 | + /** |
|
18 | + * @param array|null $body |
|
19 | + * |
|
20 | + * @throws Exception |
|
21 | + */ |
|
22 | + public function __construct(string $expression, $body = null) |
|
23 | + { |
|
24 | + $di = $this->getDI(); |
|
25 | + if (!($di instanceof DiInterface)) { |
|
26 | + throw new Exception( |
|
27 | + "A dependency injection object is required to access internal services" |
|
28 | + ); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - parent::__construct($expression); |
|
33 | + parent::__construct($expression); |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - $this->body = $body; |
|
38 | - } |
|
37 | + $this->body = $body; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * @return array|null |
|
44 | - */ |
|
45 | - public function getBody() |
|
46 | - { |
|
47 | - return $this->body; |
|
48 | - } |
|
42 | + /** |
|
43 | + * @return array|null |
|
44 | + */ |
|
45 | + public function getBody() |
|
46 | + { |
|
47 | + return $this->body; |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | - public function runInForeground() : string |
|
53 | - { |
|
54 | - ob_start(); |
|
52 | + public function runInForeground() : string |
|
53 | + { |
|
54 | + ob_start(); |
|
55 | 55 | |
56 | - $this->getDI()->get("console")->handle( |
|
57 | - $this->getBody() |
|
58 | - ); |
|
56 | + $this->getDI()->get("console")->handle( |
|
57 | + $this->getBody() |
|
58 | + ); |
|
59 | 59 | |
60 | - $contents = ob_get_contents(); |
|
60 | + $contents = ob_get_contents(); |
|
61 | 61 | |
62 | - ob_end_clean(); |
|
62 | + ob_end_clean(); |
|
63 | 63 | |
64 | - return $contents; |
|
65 | - } |
|
64 | + return $contents; |
|
65 | + } |
|
66 | 66 | } |
@@ -6,46 +6,46 @@ |
||
6 | 6 | |
7 | 7 | class CrontabParser |
8 | 8 | { |
9 | - /** |
|
10 | - * @var string |
|
11 | - */ |
|
12 | - protected $filename; |
|
9 | + /** |
|
10 | + * @var string |
|
11 | + */ |
|
12 | + protected $filename; |
|
13 | 13 | |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * @throws Exception |
|
18 | - */ |
|
19 | - public function __construct(string $filename) |
|
20 | - { |
|
21 | - if (!file_exists($filename)) { |
|
22 | - throw new Exception( |
|
23 | - "Crontab file does not exist." |
|
24 | - ); |
|
25 | - } |
|
16 | + /** |
|
17 | + * @throws Exception |
|
18 | + */ |
|
19 | + public function __construct(string $filename) |
|
20 | + { |
|
21 | + if (!file_exists($filename)) { |
|
22 | + throw new Exception( |
|
23 | + "Crontab file does not exist." |
|
24 | + ); |
|
25 | + } |
|
26 | 26 | |
27 | - $this->filename = $filename; |
|
28 | - } |
|
27 | + $this->filename = $filename; |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - public function getJobs() : array |
|
33 | - { |
|
34 | - $contents = file_get_contents($this->filename); |
|
32 | + public function getJobs() : array |
|
33 | + { |
|
34 | + $contents = file_get_contents($this->filename); |
|
35 | 35 | |
36 | - $lines = explode(PHP_EOL, $contents); |
|
36 | + $lines = explode(PHP_EOL, $contents); |
|
37 | 37 | |
38 | - $jobs = []; |
|
38 | + $jobs = []; |
|
39 | 39 | |
40 | - foreach ($lines as $line) { |
|
41 | - if (preg_match("/^(\@\w+|[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+)\s+(.*)$/", $line, $matches)) { |
|
42 | - $jobs[] = new SystemJob( |
|
43 | - $matches[1], |
|
44 | - $matches[2] |
|
45 | - ); |
|
46 | - } |
|
47 | - } |
|
40 | + foreach ($lines as $line) { |
|
41 | + if (preg_match("/^(\@\w+|[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+)\s+(.*)$/", $line, $matches)) { |
|
42 | + $jobs[] = new SystemJob( |
|
43 | + $matches[1], |
|
44 | + $matches[2] |
|
45 | + ); |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - return $jobs; |
|
50 | - } |
|
49 | + return $jobs; |
|
50 | + } |
|
51 | 51 | } |