forked from solariumphp/solarium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomizedCurlTest.php
64 lines (53 loc) · 1.71 KB
/
CustomizedCurlTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Solarium\Tests\Integration\Proxy;
use Solarium\Core\Client\Adapter\Curl;
use Solarium\Core\Client\Endpoint;
use Solarium\Core\Client\Request;
use Solarium\Tests\Integration\TestClientFactory;
/**
* Test connecting through a proxy with a customized Curl adapter that sets the proxy options differently.
*
* @group integration
* @group proxy
*/
class CustomizedCurlTest extends CurlTest
{
protected static function createClient(): void
{
self::$client = TestClientFactory::createWithCurlAdapter(self::$config);
self::$client->setAdapter(new CustomizedCurl());
}
protected static function setProxy(): void
{
self::$client->getAdapter()->setProxy(['server' => self::$proxy_server, 'port' => self::$proxy_port]);
}
}
class CustomizedCurl extends Curl
{
protected $myProxyOptions;
/**
* Override to store custom options in our own property that doesn't trigger
* the {@see Curl} adapter's regular proxy handling.
*
* @param mixed|array $proxy An associative array with keys 'server' and 'port'
*
* @return self Provides fluent interface
*/
public function setProxy($proxy): self
{
$this->myProxyOptions = $proxy;
return $this;
}
public function getProxy()
{
return $this->myProxyOptions;
}
public function createHandle(Request $request, Endpoint $endpoint): \CurlHandle
{
$handle = parent::createHandle($request, $endpoint);
// add our own options to the cURL handle
curl_setopt($handle, CURLOPT_PROXY, $this->myProxyOptions['server']);
curl_setopt($handle, CURLOPT_PROXYPORT, $this->myProxyOptions['port']);
return $handle;
}
}