chg: [connection] Allow to define onConnect callback

pull/8105/head
Jakub Onderka 2022-01-20 18:30:36 +01:00
parent f32c526bbe
commit 6159a74c88
1 changed files with 23 additions and 0 deletions

View File

@ -128,6 +128,9 @@ class HttpSocketExtended extends HttpSocket
{
public $responseClass = 'HttpSocketResponseExtended';
/** @var callable */
private $onConnect;
public function __construct($config = array())
{
parent::__construct($config);
@ -139,6 +142,26 @@ class HttpSocketExtended extends HttpSocket
}
}
public function connect()
{
$connected = parent::connect();
if ($this->onConnect) {
$handler = $this->onConnect;
$handler($this);
}
return $connected;
}
/**
* Set callback method, that will be called after connection to remote server is established.
* @param callable $callback
* @return void
*/
public function onConnectHandler(callable $callback)
{
$this->onConnect = $callback;
}
/**
* @param array $request
* @return HttpSocketResponseExtended