本文整理汇总了PHP中Zend\Validator\EmailAddress::getMessages方法的典型用法代码示例。如果您正苦于以下问题:PHP EmailAddress::getMessages方法的具体用法?PHP EmailAddress::getMessages怎么用?PHP EmailAddress::getMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Validator\EmailAddress
的用法示例。
在下文中一共展示了EmailAddress::getMessages方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUseMxRecordsBasicInvalid
/**
* @group ZF2-130
*/
public function testUseMxRecordsBasicInvalid()
{
$validator = new EmailAddress(array(
'useMxCheck' => true,
'useDeepMxCheck' => true
));
$emailAddresses = array(
'',
'bob
@domain.com',
'bob jones@domain.com',
'.bobJones@studio24.com',
'bobJones.@studio24.com',
'bob.Jones.@studio24.com',
'"bob%jones@domain.com',
'bob@verylongdomainsupercalifragilisticexpialidociousaspoonfulofsugar.com',
'bob+domain.com',
'bob.domain.com',
'bob @domain.com',
'bob@ domain.com',
'bob @ domain.com',
'Abc..123@example.com'
);
foreach ($emailAddresses as $input) {
$this->assertFalse($validator->isValid($input), implode("\n", $this->validator->getMessages()) . $input);
}
}
示例2: validateEmail
/**
* Trims and validates email
*
* @param string $email
* @return string
* @throws Exception
*/
public static function validateEmail($email)
{
$validator = new EmailAddress();
if (!$validator->isValid((new StringTrim())->filter($email))) {
throw new Exception(Json::encode($validator->getMessages()));
}
return $email;
}
示例3: validateEntity
/**
* {@inheritDoc}
*/
public function validateEntity(EntityInterface $entity, ErrorStore $errorStore)
{
if (false == $entity->getName()) {
$errorStore->addError('o:name', 'The name cannot be empty.');
}
$email = $entity->getEmail();
$validator = new EmailAddress();
if (!$validator->isValid($email)) {
$errorStore->addValidatorMessages('o:email', $validator->getMessages());
}
if (!$this->isUnique($entity, ['email' => $email])) {
$errorStore->addError('o:email', sprintf('The email "%s" is already taken.', $email));
}
if (false == $entity->getRole()) {
$errorStore->addError('o:role', 'Users must have a role.');
}
}
示例4: __construct
/**
* Constructor
*
* @param string $email
* @param null|string $name
* @throws Exception\InvalidArgumentException
* @return Address
*/
public function __construct($email, $name = null)
{
$emailAddressValidator = new EmailAddressValidator(Hostname::ALLOW_DNS | Hostname::ALLOW_LOCAL);
if (!is_string($email) || empty($email)) {
throw new Exception\InvalidArgumentException('Email must be a valid email address');
}
if (preg_match("/[\r\n]/", $email)) {
throw new Exception\InvalidArgumentException('CRLF injection detected');
}
if (!$emailAddressValidator->isValid($email)) {
$invalidMessages = $emailAddressValidator->getMessages();
throw new Exception\InvalidArgumentException(array_shift($invalidMessages));
}
if (null !== $name) {
if (!is_string($name)) {
throw new Exception\InvalidArgumentException('Name must be a string');
}
if (preg_match("/[\r\n]/", $name)) {
throw new Exception\InvalidArgumentException('CRLF injection detected');
}
$this->name = $name;
}
$this->email = $email;
}
示例5: testHostnameSettings
/**
* Test changing hostname settings via EmailAddress object
*
* @return void
*/
public function testHostnameSettings()
{
$validator = new Validator\EmailAddress();
// Check no IDN matching
$validator->getHostnameValidator()->setValidateIdn(false);
$valuesExpected = array(
array(false, array('name@b�rger.de', 'name@h�llo.de', 'name@h�llo.se'))
);
foreach ($valuesExpected as $element) {
foreach ($element[1] as $input) {
$this->assertEquals($element[0], $validator->isValid($input), implode("\n", $validator->getMessages()));
}
}
// Check no TLD matching
$validator->getHostnameValidator()->setValidateTld(false);
$valuesExpected = array(
array(true, array('name@domain.xx', 'name@domain.zz', 'name@domain.madeup'))
);
foreach ($valuesExpected as $element) {
foreach ($element[1] as $input) {
$this->assertEquals($element[0], $validator->isValid($input), implode("\n", $validator->getMessages()));
}
}
}
示例6: testUseMxCheckBasicValid
/**
* @group ZF2-130
*/
public function testUseMxCheckBasicValid()
{
$validator = new Validator\EmailAddress(array('useMxCheck' => true, 'useDeepMxCheck' => true));
$emailAddresses = array('bob@gmail.com', 'bob.jones@bbc.co.uk', 'bob.jones.smythe@bbc.co.uk', 'BoB@aol.com', 'bobjones@nist.gov', "B.O'Callaghan@usmc.mil", 'bob+jones@nic.us', 'bob+jones@dailymail.co.uk', 'bob@teaparty.uk.com', 'bob@thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com');
foreach ($emailAddresses as $input) {
$this->assertTrue($validator->isValid($input), "{$input} failed to pass validation:\n" . implode("\n", $validator->getMessages()));
}
}
示例7: testIdenticalAndNonIdenticalMessagesReturned
public function testIdenticalAndNonIdenticalMessagesReturned()
{
$validator = new EmailAddress();
$this->assertFalse($validator->isValid('invalid@email.coma'));
$this->assertCount(3, $validator->getMessages());
$this->assertArrayHasKey(EmailAddress::INVALID_HOSTNAME, $validator->getMessages());
$this->assertArrayHasKey(Hostname::UNKNOWN_TLD, $validator->getMessages());
$this->assertArrayHasKey(Hostname::LOCAL_NAME_NOT_ALLOWED, $validator->getMessages());
$validator->setMessages(array(EmailAddress::INVALID_HOSTNAME => 'This is the same error message', Hostname::UNKNOWN_TLD => 'This is the same error message'));
$this->assertFalse($validator->isValid('invalid@email.coma'));
$this->assertCount(2, $validator->getMessages());
$this->assertArrayHasKey(EmailAddress::INVALID_HOSTNAME, $validator->getMessages());
$this->assertArrayHasKey(Hostname::LOCAL_NAME_NOT_ALLOWED, $validator->getMessages());
}