mirror of
https://github.com/idanoo/php-resque
synced 2025-07-01 21:52:21 +00:00
Making the factory the default layer to construct jobs
This commit is contained in:
parent
df20186c37
commit
be19e12c31
5 changed files with 64 additions and 29 deletions
32
lib/Resque/Job/Factory.php
Normal file
32
lib/Resque/Job/Factory.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
class Resque_Job_Factory implements Resque_Job_FactoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $className
|
||||
* @param array $args
|
||||
* @param $queue
|
||||
* @return Resque_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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue