Making the factory the default layer to construct jobs

This commit is contained in:
Sebastian Machuca 2016-10-14 14:41:19 +11:00
parent df20186c37
commit be19e12c31
No known key found for this signature in database
GPG key ID: 4B3DA17F9CCF39DE
5 changed files with 64 additions and 29 deletions

View 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;
}
}