Files
Phraseanet/lib/Alchemy/Phrasea/TaskManager/Job/Factory.php
2013-10-29 18:42:46 +01:00

46 lines
1.2 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\TaskManager\Job;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Factory
{
private $dispatcher;
private $logger;
public function __construct(EventDispatcherInterface $dispatcher, LoggerInterface $logger)
{
$this->dispatcher = $dispatcher;
$this->logger = $logger;
}
public function create($fqn)
{
if (!class_exists($fqn)) {
$tryFqn = __NAMESPACE__ . '\\' . $fqn . 'Job';
if (!class_exists($tryFqn)) {
throw new InvalidArgumentException(sprintf('Job `%s` not found.', $fqn));
}
$fqn = $tryFqn;
}
if (!in_array('Alchemy\Phrasea\TaskManager\Job\JobInterface', class_implements($fqn))) {
throw new InvalidArgumentException(sprintf('Class `%s` does not implement JobInterface.', $fqn));
}
return new $fqn($this->dispatcher, $this->logger);
}
}