Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Job | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| create | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| command | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| exec | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Queue\Process; |
| 16 | |
| 17 | /** |
| 18 | * Job class |
| 19 | * |
| 20 | * @category Pop |
| 21 | * @package Pop\Queue |
| 22 | * @author Nick Sagona, III <nick@popphp.org> |
| 23 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 24 | * @license https://www.popphp.org/license New BSD License |
| 25 | * @version 3.0.0 |
| 26 | */ |
| 27 | class Job extends AbstractJob |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * Create job |
| 32 | * |
| 33 | * @param mixed $callable |
| 34 | * @param mixed $params |
| 35 | * @param ?string $id |
| 36 | * @return Job |
| 37 | */ |
| 38 | public static function create(mixed $callable = null, mixed $params = null, ?string $id = null): Job |
| 39 | { |
| 40 | return new self($callable, $params, $id); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Create a job object with an application command - an invocation string |
| 45 | * routed through the application (e.g. Job::command('greet Nick')), or an |
| 46 | * argv-style array of already split segments (e.g. |
| 47 | * Job::command(['notify', 'Hello there, world'])). The router splits the |
| 48 | * string form on whitespace, so the array form is the only way to pass an |
| 49 | * argument value that itself contains spaces. |
| 50 | * |
| 51 | * @param string|array $command |
| 52 | * @param ?string $id |
| 53 | * @return static |
| 54 | */ |
| 55 | public static function command(string|array $command, ?string $id = null): static |
| 56 | { |
| 57 | $job = new static(null, null, $id); |
| 58 | $job->setCommand($command); |
| 59 | |
| 60 | return $job; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Create a job object with a CLI executable command - a shell command |
| 65 | * string (runs via the shell, e.g. Job::exec('ls -la | wc -l')), or an |
| 66 | * argv-style array to run with no shell involved at all (e.g. |
| 67 | * Job::exec(['ls', '-la']) - the safer form when any part of the |
| 68 | * command isn't a fully-trusted literal, since shell metacharacters in |
| 69 | * an argv element are inert) |
| 70 | * |
| 71 | * @param string|array $command |
| 72 | * @param ?string $id |
| 73 | * @return static |
| 74 | */ |
| 75 | public static function exec(string|array $command, ?string $id = null): static |
| 76 | { |
| 77 | $job = new static(null, null, $id); |
| 78 | $job->setExec($command); |
| 79 | |
| 80 | return $job; |
| 81 | } |
| 82 | |
| 83 | } |