コード例 #1
0
 public function index01Action()
 {
     echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>";
     //case 1
     // $validator = new \Zend\Validator\Between(2,5,false);
     //case 2
     // $validator = new \Zend\Validator\Between(array("min"=>"2","max"=>5,"inclusive"=>false));
     //case 3
     $validator = new \Zend\Validator\Between(5, 6);
     $validator->setMin(1)->setMax(3)->setInclusive(true);
     $input = "3a";
     $input = "a3a";
     $input = 4;
     if (!$validator->isValid($input)) {
         $message = $validator->getMessages();
         echo "<pre style='font-weight:bold'>";
         print_r($message);
         echo "</pre>";
         echo current($message);
     } else {
         echo "ok";
     }
     return false;
 }
コード例 #2
0
ファイル: Yahoo.php プロジェクト: niallmccrudden/zf2
    /**
     * Validate Web Search Options
     *
     * @param  array $options
     * @return void
     * @throws Zend\Service\Exception
     */
    protected function _validateWebSearch(array $options)
    {
        $validOptions = array('appid', 'query', 'results', 'start', 'language', 'type', 'format', 'adult_ok',
                              'similar_ok', 'country', 'site', 'subscription', 'license', 'region');

        $this->_compareOptions($options, $validOptions);

        $between = new Zend\Validator\Between(1, 100, true);

        if (isset($options['results']) && !$between->setMin(1)->setMax(100)->isValid($options['results'])) {
            throw new Zend\Service\Exception("Invalid value for option 'results': {$options['results']}");
        }

        if (isset($options['start']) && !$between->setMin(1)->setMax(1000)->isValid($options['start'])) {
            throw new Zend\Service\Exception("Invalid value for option 'start': {$options['start']}");
        }

        if (isset($options['language'])) {
            $this->_validateLanguage($options['language']);
        }

        $this->_validateInArray('type', $options['type'], array('all', 'any', 'phrase'));
        $this->_validateInArray('format', $options['format'], array('any', 'html', 'msword', 'pdf', 'ppt', 'rss',
                                                                    'txt', 'xls'));
        if (isset($options['license'])) {
            $this->_validateInArray('license', $options['license'], array('any', 'cc_any', 'cc_commercial',
                                                                      'cc_modifiable'));
        }

        if (isset($options['region'])){
            $this->_validateInArray('region', $options['region'], array('ar', 'au', 'at', 'br', 'ca', 'ct', 'dk', 'fi',
                                                                          'fr', 'de', 'in', 'id', 'it', 'my', 'mx',
                                                                          'nl', 'no', 'ph', 'ru', 'sg', 'es', 'se',
                                                                          'ch', 'th', 'uk', 'us'));
        }
    }
コード例 #3
0
ファイル: SearchParameters.php プロジェクト: bradley-holt/zf2
 /**
  * set the max result hits for this search
  *
  * @param integer $hits
  * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters
  */
 public function setHits($hits = 10)
 {
     $validator = new Zend\Validator\Between(0, 1000);
     if (!$validator->isValid($hits)) {
         $message = $validator->getMessages();
         throw new Zend_Service_DeveloperGarden_LocalSearch_Exception(current($message));
     }
     $this->_parameters['hits'] = $hits;
     return $this;
 }
コード例 #4
0
ファイル: Flickr.php プロジェクト: alab1001101/zf2
 /**
  * Validate Group Search Options
  *
  * @param  array $options
  * @throws Zend\Service\Exception
  * @return void
  */
 protected function _validateGroupPoolGetPhotos(array $options)
 {
     $validOptions = array('api_key', 'tags', 'method', 'group_id', 'per_page', 'page', 'extras', 'user_id');
     $this->_compareOptions($options, $validOptions);
     $between = new Zend\Validator\Between(1, 500, true);
     if (!$between->isValid($options['per_page'])) {
         throw new Zend\Service\Exception($options['per_page'] . ' is not valid for the "per_page" option');
     }
     $int = new Zend\Validator\Int();
     if (!$int->isValid($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 (isset($options['extras'])) {
         $extras = explode(',', $options['extras']);
         $validExtras = 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), $validExtras);
         }
     }
 }