Example #1
0
 /**
  * @dataProvider castWrongVartypeProvider
  */
 public function testCastWrongVartype($vartype)
 {
     $this->setExpectedException('InvalidArgumentException');
     rex_type::cast(1, $vartype);
 }
Example #2
0
 /**
  * Searches the value $needle in array $haystack and returns the casted value.
  *
  * @param array      $haystack Array
  * @param string|int $needle   Value to search
  * @param string     $vartype  Variable type
  * @param mixed      $default  Default value
  *
  * @throws InvalidArgumentException
  *
  * @return mixed
  */
 private static function arrayKeyCast(array $haystack, $needle, $vartype, $default = '')
 {
     if (!is_scalar($needle)) {
         throw new InvalidArgumentException('Scalar expected for $needle in arrayKeyCast()!');
     }
     if (array_key_exists($needle, $haystack)) {
         return rex_type::cast($haystack[$needle], $vartype);
     }
     if ($default === '') {
         return rex_type::cast($default, $vartype);
     }
     return $default;
 }