浏览代码

GeocodeLib.php _transform() handles null results

I have run into this too, if the data doesn't come back from the geocode API for whatever reason, the `_transform()` doesn't work.

https://travis-ci.org/dereuromark/cakephp-tools/jobs/38745456
"array_key_exists() expects parameter 2 to be array, null given"

added a couple of minor checks to ensure that an array is what we're dealing with, for results, at all times
alan blount 11 年之前
父节点
当前提交
e08934efaf
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      Lib/GeocodeLib.php

+ 7 - 0
Lib/GeocodeLib.php

@@ -517,6 +517,10 @@ class GeocodeLib {
 		if (!is_array($record)) {
 			$record = json_decode($record, true);
 		}
+		if (empty($record['results'])) {
+			$record['results'] = array();
+			return $record;
+		}
 		$record['results'] = $this->_transformData($record['results']);
 		return $record;
 	}
@@ -565,6 +569,9 @@ class GeocodeLib {
 	 * @return array record organized & normalized
 	 */
 	protected function _transformData($record) {
+		if (!is_array($record)) {
+			return array();
+		}
 		if (!array_key_exists('address_components', $record)) {
 			foreach (array_keys($record) as $key) {
 				$record[$key] = $this->_transformData($record[$key]);