/** * Test validate email. */ public function test_validate_email() { $invalid = array(true, false, null, array(), new \stdClass(), 1, 1.2, '1', 'test', 'james.example.com', '*****@*****.**', '*****@*****.**', 'A@b@c@example.com', 'a"b(c)d,e:f;g<h>i[j\\k]l@example.com', 'just"not"*****@*****.**', 'this is"not\\allowed@example.com', 'this\\ still\\"not\\allowed@example.com'); foreach ($invalid as $val) { $this->assertEquals(false, \pdyn\datatype\Validator::email($val)); } $valid = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', 'user@[127.0.0.1]', 'user@[1.2.3.4]', 'user@[IPv6:2001:db8:1ff::a0b:dbd0]', '"*****@*****.**"@example.com', '"very.(),:;<>[]\\".VERY.\\"very@\\ \\"very\\".unusual"@strange.example.com', '!#$%&\'*+-/=?^_`{}|~@example.org', '""@example.org'); foreach ($valid as $val) { $this->assertEquals(true, \pdyn\datatype\Validator::email($val)); } }
/** * Assign values to class properties. * * @param array $info An array of data to assign. * @return bool Success/Failure. */ protected function populate(array $info = array()) { if (empty($info)) { $this->post_populate(); return false; } // Load datatype information into static var cache. $obj_datatypes = static::get_obj_datatypes($this->DB); $info = array_intersect_key($info, $obj_datatypes); foreach ($info as $key => $val) { switch ($obj_datatypes[$key]) { case 'email': if (\pdyn\datatype\Validator::email($val)) { $this->{$key} = (string) $val; } break; case 'timestamp': if ((int) $val > 0) { $this->{$key} = (int) $val; } break; case 'str': case 'text': case 'longtext': $this->{$key} = (string) $val; break; case 'filename': $val = trim($val); if (!empty($val)) { $this->{$key} = \pdyn\filesystem\FilesystemUtils::sanitize_filename($val); } break; case 'int': case 'bigint': $this->{$key} = (int) $val; break; case 'float': $this->{$key} = (double) $val; break; case 'id': $this->{$key} = (int) $val; break; case 'bool': $this->{$key} = (bool) $val; break; case 'user_id': if (\pdyn\datatype\Id::validate($val) === true) { $this->{$key} = (int) $val; } break; case 'url': if (\pdyn\datatype\Url::validate($val) === true) { $this->{$key} = (string) $val; } break; case 'mime': if (\pdyn\datatype\Validator::mime($val) === true) { $this->{$key} = (string) $val; } break; default: if (is_array($obj_datatypes[$key])) { if (in_array($val, $obj_datatypes[$key], true)) { $this->{$key} = $val; } } else { $this->{$key} = $val; } } } $this->post_populate(); return true; }