Add guzzle to composer

This commit is contained in:
Kendrick Chan 2018-01-15 16:26:32 +08:00
parent 6737099278
commit e4d9c47eb5
4 changed files with 286 additions and 2 deletions

View file

@ -5,6 +5,7 @@
"php": "^7.1.3",
"ext-iconv": "*",
"creof/doctrine2-spatial": "^1.2",
"guzzlehttp/guzzle": "^6.3",
"sensio/framework-extra-bundle": "^5.1",
"symfony/console": "^4.0",
"symfony/debug": "^4.0",

233
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "cdf67500854c3ba9f2f9d1cbeeb8ee7d",
"content-hash": "76c7ab30aaf88fded46189060d30a852",
"packages": [
{
"name": "creof/doctrine2-spatial",
@ -1139,6 +1139,187 @@
],
"time": "2017-12-20T00:38:15+00:00"
},
{
"name": "guzzlehttp/guzzle",
"version": "6.3.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699",
"reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.4",
"php": ">=5.5"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^4.0 || ^5.0",
"psr/log": "^1.0"
},
"suggest": {
"psr/log": "Required for using the Log middleware"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.2-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2017-06-22T18:50:49+00:00"
},
{
"name": "guzzlehttp/promises",
"version": "v1.3.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"time": "2016-12-20T10:07:11+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"request",
"response",
"stream",
"uri",
"url"
],
"time": "2017-03-20T17:10:46+00:00"
},
{
"name": "jdorn/sql-formatter",
"version": "v1.2.17",
@ -1403,6 +1584,56 @@
],
"time": "2017-02-14T16:28:37+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"time": "2016-08-06T14:39:51+00:00"
},
{
"name": "psr/log",
"version": "1.0.2",

View file

@ -8,6 +8,7 @@ use App\Access\Generator;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use App\Entity\Outlet;
use GuzzleHttp\Client as GuzzleClient;
class TestController extends BaseController
{
@ -37,11 +38,46 @@ class TestController extends BaseController
return $this->render('test/map.html.twig', $params);
}
protected function mapGetDistances(Point $point, $outlets)
{
$client = new GuzzleClient();
// origins
$origins_value = $point->getLatitude() . ',' . $point->getLongitude();
// destinations
$dests = [];
foreach ($outlets as $outlet)
{
$coord = $outlet->getCoordinates();
$dests[] = $coord->getLatitude() . ',' . $point->getLongitude();
}
$dests_value = implode('|', $dests);
// google maps base url api
$maps_url = 'https://maps.googleapis.com/maps/api/distancematrix/json';
// parameters
$gmaps_params = [
'origins' => $origins_value,
'destinations' => $dests_value,
];
error_log(print_r($gmaps_params, true));
// query google maps api
$res = $client->request('GET', $maps_url, ['query' => $gmaps_params]);
error_log($res->getBody());
return $res;
}
public function distance()
{
$params = $this->initParameters('home');
$point = new Point(121.0495453, 14.6042567);
// $point = new Point(121.0495453, 14.6042567);
$point = new Point(120.343692, 16.048560);
// test if we can get the top 5 closest outlets to a point
$em = $this->getDoctrine()->getManager();
@ -52,11 +88,15 @@ class TestController extends BaseController
error_log($query->getSql());
$result = $query->getResult();
$outlets = [];
foreach ($result as $row)
{
error_log($row[0]->getName() . ' - ' . $row['dist']);
$outlets[] = $row[0];
}
$this->mapGetDistances($point, $outlets);
return $this->render('home.html.twig', $params);
}
}

View file

@ -68,6 +68,15 @@
"doctrine/orm": {
"version": "v2.6.0"
},
"guzzlehttp/guzzle": {
"version": "6.3.0"
},
"guzzlehttp/promises": {
"version": "v1.3.1"
},
"guzzlehttp/psr7": {
"version": "1.4.2"
},
"jdorn/sql-formatter": {
"version": "v1.2.17"
},
@ -83,6 +92,9 @@
"psr/container": {
"version": "1.0.0"
},
"psr/http-message": {
"version": "1.0.1"
},
"psr/log": {
"version": "1.0.2"
},