Completed
Push — master ( f6b571...ab1502 )
by
unknown
38:58
created

JobResolver::addJob()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace SfCod\QueueBundle\Service;
4
5
use SfCod\QueueBundle\Base\JobInterface;
6
use SfCod\QueueBundle\Base\JobResolverInterface;
7
use SfCod\QueueBundle\Exception\FatalThrowableException;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
10
/**
11
 * Class JobResolver
12
 *
13
 * @author Virchenko Maksim <[email protected]>
14
 *
15
 * @package SfCod\QueueBundle\Service
16
 */
17
class JobResolver implements JobResolverInterface
18
{
19
    /**
20
     * @var JobInterface[]
21
     */
22
    private $jobs = [];
23
24
    /**
25
     * Resolve the given class.
26
     *
27
     * @param string $id
28
     *
29
     * @return JobInterface
30
     */
31
    public function resolve(string $id): JobInterface
32
    {
33
        if (isset($this->jobs[$id])) {
34
            return $this->jobs[$id];
35
        }
36
37
        throw new FatalThrowableException("Job handler '$id' not found.");
38
    }
39
40
    /**
41
     * @inheritDoc
42
     *
43
     * @param string $id
44
     * @param JobInterface $job
45
     */
46
    public function addJob(string $id, JobInterface $job)
47
    {
48
        $this->jobs[$id] = $job;
49
    }
50
}
51