Esempio n. 1
0
/**
 * Convenience wrapper for array_check_types that throws an error if the array
 * didn't match the given type specification. Refer to the array_check_types
 * documentation for more information.
 *
 * \param $arr
 *   The array to check.
 *
 * \param $typespec
 *   A type specification.
 *
 * \see
 *   array_check_types
 */
function require_args(&$arr, $typespec)
{
    if (!array_check_types($arr, $typespec)) {
        throw new AnewtException('Invalid data typespec "%s".', $typespec);
    }
}
Esempio n. 2
0
 /**
  * Test array_check_types and require_args
  */
 function test_array_type_checking()
 {
     $data = array('foo', 1, '2', true, 'bar', array());
     $this->assertFalse(array_check_types($data, "siibsa", false));
     $this->assertTrue(array_check_types($data, "siibsa"));
     $this->assertFalse(array_check_types($data, "a"));
     $this->assertFalse(array_check_types($data, "abc"));
     require_args($data, 'siibsa');
     // should not throw an error
 }