示例#1
0
文件: URITest.php 项目: mast3rpee/blw
 /**
  * @depends test_construct
  * @covers ::getIterator
  */
 public function test_getIterator()
 {
     $count = 0;
     $this->assertInstanceOf('Traversable', $this->URI->getIterator(), 'IURI::getIterator() Returned an invalid result');
     foreach ($this->URI as $v) {
         $count++;
     }
     $this->assertSame(count($this->URI), $count, 'IEmailAddress::getIterator() Returned an invalid result');
 }
示例#2
0
文件: Helper.php 项目: mast3rpee/blw
 /**
  * Perform a request and update $FreeHandles.
  *
  * @link http://www.php.net/manual/en/function.curl-setopt-array.php curl_setopt_array()
  * @link http://www.php.net/manual/en/function.curl-setopt.php curl_multi_add_handle()
  *
  * @throws \RuntimeException If there is a cURL error.
  * @throws \BLW\Model\InvalidArgumentException If <code>$Handle</code> is not a valid resource.
  *
  * @param resource $Handle
  *            Resource from <code>curl_init()</code> stored in <code>$Handles</code>.
  * @param array $Options
  *            Options passed to <code>curl_setopt_array()</code>
  * @return boolean <code>TRUE</code> on success. <code>FALSE</code> otherwise.
  */
 public function execute($Handle, array $Options)
 {
     // Validate $Handle
     if (!is_resource($Handle) ?: !in_array($Handle, $this->FreeHandles)) {
         throw new InvalidArgumentException(0);
     } elseif (!($result = @curl_setopt_array($Handle, $Options))) {
         throw new RuntimeException('Unable to set cURL options', curl_errno($Handle));
     }
     // Add handle
     $result = curl_multi_add_handle($this->MainHandle, $Handle);
     // Check results
     if ($result == 0) {
         // Remove handle from free list
         $this->FreeHandles = array_filter($this->FreeHandles, function ($v) use($Handle) {
             return $v != $Handle;
         });
         // Update Stats
         // 1. NewConnections
         $this->Stats['NewConnections'][] = new DateTime();
         // 2. HostConnections
         if (isset($Options[CURLOPT_URL])) {
             $Host = AURI::parse($Options[CURLOPT_URL]);
             $Host = $Host['host'];
             // Stats exist? Update
             if (isset($this->Stats['HostConnections'][$Host])) {
                 $this->Stats['HostConnections'][$Host][] = $Handle;
                 // No stats? Create
             } else {
                 $this->Stats['HostConnections'][$Host] = array($Handle);
             }
         }
         // Done
         return true;
         // @codeCoverageIgnoreStart
         // Unable to add
     } else {
         // Exception
         throw new RuntimeException(sprintf('Error [%d]: Unable to add curl request (%s)', $result, curl_error($Handle)), $result);
     }
     // @codeCoverageIgnoreEnd
 }
示例#3
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);
 }