@@ -6,72 +6,72 @@ |
||
| 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 | - /** |
|
| 22 | - * @param string $expression |
|
| 23 | - * @param string $command |
|
| 24 | - * @param string $output |
|
| 25 | - */ |
|
| 26 | - public function __construct($expression, $command, $output = null) |
|
| 27 | - { |
|
| 28 | - parent::__construct($expression); |
|
| 21 | + /** |
|
| 22 | + * @param string $expression |
|
| 23 | + * @param string $command |
|
| 24 | + * @param string $output |
|
| 25 | + */ |
|
| 26 | + public function __construct($expression, $command, $output = null) |
|
| 27 | + { |
|
| 28 | + parent::__construct($expression); |
|
| 29 | 29 | |
| 30 | - $this->command = $command; |
|
| 31 | - $this->output = $output; |
|
| 32 | - } |
|
| 30 | + $this->command = $command; |
|
| 31 | + $this->output = $output; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - public function getCommand() |
|
| 40 | - { |
|
| 41 | - return $this->command; |
|
| 42 | - } |
|
| 36 | + /** |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + public function getCommand() |
|
| 40 | + { |
|
| 41 | + return $this->command; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function getOutput() |
|
| 48 | - { |
|
| 49 | - return $this->output; |
|
| 50 | - } |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function getOutput() |
|
| 48 | + { |
|
| 49 | + return $this->output; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - private function buildCommand() |
|
| 58 | - { |
|
| 59 | - $command = $this->getCommand(); |
|
| 54 | + /** |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + private function buildCommand() |
|
| 58 | + { |
|
| 59 | + $command = $this->getCommand(); |
|
| 60 | 60 | |
| 61 | - if ($this->getOutput()) { |
|
| 62 | - $command .= ' > ' . $this->getOutput() . ' 2>&1'; |
|
| 63 | - } |
|
| 61 | + if ($this->getOutput()) { |
|
| 62 | + $command .= ' > ' . $this->getOutput() . ' 2>&1'; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return $command; |
|
| 66 | - } |
|
| 65 | + return $command; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function runInForeground() |
|
| 74 | - { |
|
| 75 | - return shell_exec($this->buildCommand()); |
|
| 76 | - } |
|
| 70 | + /** |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function runInForeground() |
|
| 74 | + { |
|
| 75 | + return shell_exec($this->buildCommand()); |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -6,43 +6,43 @@ |
||
| 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 | - /** |
|
| 17 | - * @param string $expression |
|
| 18 | - * @param callable $callback |
|
| 19 | - */ |
|
| 20 | - public function __construct($expression, callable $callback) |
|
| 21 | - { |
|
| 22 | - parent::__construct($expression); |
|
| 16 | + /** |
|
| 17 | + * @param string $expression |
|
| 18 | + * @param callable $callback |
|
| 19 | + */ |
|
| 20 | + public function __construct($expression, callable $callback) |
|
| 21 | + { |
|
| 22 | + parent::__construct($expression); |
|
| 23 | 23 | |
| 24 | - $this->callback = $callback; |
|
| 25 | - } |
|
| 24 | + $this->callback = $callback; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return callable |
|
| 31 | - */ |
|
| 32 | - public function getCallback() |
|
| 33 | - { |
|
| 34 | - return $this->callback; |
|
| 35 | - } |
|
| 29 | + /** |
|
| 30 | + * @return callable |
|
| 31 | + */ |
|
| 32 | + public function getCallback() |
|
| 33 | + { |
|
| 34 | + return $this->callback; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return mixed |
|
| 41 | - */ |
|
| 42 | - public function runInForeground() |
|
| 43 | - { |
|
| 44 | - $contents = call_user_func($this->callback); |
|
| 39 | + /** |
|
| 40 | + * @return mixed |
|
| 41 | + */ |
|
| 42 | + public function runInForeground() |
|
| 43 | + { |
|
| 44 | + $contents = call_user_func($this->callback); |
|
| 45 | 45 | |
| 46 | - return $contents; |
|
| 47 | - } |
|
| 46 | + return $contents; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -7,62 +7,62 @@ |
||
| 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 string $expression |
|
| 19 | - * @param array|null $body |
|
| 20 | - * |
|
| 21 | - * @throws Exception |
|
| 22 | - */ |
|
| 23 | - public function __construct($expression, $body = null) |
|
| 24 | - { |
|
| 25 | - $di = $this->getDI(); |
|
| 26 | - if (!($di instanceof DiInterface)) { |
|
| 27 | - throw new Exception("A dependency injection object is required to access internal services"); |
|
| 28 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $expression |
|
| 19 | + * @param array|null $body |
|
| 20 | + * |
|
| 21 | + * @throws Exception |
|
| 22 | + */ |
|
| 23 | + public function __construct($expression, $body = null) |
|
| 24 | + { |
|
| 25 | + $di = $this->getDI(); |
|
| 26 | + if (!($di instanceof DiInterface)) { |
|
| 27 | + throw new Exception("A dependency injection object is required to access internal services"); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | |
| 32 | - parent::__construct($expression); |
|
| 32 | + parent::__construct($expression); |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | |
| 36 | - $this->body = $body; |
|
| 37 | - } |
|
| 36 | + $this->body = $body; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return array|null |
|
| 43 | - */ |
|
| 44 | - public function getBody() |
|
| 45 | - { |
|
| 46 | - return $this->body; |
|
| 47 | - } |
|
| 41 | + /** |
|
| 42 | + * @return array|null |
|
| 43 | + */ |
|
| 44 | + public function getBody() |
|
| 45 | + { |
|
| 46 | + return $this->body; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function runInForeground() |
|
| 55 | - { |
|
| 56 | - ob_start(); |
|
| 51 | + /** |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function runInForeground() |
|
| 55 | + { |
|
| 56 | + ob_start(); |
|
| 57 | 57 | |
| 58 | - $this->getDI()->get("console")->handle( |
|
| 59 | - $this->getBody() |
|
| 60 | - ); |
|
| 58 | + $this->getDI()->get("console")->handle( |
|
| 59 | + $this->getBody() |
|
| 60 | + ); |
|
| 61 | 61 | |
| 62 | - $contents = ob_get_contents(); |
|
| 62 | + $contents = ob_get_contents(); |
|
| 63 | 63 | |
| 64 | - ob_end_clean(); |
|
| 64 | + ob_end_clean(); |
|
| 65 | 65 | |
| 66 | - return $contents; |
|
| 67 | - } |
|
| 66 | + return $contents; |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -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 | - * @param string $filename |
|
| 18 | - * |
|
| 19 | - * @throws Exception |
|
| 20 | - */ |
|
| 21 | - public function __construct($filename) |
|
| 22 | - { |
|
| 23 | - if (!file_exists($filename)) { |
|
| 24 | - throw new Exception("Crontab file does not exist."); |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * @param string $filename |
|
| 18 | + * |
|
| 19 | + * @throws Exception |
|
| 20 | + */ |
|
| 21 | + public function __construct($filename) |
|
| 22 | + { |
|
| 23 | + if (!file_exists($filename)) { |
|
| 24 | + throw new Exception("Crontab file does not exist."); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - $this->filename = $filename; |
|
| 28 | - } |
|
| 27 | + $this->filename = $filename; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @return array |
|
| 34 | - */ |
|
| 35 | - public function getJobs() |
|
| 36 | - { |
|
| 37 | - $contents = file_get_contents($this->filename); |
|
| 32 | + /** |
|
| 33 | + * @return array |
|
| 34 | + */ |
|
| 35 | + public function getJobs() |
|
| 36 | + { |
|
| 37 | + $contents = file_get_contents($this->filename); |
|
| 38 | 38 | |
| 39 | - $lines = explode(PHP_EOL, $contents); |
|
| 39 | + $lines = explode(PHP_EOL, $contents); |
|
| 40 | 40 | |
| 41 | - $jobs = []; |
|
| 41 | + $jobs = []; |
|
| 42 | 42 | |
| 43 | - foreach ($lines as $line) { |
|
| 44 | - if (preg_match("/^(\@\w+|[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+)\s+(.*)$/", $line, $matches)) { |
|
| 45 | - $jobs[] = new SystemJob($matches[1], $matches[2]); |
|
| 46 | - } |
|
| 47 | - } |
|
| 43 | + foreach ($lines as $line) { |
|
| 44 | + if (preg_match("/^(\@\w+|[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+)\s+(.*)$/", $line, $matches)) { |
|
| 45 | + $jobs[] = new SystemJob($matches[1], $matches[2]); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return $jobs; |
|
| 50 | - } |
|
| 49 | + return $jobs; |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -7,74 +7,74 @@ |
||
| 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 | - /** |
|
| 18 | - * @param string $expression |
|
| 19 | - */ |
|
| 20 | - public function __construct($expression) |
|
| 21 | - { |
|
| 22 | - $this->expression = $expression; |
|
| 23 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $expression |
|
| 19 | + */ |
|
| 20 | + public function __construct($expression) |
|
| 21 | + { |
|
| 22 | + $this->expression = $expression; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function getExpression() |
|
| 31 | - { |
|
| 32 | - return $this->expression; |
|
| 33 | - } |
|
| 27 | + /** |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function getExpression() |
|
| 31 | + { |
|
| 32 | + return $this->expression; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param \DateTime|string $datetime |
|
| 39 | - * |
|
| 40 | - * @return boolean |
|
| 41 | - */ |
|
| 42 | - public function isDue($datetime = "now") |
|
| 43 | - { |
|
| 44 | - return CronExpression::factory($this->getExpression())->isDue($datetime); |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * @param \DateTime|string $datetime |
|
| 39 | + * |
|
| 40 | + * @return boolean |
|
| 41 | + */ |
|
| 42 | + public function isDue($datetime = "now") |
|
| 43 | + { |
|
| 44 | + return CronExpression::factory($this->getExpression())->isDue($datetime); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return mixed |
|
| 51 | - */ |
|
| 52 | - abstract public function runInForeground(); |
|
| 49 | + /** |
|
| 50 | + * @return mixed |
|
| 51 | + */ |
|
| 52 | + abstract public function runInForeground(); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return Process |
|
| 56 | - * |
|
| 57 | - * @throws Exception |
|
| 58 | - */ |
|
| 59 | - public function runInBackground() |
|
| 60 | - { |
|
| 61 | - $processID = pcntl_fork(); |
|
| 54 | + /** |
|
| 55 | + * @return Process |
|
| 56 | + * |
|
| 57 | + * @throws Exception |
|
| 58 | + */ |
|
| 59 | + public function runInBackground() |
|
| 60 | + { |
|
| 61 | + $processID = pcntl_fork(); |
|
| 62 | 62 | |
| 63 | - if ($processID == -1) { |
|
| 64 | - throw new Exception("Failed to fork process."); |
|
| 65 | - } |
|
| 63 | + if ($processID == -1) { |
|
| 64 | + throw new Exception("Failed to fork process."); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - // This is the child process. |
|
| 68 | - if ($processID == 0) { |
|
| 69 | - // @codeCoverageIgnoreStart |
|
| 70 | - $this->runInForeground(); |
|
| 67 | + // This is the child process. |
|
| 68 | + if ($processID == 0) { |
|
| 69 | + // @codeCoverageIgnoreStart |
|
| 70 | + $this->runInForeground(); |
|
| 71 | 71 | |
| 72 | - exit(0); |
|
| 73 | - // @codeCoverageIgnoreEnd |
|
| 74 | - } |
|
| 72 | + exit(0); |
|
| 73 | + // @codeCoverageIgnoreEnd |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $process = new Process($processID); |
|
| 76 | + $process = new Process($processID); |
|
| 77 | 77 | |
| 78 | - return $process; |
|
| 79 | - } |
|
| 78 | + return $process; |
|
| 79 | + } |
|
| 80 | 80 | } |