composer package updates
[openemr.git] / vendor / zendframework / zend-uri / src / Mailto.php
blob34ccadab87ff0d987a6d88dea83aa6316cb1914a
1 <?php
2 /**
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
6 */
8 namespace Zend\Uri;
10 use Zend\Validator\EmailAddress as EmailValidator;
11 use Zend\Validator\ValidatorInterface;
13 /**
14 * "Mailto" URI handler
16 * The 'mailto:...' scheme is loosely defined in RFC-1738
18 class Mailto extends Uri
20 protected static $validSchemes = ['mailto'];
22 /**
23 * Validator for use when validating email address
24 * @var ValidatorInterface
26 protected $emailValidator;
28 /**
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
34 * @return bool
35 * @see Uri::isValid()
37 public function isValid()
39 if ($this->host || $this->userInfo || $this->port) {
40 return false;
43 if (empty($this->path)) {
44 return false;
47 if (0 === strpos($this->path, '/')) {
48 return false;
51 $validator = $this->getValidator();
52 return $validator->isValid($this->path);
55 /**
56 * Set the email address
58 * This is in fact equivalent to setPath() - but provides a more clear interface
60 * @param string $email
61 * @return Mailto
63 public function setEmail($email)
65 return $this->setPath($email);
68 /**
69 * Get the email address
71 * This is infact equivalent to getPath() - but provides a more clear interface
73 * @return string
75 public function getEmail()
77 return $this->getPath();
80 /**
81 * Set validator to use when validating email address
83 * @param ValidatorInterface $validator
84 * @return Mailto
86 public function setValidator(ValidatorInterface $validator)
88 $this->emailValidator = $validator;
89 return $this;
92 /**
93 * Retrieve validator for use with validating email address
95 * If none is currently set, an EmailValidator instance with default options
96 * will be used.
98 * @return ValidatorInterface
100 public function getValidator()
102 if (null === $this->emailValidator) {
103 $this->setValidator(new EmailValidator());
105 return $this->emailValidator;