Beispiel #1
0
 /**
  * @covers ::parseTLD
  */
 public function test_parseTLD()
 {
     # Valid input
     foreach ($this->generateTLDs() as $Arguments) {
         list($Input, $Expected) = $Arguments;
         $this->assertSame($Expected, $this->URI->parseTLD($Input), sprintf('IURI::parseTLD(%s) returned an invalid value', $Input));
     }
     # Invalid input
     $this->assertSame(false, $this->URI->parseTLD(NULL), 'IURI::parseTLD(NULL) returned an invalid value');
     try {
         $this->assertSame(false, $this->URI->parseTLD(array()), 'IURI::parseTLD(array()) returned an invalid value');
         $this->fail('Failed to generate warning with invalid parameter');
     } catch (\PHPUnit_Framework_Error_Warning $e) {
     }
 }
Beispiel #2
0
 /**
  * Parse email address into various components.
  *
  * @uses \BLW\Type\AURL::parseTLD() AURL::parseTLD()
  *
  * @param string $Address
  *            Email address to parse.
  * @param string $Personal
  *            Owner of email address
  * @return array Parsed parts:
  *
  * <ul>
  * <li><b>Personal</b>:</li>
  * <li><b>Local</b>:</li>
  * <li><b>Domain</b>:</li>
  * <li><b>TLD</b>:</li>
  * <li><b>LocalAtom</b>:</li>
  * <li><b>LocalQuoted</b>:</li>
  * <li><b>LocalObs</b>:</li>
  * <li><b>DomainAtom</b>:</li>
  * <li><b>DomainLiteral</b>:</li>
  * <li><b>DomainObs</b>:</li>
  * </ul>
  */
 public function parse($Address, $Personal = '')
 {
     $Parts = array();
     // Address
     if (preg_match('!^' . $this->getRegex() . '$!', @strval($Address), $m)) {
         $Parts['Address'] = isset($m[0]) ? $m[0] : '';
         $Parts['Local'] = isset($m[1]) ? $m[1] : '';
         $Parts['LocalAtom'] = isset($m[2]) ? $m[2] : '';
         $Parts['LocalQuoted'] = isset($m[3]) ? $m[3] : '';
         $Parts['LocalObs'] = isset($m[4]) ? $m[4] : '';
         $Parts['Domain'] = isset($m[5]) ? $m[5] : '';
         $Parts['DomainAtom'] = isset($m[6]) ? $m[6] : '';
         $Parts['DomainLiteral'] = isset($m[7]) ? $m[7] : '';
         $Parts['DomainObs'] = isset($m[8]) ? $m[8] : '';
     }
     // Personal
     $Parts['Personal'] = trim(substr(str_replace(array('\\xa', '\\xd'), ' ', @strval($Personal)), 0, 63));
     // TLD
     if (!empty($Parts['Domain']) ? empty($Parts['DomainLiteral']) : false) {
         $Parts['TLD'] = AURI::parseTLD($Parts['Domain']);
     }
     // Done
     return array_merge(self::$_Default, $Parts);
 }