/** * Validate Local Search Options * * @param array $options */ protected function _validateLocalSearch($options) { $valid_options = array('appid', 'query', 'results', 'start', 'sort', 'radius', 'street', 'city', 'state', 'zip', 'location', 'latitude', 'longitude'); if (!is_array($options)) { return; } $this->_compareOptions($options, $valid_options); if (isset($options['results'])) { if (!Zend_Filter::isBetween($options['results'], 1, 20, true)) { throw new Zend_Service_Exception($options['results'] . ' is not valid for the "results" option.'); } } if (isset($options['start'])) { if (!Zend_Filter::isBetween($options['start'], 1, 1000, true)) { throw new Zend_Service_Exception($options['start'] . ' is not valid for the "start" option.'); } } if (isset($options['longitude'])) { if (!Zend_Filter::isBetween($options['longitude'], -90, 90, true)) { throw new Zend_Service_Exception($options['longitude'] . ' is not valid for the "longitude" option.'); } } if (isset($options['latitude'])) { if (!Zend_Filter::isBetween($options['latitude'], -180, 180, true)) { throw new Zend_Service_Exception($options['latitude'] . ' is not valid for the "latitude" option.'); } } if (isset($options['zip'])) { if (!Zend_Filter::isZip($options['zip'])) { throw new Zend_Service_Exception($options['zip'] . ' is not a valid for the "zip" option.'); } } $locationFields = array('street', 'city', 'state', 'zip', 'location', 'lon'); foreach ($locationFields as $field) { if (isset($options[$field]) && $options[$field] != '') { $locations[] = 1; } } if (!is_array($locations) && $options['latitude'] == '' && $options['longitude'] == '') { throw new Zend_Service_Exception('You must enter a locale to search near.'); } if (!in_array($options['sort'], array('relevance', 'title', 'distance', 'rating'))) { throw new Zend_Service_Exception('You have entered an invalid sort property.'); } }
/** * Returns value if it is a valid US ZIP, FALSE otherwise. * * @param mixed $key * @return mixed */ public function testZip($key) { if (!$this->keyExists($key)) { return false; } if (Zend_Filter::isZip($this->_source[$key])) { return $this->_source[$key]; } return FALSE; }
/** * Returns value if it is a valid US ZIP, FALSE otherwise. * * @param mixed $key * @return mixed */ public function testZip($key) { if (Zend_Filter::isZip($this->_source[$key])) { return $this->_source[$key]; } return FALSE; }
public function testIsZip() { $this->assertTrue(Zend_Filter::isZip('90210'), '"90210" is a valid zip code'); $this->assertFalse(Zend_Filter::isZip('9501'), '"04600" is not a valid zip code'); }
/** * Returns value if it is a valid US ZIP, FALSE otherwise. * * @param mixed $key * @return mixed */ public function isZip($key) { return Zend_Filter::isZip($this->_source[$key]); }
/** * Returns value if it is a valid US ZIP, FALSE otherwise. * * @param mixed $key * @return mixed */ public function testZip($key = null) { if (!($value = $this->keyExists($key))) { return false; } if (Zend_Filter::isZip($value)) { return $value; } return FALSE; }