mirror of https://github.com/MISP/MISP
chg: [connection] Allow to define onConnect callback
parent
f32c526bbe
commit
6159a74c88
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue