Completed
Push — master ( 6a1fcf...fe496e )
by Peter
09:07
created

HandlerLocatedQueryBus::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Query\Bus;
12
13
use GpsLab\Component\Query\Exception\HandlerNotFoundException;
14
use GpsLab\Component\Query\Handler\Locator\QueryHandlerLocator;
15
use GpsLab\Component\Query\Handler\QueryHandler;
16
use GpsLab\Component\Query\Query;
17
18
class HandlerLocatedQueryBus implements QueryBus
19
{
20
    /**
21
     * @var QueryHandlerLocator
22
     */
23
    private $locator;
24
25
    /**
26
     * @param QueryHandlerLocator $locator
27
     */
28
    public function __construct(QueryHandlerLocator $locator)
29
    {
30
        $this->locator = $locator;
31
    }
32
33
    /**
34
     * @param Query $query
35
     *
36
     * @return mixed
37
     */
38
    public function handle(Query $query)
39
    {
40
        $handler = $this->locator->getQueryHandler($query);
41
42
        if (!($handler instanceof QueryHandler)) {
43
            throw HandlerNotFoundException::notFound($query);
44
        }
45
46
        return $handler->handle($query);
47
    }
48
}
49