mirror of
https://github.com/idanoo/php-resque
synced 2025-07-02 06:02:21 +00:00
47 lines
1 KiB
PHP
47 lines
1 KiB
PHP
<?php
|
|
|
|
namespace Resque\Job;
|
|
|
|
/**
|
|
* Job Factory!
|
|
*
|
|
* @package Resque/Job
|
|
* @author Daniel Mason <daniel@m2.nz>
|
|
* @license http://www.opensource.org/licenses/mit-license.php
|
|
*/
|
|
class Factory implements FactoryInterface
|
|
{
|
|
public ?Job $job;
|
|
public string $queue;
|
|
public array $args;
|
|
|
|
/**
|
|
* @param $className
|
|
* @param array $args
|
|
* @param $queue
|
|
*
|
|
* @return \Resque\Job\JobInterface
|
|
*
|
|
* @throws \Resque\Exception
|
|
*/
|
|
public function create($className, $args, $queue)
|
|
{
|
|
if (!class_exists($className)) {
|
|
throw new \Resque\Exception(
|
|
'Could not find job class ' . $className . '.'
|
|
);
|
|
}
|
|
|
|
if (!method_exists($className, 'perform')) {
|
|
throw new \Resque\Exception(
|
|
'Job class ' . $className . ' does not contain a perform() method.'
|
|
);
|
|
}
|
|
|
|
$instance = new $className();
|
|
$instance->args = $args;
|
|
$instance->queue = $queue;
|
|
|
|
return $instance;
|
|
}
|
|
}
|