|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ONGR package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ONGR\RouterBundle\Routing; |
|
13
|
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchBundle\Result\Result; |
|
15
|
|
|
use ONGR\ElasticsearchBundle\Service\Manager; |
|
16
|
|
|
use ONGR\ElasticsearchDSL\Query\MatchQuery; |
|
17
|
|
|
use ONGR\ElasticsearchDSL\Search; |
|
18
|
|
|
use Symfony\Cmf\Component\Routing\RouteProviderInterface; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
20
|
|
|
use Symfony\Component\Routing\Exception\RouteNotFoundException; |
|
21
|
|
|
use Symfony\Component\Routing\Route; |
|
22
|
|
|
use Symfony\Component\Routing\RouteCollection; |
|
23
|
|
|
|
|
24
|
|
|
class ElasticsearchRouteProvider implements RouteProviderInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var array Route map configuration to map Elasticsearch types and Controllers |
|
28
|
|
|
*/ |
|
29
|
|
|
private $routeMap; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var Manager |
|
33
|
|
|
*/ |
|
34
|
|
|
private $manager; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* ElasticsearchRouteProvider constructor. |
|
38
|
|
|
* |
|
39
|
|
|
* @param array $routeMap |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(array $routeMap = []) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->routeMap = $routeMap; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns Elasticsearch manager instance that was set in app/config.yml. |
|
48
|
|
|
* |
|
49
|
|
|
* @return Manager |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getManager() |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->manager; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param Manager $manager |
|
58
|
|
|
*/ |
|
59
|
|
|
public function setManager(Manager $manager) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->manager = $manager; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @inheritDoc |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getRouteCollectionForRequest(Request $request) |
|
68
|
|
|
{ |
|
69
|
|
|
if (!$this->manager) { |
|
70
|
|
|
throw new \Exception('Manager must be set to execute query to the elasticsearch'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$collection = new RouteCollection(); |
|
|
|
|
|
|
74
|
|
|
$requestPath = $request->getPathInfo(); |
|
75
|
|
|
|
|
76
|
|
|
$search = new Search(); |
|
77
|
|
|
$search->addQuery(new MatchQuery('url', $requestPath)); |
|
78
|
|
|
|
|
79
|
|
|
$results = $this->manager->execute(array_keys($this->routeMap), $search, Result::RESULTS_OBJECT); |
|
80
|
|
|
|
|
81
|
|
|
foreach ($results as $result) { |
|
82
|
|
|
//Boom, you are doomed! |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @inheritDoc |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getRouteByName($name) |
|
90
|
|
|
{ |
|
91
|
|
|
// TODO: Implement getRouteByName() method. |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @inheritDoc |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getRoutesByNames($names) |
|
98
|
|
|
{ |
|
99
|
|
|
// TODO: Implement getRoutesByNames() method. |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.