From 709c096b401b94612b9c1f4f67493712ca5f2b2b Mon Sep 17 00:00:00 2001 From: Gl3nda85 Date: Thu, 9 Feb 2017 18:28:21 +1100 Subject: [PATCH] added text search into base api --- .idea/vcs.xml | 6 ++++++ composer.json | 4 +++- src/GooglePlaces.php | 20 ++++++++++++++++++++ tests/GooglePlacesTest.php | 3 +++ tests/Test.php | 20 ++++++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .idea/vcs.xml create mode 100644 tests/Test.php diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/composer.json b/composer.json index 148b173..beef216 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ "homepage": "http://joshtronic.com" }], "require": { - "php": ">=5.3.0" + "php": ">=5.3.0", + "phpunit/phpunit": "4.0.*" }, "require-dev": { "satooshi/php-coveralls": "dev-master" @@ -20,4 +21,5 @@ "autoload": { "psr-4": {"joshtronic\\": "src/"} } + } diff --git a/src/GooglePlaces.php b/src/GooglePlaces.php index 8cbcfd8..dfe45a3 100644 --- a/src/GooglePlaces.php +++ b/src/GooglePlaces.php @@ -2,6 +2,8 @@ namespace joshtronic; +use SebastianBergmann\Exporter\Exception; + class GooglePlaces { public $client = ''; @@ -24,6 +26,9 @@ class GooglePlaces public $placeid = null; public $reference = null; public $opennow = null; + //added these for text search. + public $textsearch = null; + public $query = null; public $subradius = null; public $getmax = true; @@ -212,6 +217,14 @@ private function methodChecker($parameters, $method) } break; + + //added this for text search + case 'textsearch': + if(!isset($parameters['query'])){ + + throw new Exception('You must specify the string you want to search for'); + } + break; } } @@ -240,6 +253,12 @@ private function queryGoogle($url, $parameters) $querystring .= '&'; } + // added this to remove spaces from text search + if(preg_match('/\s/',$value)){ + + $value = str_replace(' ', '+', $value); + } + $querystring .= $variable . '=' . $value; } @@ -247,6 +266,7 @@ private function queryGoogle($url, $parameters) if ($this->output == 'json') { + $response = json_decode($response, true); if ($response === null) diff --git a/tests/GooglePlacesTest.php b/tests/GooglePlacesTest.php index 2d0b401..4366487 100644 --- a/tests/GooglePlacesTest.php +++ b/tests/GooglePlacesTest.php @@ -1,8 +1,11 @@ query = "Shop 111 Epping Plaza High Street"; +$results = $google_places->textsearch(); + +highlight_string(""); \ No newline at end of file