16 private ObjectFactory $objectFactory;
19 private array $jobObjectSpecs;
25 public function __construct( ObjectFactory $objectFactory, array $jobObjectSpecs ) {
26 $this->objectFactory = $objectFactory;
27 $this->jobObjectSpecs = $jobObjectSpecs;
49 public function newJob(
string $command, $params = [] ):
Job {
50 if ( !isset( $this->jobObjectSpecs[ $command ] ) ) {
51 throw new InvalidArgumentException(
"Invalid job command '{$command}'" );
54 $spec = $this->jobObjectSpecs[ $command ];
55 $needsTitle = $this->needsTitle( $command, $spec );
60 $title = Title::newFromPageReference( $params );
61 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
62 } elseif ( isset( $params[
'namespace'] ) && isset( $params[
'title'] ) ) {
88 $job = $this->objectFactory->createObject(
91 'allowClassName' =>
true,
92 'allowCallable' =>
true,
94 'assertClass' => Job::class
99 $job->command = $command;
112 private function needsTitle(
string $command, $spec ): bool {
115 } elseif ( is_array( $spec ) ) {
116 if ( isset( $spec[
'needsPage'] ) ) {
117 $needsTitle =
$spec[
'needsPage'];
118 } elseif ( isset( $spec[
'class'] ) ) {
119 $needsTitle = !is_subclass_of( $spec[
'class'],
120 GenericParameterJob::class );
121 } elseif ( isset( $spec[
'factory'] ) ) {
124 throw new InvalidArgumentException(
125 "Invalid job specification for '{$command}': " .
126 "must contain the 'class' or 'factory' key."
129 } elseif ( is_string( $spec ) ) {
130 $needsTitle = !is_subclass_of( $spec,
131 GenericParameterJob::class );
133 throw new InvalidArgumentException(
134 "Invalid job specification for '{$command}': " .
135 "must be a callable, an object spec array, or a class name"