public function testEnsureFloat()
 {
     $entries = array(array(123, 123.0), array(1.23, 1.23), array(null, 0.0), array('', 0.0), array('abc', 0.0), array('123', 123.0), array('1.23', 1.23), array(' 1.23', 1.23), array(' 1.23abc', 1.23), array('abc1.23abc', 0.0), array(true, 1.0), array(false, 0.0), array(array(), 0.0), array(array(0), 1.0));
     foreach ($entries as $index => $entry) {
         $this->assertTrue(CPropertyValue::ensureFloat($entry[0]) === $entry[1], "Comparison {$index}: {$this->varToString($entry[0])}=={$this->varToString($entry[1])}");
     }
 }
Example #2
0
 public function init()
 {
     $this->maxBlockTime = $this->getTimeInterval($this->maxBlockTime);
     $this->alertRepeatInterval = $this->getTimeInterval($this->alertRepeatInterval);
     $this->gatewayMinCredit = CPropertyValue::ensureFloat($this->gatewayMinCredit);
     $gateways = array();
     foreach ($this->gateways as $gateway) {
         $gateways[] = Yii::createComponent($gateway);
     }
     $this->gateways = $gateways;
 }
 public function convertType($value)
 {
     $value = trim($value);
     if (ctype_digit($value)) {
         return CPropertyValue::ensureInteger($value);
     }
     if (is_numeric($value)) {
         return CPropertyValue::ensureFloat($value);
     }
     if (strcasecmp($value, 'null') == 0) {
         return null;
     } else {
         if (strcasecmp($value, 'true') == 0 || strcasecmp($value, 'false') == 0) {
             return CPropertyValue::ensureBoolean($value);
         } else {
             if (preg_match('/^\\(.+\\)|\\(\\)$/', $value)) {
                 return CPropertyValue::ensureArray($value);
             }
         }
     }
     return $value;
 }
 public function setTimeLimit($value)
 {
     $this->_timeLimit = CPropertyValue::ensureFloat($value);
 }
Example #5
0
 /**
  * Extract an data from input data
  *
  * @param string $name can be an normal name or 'Class[attribute]' to get input of a model attribute
  *
  * @param mixed $defaultValue it is recommended to specify default value even when you
  * are sure that the input has data you want to extract.
  *
  * @param string $filter 'xss,notag,newline' filters the data is run through before returned
  * do not combine xss with notag as it slow down the performance.
  */
 public function getInput($name, $defaultValue = null, $filter = '')
 {
     if (is_array($parsedName = $this->parseName($name))) {
         $name = $parsedName[0];
         $key = $parsedName[1];
     }
     if (!array_key_exists($name, $this->data)) {
         return $defaultValue;
     } else {
         $value = $this->data[$name];
         if (isset($key) && is_array($value)) {
             $value = $value[$key];
         }
         if (is_null($value)) {
             return $defaultValue;
         }
     }
     //Run filters
     if (is_string($value) || is_array($value)) {
         foreach ($this->filters as $flt) {
             $value = call_user_func(array($this, $flt), $value, $filter);
         }
     }
     if (is_array($value)) {
         return $value;
     }
     $value = trim($value);
     //Convert to expected type
     if (is_null($defaultValue)) {
         return trim($value);
     }
     if (is_string($defaultValue)) {
         return CPropertyValue::ensureString($value);
     }
     if (is_int($defaultValue)) {
         return CPropertyValue::ensureInteger($value);
     }
     if (is_numeric($defaultValue)) {
         return CPropertyValue::ensureFloat($value);
     }
     if (is_array($defaultValue)) {
         if (!is_array($value)) {
             return array($value);
         } else {
             return $value;
         }
     }
     return $value;
 }
Example #6
0
 public function init()
 {
     $this->minCredit = CPropertyValue::ensureFloat($this->minCredit);
 }