-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathindex.php
53 lines (42 loc) · 1.24 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require __DIR__ . '/../vendor/autoload.php';
use GSoares\GoogleTrends\Search\Psr7\Search;
use GSoares\GoogleTrends\Search\InterestByRegionSearch;
use GSoares\GoogleTrends\Search\InterestOverTimeSearch;
use GSoares\GoogleTrends\Search\RelatedTopicsSearch;
use GSoares\GoogleTrends\Search\RelatedQueriesSearch;
use GSoares\GoogleTrends\Search\SearchInterface;
use GuzzleHttp\Psr7\ServerRequest;
function getUri(): string
{
$uri = trim($_SERVER['REQUEST_URI'], '/');
if (strpos($uri, '?') === false) {
return $uri;
}
return substr(
$uri,
0,
strpos(
$uri,
'?'
)
);
}
function getSearchByUri($uri): SearchInterface
{
if ($uri === 'search-related-queries') {
return new RelatedQueriesSearch();
}
if ($uri === 'search-related-topics') {
return new RelatedTopicsSearch();
}
if ($uri === 'search-interest-over-time') {
return new InterestOverTimeSearch();
}
if ($uri === 'search-interest-by-region') {
return new InterestByRegionSearch();
}
}
$httpSearch = new Search(getSearchByUri(getUri()));
header('Content-Type', 'application/json');
echo (string)$httpSearch->search(ServerRequest::fromGlobals())->getBody();