public function checkCondition($value)
 {
     if (parent::checkCondition($value)) {
         return true;
     }
     if (!TypeCheck::isInt($value)) {
         return false;
     } else {
         $value = (int) $value;
         return $value >= $this->min && $value <= $this->max;
     }
 }
예제 #2
0
 /**
  * Casts a string to the given type.
  *
  * @param string $value the value as string
  * @param int $type the type - any of <code>Input::TYPE_STRING</code>,
  * <code>Input::TYPE_INT</code>, <code>Input::TYPE_BOOL</code> or
  * <code>Input::TYPE_SERIALIZED</code>,
  * @return string number boolean array mixed null if the value could not be cast
  */
 protected function typecast($value, $type)
 {
     switch ($type) {
         case self::TYPE_STRING:
             return $value;
         case self::TYPE_INT:
             if (TypeCheck::isInt($value)) {
                 return (int) $value;
             }
             return null;
         case self::TYPE_FLOAT:
             if (TypeCheck::isFloat($value)) {
                 return (double) $value;
             }
             return null;
         case self::TYPE_BOOL:
             if (is_bool($value)) {
                 return $value;
             }
             switch ($value) {
                 case 'true':
                 case '1':
                     return true;
                 case 'false':
                 case '0':
                     return false;
                 default:
                     return null;
             }
         case self::TYPE_SERIALIZED:
             try {
                 $decoded = base64_decode($value);
                 return unserialize($decoded);
             } catch (ErrorException $e) {
                 return null;
             }
         default:
             return null;
     }
 }
예제 #3
0
 /**
  * Tests if a value is a boolean.
  *
  * @dataProvider isBoolProvider
  * @covers empire\framework\util\TypeCheck::isBool
  *
  * @param mixed $value the value to check
  * @param boolean $res if it is an boolean
  */
 public function testIsBool($value, $res)
 {
     $this->assertSame($res, TypeCheck::isBool($value));
 }