1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DH\NavigationBundle; |
4
|
|
|
|
5
|
|
|
use DH\NavigationBundle\Contract\DistanceMatrix\DistanceMatrixQueryInterface; |
6
|
|
|
use DH\NavigationBundle\Contract\Routing\RoutingQueryInterface; |
7
|
|
|
use DH\NavigationBundle\Exception\UnsupportedFeatureException; |
8
|
|
|
use DH\NavigationBundle\Provider\ProviderAggregator; |
9
|
|
|
use DH\NavigationBundle\Provider\ProviderInterface; |
10
|
|
|
|
11
|
|
|
class NavigationManager |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var ProviderAggregator |
15
|
|
|
*/ |
16
|
|
|
private $providerAggregator; |
17
|
|
|
|
18
|
|
|
public function __construct(ProviderAggregator $providerAggregator) |
19
|
|
|
{ |
20
|
|
|
$this->providerAggregator = $providerAggregator; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Sets the default provider to use. |
25
|
|
|
* |
26
|
|
|
* @param string $name |
27
|
|
|
* |
28
|
|
|
* @return NavigationManager |
29
|
|
|
*/ |
30
|
|
|
public function using(string $name): self |
31
|
|
|
{ |
32
|
|
|
$this->providerAggregator->using($name); |
33
|
|
|
|
34
|
|
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @throws UnsupportedFeatureException |
39
|
|
|
* |
40
|
|
|
* @return DistanceMatrixQueryInterface |
41
|
|
|
*/ |
42
|
|
|
public function createDistanceMatrixQuery(): DistanceMatrixQueryInterface |
43
|
|
|
{ |
44
|
|
|
$provider = $this->providerAggregator->getProvider(); |
45
|
|
|
|
46
|
|
|
if (method_exists($provider, 'createDistanceMatrixQuery')) { |
47
|
|
|
return $provider->createDistanceMatrixQuery(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
throw new UnsupportedFeatureException(sprintf('Distance Matrix is not supported by "%s" provider.', $provider->getName())); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @throws UnsupportedFeatureException |
55
|
|
|
* |
56
|
|
|
* @return RoutingQueryInterface |
57
|
|
|
*/ |
58
|
|
|
public function createRoutingQuery(): RoutingQueryInterface |
59
|
|
|
{ |
60
|
|
|
$provider = $this->providerAggregator->getProvider(); |
61
|
|
|
|
62
|
|
|
if (method_exists($provider, 'createRoutingQuery')) { |
63
|
|
|
return $provider->createRoutingQuery(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
throw new UnsupportedFeatureException(sprintf('Routing is not supported by "%s" provider.', $provider->getName())); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param null|string $name |
71
|
|
|
* |
72
|
|
|
* @return ProviderInterface |
73
|
|
|
*/ |
74
|
|
|
public function getProvider(?string $name = null): ProviderInterface |
75
|
|
|
{ |
76
|
|
|
return $this->providerAggregator->getProvider($name); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
|
|
public function getProviders(): array |
83
|
|
|
{ |
84
|
|
|
return $this->providerAggregator->getProviders(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return ProviderAggregator |
89
|
|
|
*/ |
90
|
|
|
public function getProviderAggregator(): ProviderAggregator |
91
|
|
|
{ |
92
|
|
|
return $this->providerAggregator; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|