コード例 #1
0
ファイル: Request.php プロジェクト: pengzhile/purl
 /**
  * Request constructor.
  * @param string $method
  * @param UrlInfo $urlInfo
  * @param array $headers
  * @param array $posts
  */
 public function __construct($method, UrlInfo $urlInfo, array $headers = null, array $posts = null)
 {
     $this->method = $method;
     $this->scheme = $urlInfo->getScheme();
     $this->http = 'http' === $this->scheme;
     $this->https = 'https' === $this->scheme;
     $this->host = $urlInfo->getHost();
     $this->port = $urlInfo->getPort();
     $query = $urlInfo->getQuery();
     $this->uri = $urlInfo->getPath() . ($query ? '?' . $query : '');
     $posts && ($this->posts = $posts);
     if ($headers) {
         $this->headers = $headers + $this->headers;
     }
 }
コード例 #2
0
ファイル: AsyncClient.php プロジェクト: pengzhile/purl
 protected function add($method, $url, $callback, array $headers = null, array $data = null)
 {
     static $id = 0;
     ++$id;
     $info = new UrlInfo($url);
     $ip = Helper::host2ip($info->getHost());
     $parser = new Parser();
     if ('http' === $info->getScheme()) {
         $stream = new TCP($id, $ip, $info->getPort(), $parser);
     } elseif ('https' === $info->getScheme()) {
         $stream = new SSL($id, $info->getHost(), $ip, $info->getPort(), $parser, $this->connTimeout, $this->verifyCert);
     } else {
         throw new Exception('Unsupported url');
     }
     $stream->addRequest(new Request($method, $info, $headers, $data), $callback);
     $this->event->onWrite($stream->getResource(), array($this, 'sendCallback'), $stream, $this->connTimeout);
     return $id;
 }