3 * @see https://github.com/zendframework/zend-uri for the canonical source repository
4 * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-uri/blob/master/LICENSE.md New BSD License
10 use Zend\Validator\EmailAddress
as EmailValidator
;
11 use Zend\Validator\ValidatorInterface
;
14 * "Mailto" URI handler
16 * The 'mailto:...' scheme is loosely defined in RFC-1738
18 class Mailto
extends Uri
20 protected static $validSchemes = ['mailto'];
23 * Validator for use when validating email address
24 * @var ValidatorInterface
26 protected $emailValidator;
29 * Check if the URI is a valid Mailto URI
31 * This applies additional specific validation rules beyond the ones
32 * required by the generic URI syntax
37 public function isValid()
39 if ($this->host ||
$this->userInfo ||
$this->port
) {
43 if (empty($this->path
)) {
47 if (0 === strpos($this->path
, '/')) {
51 $validator = $this->getValidator();
52 return $validator->isValid($this->path
);
56 * Set the email address
58 * This is in fact equivalent to setPath() - but provides a more clear interface
60 * @param string $email
63 public function setEmail($email)
65 return $this->setPath($email);
69 * Get the email address
71 * This is infact equivalent to getPath() - but provides a more clear interface
75 public function getEmail()
77 return $this->getPath();
81 * Set validator to use when validating email address
83 * @param ValidatorInterface $validator
86 public function setValidator(ValidatorInterface
$validator)
88 $this->emailValidator
= $validator;
93 * Retrieve validator for use with validating email address
95 * If none is currently set, an EmailValidator instance with default options
98 * @return ValidatorInterface
100 public function getValidator()
102 if (null === $this->emailValidator
) {
103 $this->setValidator(new EmailValidator());
105 return $this->emailValidator
;