getDefinition() public method

Get the grammar defined for $name token.
public getDefinition ( string $name ) : string
$name string exactly as written in the RFC
return string
Esempio n. 1
0
 /**
  * Checks if an email matches the current grammars
  * @param string $email
  */
 public static function email($email)
 {
     if (self::$grammar === null) {
         self::$grammar = Swift_DependencyContainer::getInstance()->lookup('mime.grammar');
     }
     return preg_match('/^' . self::$grammar->getDefinition('addr-spec') . '$/D', $email);
 }
Esempio n. 2
0
 /**
  * Validates a given address to ensure RFC 2822, 3.6.2 specs
  *
  * @param $address
  *
  * @throws \Swift_RfcComplianceException
  */
 public static function validateEmail($address)
 {
     static $grammer;
     if ($grammer === null) {
         $grammer = new \Swift_Mime_Grammar();
     }
     if (!preg_match('/^' . $grammer->getDefinition('addr-spec') . '$/D', $address)) {
         throw new \Swift_RfcComplianceException('Address in mailbox given [' . $address . '] does not comply with RFC 2822, 3.6.2.');
     }
 }