This curl adapter provides the required method implementations of the abstract Socket class for open, close, read, write, timeout eof and encoding. Your PHP installation must have been compiled with the --with-curl[=DIR] directive. If this is not the case, you must either recompile PHP with the proper configuration flags to enable curl, or you may use the Stream adapter that is also included with the Lithium core.
See also: lithium\net\socket\Stream
Inheritance: extends lithium\net\Socket
Exemplo n.º 1
0
 public function testCurlAdapter()
 {
     $socket = new Curl($this->_testConfig);
     $this->assertTrue($socket->open());
     $response = $socket->send();
     $this->assertTrue($response instanceof \lithium\net\http\Response);
     $expected = 'www.google.com';
     $result = $response->host;
     $this->assertEqual($expected, $result);
     $result = $response->body();
     $this->assertPattern("/<title[^>]*>Google<\\/title>/im", (string) $result);
 }
Exemplo n.º 2
0
 public function testCurlAdapter()
 {
     $message = 'Your PHP installation was not compiled with curl support.';
     $this->skipIf(!function_exists('curl_init'), $message);
     $socket = new Curl($this->_testConfig);
     $this->assertTrue($socket->open());
     $response = $socket->send();
     $this->assertTrue($response instanceof Response);
     $expected = 'google.com';
     $result = $response->host;
     $this->assertEqual($expected, $result);
     $result = $response->body();
     $this->assertPattern("/<title[^>]*>.*<\\/title>/im", (string) $result);
 }
Exemplo n.º 3
0
 public function testWriteAndRead()
 {
     $stream = new Curl($this->_testConfig);
     $this->assertTrue(is_resource($stream->open()));
     $this->assertTrue(is_resource($stream->resource()));
     $stream->set(CURLOPT_URL, $this->_testUrl);
     $this->assertTrue($stream->write(null));
     $this->assertTrue($stream->read());
     $response = $stream->send(new Request(), array('response' => 'lithium\\net\\http\\Response'));
     $this->assertEqual(trim(file_get_contents($this->_testUrl)), trim($response->body()));
     $this->assertNull($stream->eof());
 }
Exemplo n.º 4
0
 public function testSendWithObject()
 {
     $stream = new Curl($this->_testConfig);
     $this->assertTrue(is_resource($stream->open()));
     $result = $stream->send(new Request($this->_testConfig), array('response' => 'lithium\\net\\http\\Response'));
     $this->assertTrue($result instanceof \lithium\net\http\Response);
     $this->assertPattern("/^HTTP/", (string) $result);
 }
Exemplo n.º 5
0
 public function testCurlAdapter()
 {
     $socket = new Curl($this->_testConfig);
     $this->assertNotEmpty($socket->open());
     $response = $socket->send();
     $this->assertInstanceOf('lithium\\net\\http\\Response', $response);
     $expected = 'example.org';
     $result = $response->host;
     $this->assertEqual($expected, $result);
     $result = $response->body();
     $this->assertPattern("/<title[^>]*>Example Domain<\\/title>/im", (string) $result);
 }
Exemplo n.º 6
0
 public function testSendPostThenGet()
 {
     $postConfig = array('method' => 'POST', 'body' => '{"body"}');
     $stream = new Curl($this->_testConfig);
     $this->assertTrue(is_resource($stream->open()));
     $this->assertTrue($stream->write(new Request($postConfig + $this->_testConfig)));
     $this->assertTrue(isset($stream->options[CURLOPT_POST]));
     $this->assertTrue($stream->close());
     $this->assertTrue(is_resource($stream->open()));
     $this->assertTrue($stream->write(new Request($this->_testConfig)));
     $this->assertFalse(isset($stream->options[CURLOPT_POST]));
     $this->assertTrue($stream->close());
 }
Exemplo n.º 7
0
 public function close()
 {
     $this->closed = parent::close();
     return true;
 }
Exemplo n.º 8
0
 public function testSendPutThenGet()
 {
     $postConfig = array('method' => 'PUT', 'body' => '{"body"}');
     $stream = new Curl($this->_testConfig);
     $this->assertTrue(is_resource($stream->open()));
     $this->assertTrue($stream->write(new Request($postConfig + $this->_testConfig)));
     $this->assertTrue(isset($stream->options[CURLOPT_CUSTOMREQUEST]));
     $this->assertEqual($stream->options[CURLOPT_CUSTOMREQUEST], 'PUT');
     $this->assertTrue(isset($stream->options[CURLOPT_POSTFIELDS]));
     $this->assertEqual($stream->options[CURLOPT_POSTFIELDS], $postConfig['body']);
     $this->assertTrue($stream->close());
     $this->assertTrue(is_resource($stream->open()));
     $this->assertTrue($stream->write(new Request($this->_testConfig)));
     $this->assertFalse(isset($stream->options[CURLOPT_CUSTOMREQUEST]));
     $this->assertTrue($stream->close());
 }