Example #1
0
 public function testIsBetween()
 {
     $this->assertTrue(Zend_Filter::isBetween(10, 1, 20, FALSE), '"10" is between "1" and "20" non inclusive');
     $this->assertTrue(Zend_Filter::isBetween(10, 1, 10), '"10" is between "1" and "20" inclusive');
     $this->assertFalse(Zend_Filter::isBetween(10, 1, 9, FALSE), '"10" is not between "1" and "9" inclusive');
     $this->assertFalse(Zend_Filter::isBetween(10, 1, 9), '"10" is not between "1" and "9" inclusive');
 }
Example #2
0
 /**
  * Validate Web Search Options
  *
  * @param array $options
  */
 protected function _validateWebSearch($options)
 {
     $valid_options = array('appid', 'query', 'results', 'start', 'language', 'type', 'format', 'adult_ok', 'similar_ok', 'country', 'site', 'subscription', 'license');
     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.');
         }
     }
     $this->_validateLanguage($options['language']);
     $this->_validateInArray('query type', $options['type'], array('all', 'any', 'phrase'));
     $this->_validateInArray('format', $options['format'], array('any', 'html', 'msword', 'pdf', 'ppt', 'rss', 'txt', 'xls'));
     $this->_validateInArray('license', $options['license'], array('any', 'cc_any', 'cc_commercial', 'cc_modifiable'));
 }
Example #3
0
 /**
  * Validate options for an ItemLookup
  *
  * @param array $options Options array to be used for the query
  * @throws Zend_Service_Exception
  * @return void
  */
 protected function _validateItemLookup($options = array())
 {
     if (!is_array($options)) {
         throw new Zend_Service_Exception('Options must be specified as an array');
     }
     // Validate keys in the $options array
     $this->_compareOptions($options, array('ItemId', 'IdType', 'SearchIndex', 'MerchantId', 'Condition', 'DeliveryMethod', 'ISPUPostalCode', 'OfferPage', 'ReviewPage', 'VariationPage', 'ResponseGroup', 'Service', 'SubscriptionId', 'Operation'));
     // Validate ResponseGroup (required)
     if (empty($options['ResponseGroup'])) {
         throw new Zend_Service_Exception('Query requires a ResponseGroup');
     } else {
         $responseGroup = split(',', $options['ResponseGroup']);
         foreach ($responseGroup as $r) {
             if (!in_array($r, array('Request', 'Small', 'Medium', 'Large'))) {
                 throw new Zend_Service_Exception('This wrapper only supports Request, Small, Medium and Large ' . 'ResponseGroups');
             }
         }
     }
     // Validate Sort (optional)
     if (isset($options['Sort'])) {
         $this->_validateInArray('Sort', $options['Sort'], array_values(self::$_searchSort[$options['SearchIndex']]));
     }
     // Validate City (optional)
     if (isset($options['City'])) {
         $this->_validateInArray('City', $options['City'], array('Boston', 'Chicago', 'New York', 'San Francisco', 'Seattle', 'Washington, D.C.'));
     }
     if (isset($options['ItemPage'])) {
         if (!Zend_Filter::isBetween($options['ItemPage'], 0, 2500, true)) {
             throw new Zend_Service_Exception($options['ItemPage'] . ' is not a valid value for the "ItemPage" option.');
         }
     }
 }
Example #4
0
 /**
  * Returns value if it is greater than or equal to $min and less
  * than or equal to $max, FALSE otherwise. If $inc is set to
  * FALSE, then the value must be strictly greater than $min and
  * strictly less than $max.
  *
  * @param mixed $key
  * @param mixed $min
  * @param mixed $max
  * @param boolean $inclusive
  * @return mixed
  */
 public function testBetween($key, $min, $max, $inc = TRUE)
 {
     if (!$this->keyExists($key)) {
         return false;
     }
     if (Zend_Filter::isBetween($this->_source[$key], $min, $max, $inc)) {
         return $this->_source[$key];
     }
     return FALSE;
 }
Example #5
0
 /**
  * Validate Tag Search Options
  *
  * @param array $options
  */
 protected function _validateTagSearch($options)
 {
     $valid_options = array('api_key', 'method', 'user_id', 'per_page', 'page', 'extras', 'min_upload_date', 'min_taken_date', 'max_upload_date', 'max_taken_date', 'tag_mode', 'tags');
     if (!is_array($options)) {
         return;
     }
     $this->_compareOptions($options, $valid_options);
     if (!Zend_Filter::isBetween($options['per_page'], 1, 500, true)) {
         throw new Zend_Service_Exception($options['per_page'] . ' is not valid for the "per_page" option');
     }
     if (!Zend_Filter::isInt($options['page'])) {
         throw new Zend_Service_Exception($options['page'] . ' is not valid for the "page" option');
     }
     // validate extras, which are delivered in csv format
     if ($options['extras']) {
         $extras = explode(',', $options['extras']);
         $valid_extras = array('license', 'date_upload', 'date_taken', 'owner_name', 'icon_server');
         foreach ($extras as $extra) {
             /**
              * @todo The following does not do anything [yet], so it is commented out.
              */
             //in_array(trim($extra), $valid_extras);
         }
     }
 }
Example #6
0
 /**
  * Returns value if it is greater than or equal to $min and less
  * than or equal to $max, FALSE otherwise. If $inc is set to
  * FALSE, then the value must be strictly greater than $min and
  * strictly less than $max.
  *
  * @param mixed $key
  * @param mixed $min
  * @param mixed $max
  * @param boolean $inclusive
  * @return mixed
  */
 public function isBetween($key, $min = NULL, $max = NULL, $inc = TRUE)
 {
     return Zend_Filter::isBetween($this->_source[$key], $min, $max, $inc);
 }
Example #7
0
 /**
  * Returns value if it is greater than or equal to $min and less
  * than or equal to $max, FALSE otherwise. If $inc is set to
  * FALSE, then the value must be strictly greater than $min and
  * strictly less than $max.
  *
  * @param mixed $key
  * @param mixed $min
  * @param mixed $max
  * @param boolean $inclusive
  * @return mixed
  */
 public function testBetween($key = null, $min, $max, $inc = TRUE)
 {
     if (!($value = $this->keyExists($key))) {
         return false;
     }
     if (Zend_Filter::isBetween($value, $min, $max, $inc)) {
         return $value;
     }
     return FALSE;
 }