コード例 #1
0
ファイル: Socket.php プロジェクト: versionable/prospect
 public function call(RequestInterface $request, ResponseInterface $response)
 {
     $handle = \fsockopen($request->getUrl()->getHostname(), $request->getPort(), $errno, $errstr, 30);
     if (!$handle) {
         throw new \RuntimeException('Error connecting to host: ' . $request->getUrl()->getHostname());
     }
     $string = '';
     if ($handle) {
         $builder = new StringBuilder();
         $builder->setRequest($request);
         fputs($handle, $builder->toString());
         while (false === feof($handle)) {
             $string .= fgets($handle, 1024);
         }
     }
     $response->parse($string);
     fclose($handle);
     if ($response->getCode() == 301) {
         $response->getHeaders()->get('Location')->getValue();
         $request->getUrl()->setUrl($response->getHeaders()->get('Location')->getValue());
         $request->setCookies($response->getCookies());
         $class = \get_class($response);
         $response = $this->call($request, new $class());
     }
     return $response;
 }
コード例 #2
0
 public function test__toString()
 {
     $request = new Request();
     $request->setUrl(new Url('http://www.versionable.co.uk'));
     $this->object->setRequest($request);
     $this->assertEquals($this->object->toString(), (string) $this->object);
 }