Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #30967 [HttpClient] Document the state object that is passed arou…
…nd by the HttpClient (derrabus) This PR was merged into the 4.3-dev branch. Discussion ---------- [HttpClient] Document the state object that is passed around by the HttpClient | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A In an attempt to make the code of the new HttpClient component more understandable, I've introduced internal classes that document the `$multi` object that is being passed around between *Client and *Response classes. My goal is to make the code more accessible to potential contributors and static code analyzers. Commits ------- 20f4eb3 Document the state object that is passed around by the HttpClient.
- Loading branch information
Showing
11 changed files
with
240 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpClient\Internal; | ||
|
||
/** | ||
* Internal representation of the client state. | ||
* | ||
* @author Alexander M. Turek <me@derrabus.de> | ||
* | ||
* @internal | ||
*/ | ||
class ClientState | ||
{ | ||
public $handlesActivity = []; | ||
public $openHandles = []; | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Symfony/Component/HttpClient/Internal/CurlClientState.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpClient\Internal; | ||
|
||
/** | ||
* Internal representation of the cURL client's state. | ||
* | ||
* @author Alexander M. Turek <me@derrabus.de> | ||
* | ||
* @internal | ||
*/ | ||
final class CurlClientState extends ClientState | ||
{ | ||
/** @var resource */ | ||
public $handle; | ||
/** @var PushedResponse[] */ | ||
public $pushedResponses = []; | ||
/** @var DnsCache */ | ||
public $dnsCache; | ||
|
||
public function __construct() | ||
{ | ||
$this->handle = curl_multi_init(); | ||
$this->dnsCache = new DnsCache(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpClient\Internal; | ||
|
||
/** | ||
* Cache for resolved DNS queries. | ||
* | ||
* @author Alexander M. Turek <me@derrabus.de> | ||
* | ||
* @internal | ||
*/ | ||
final class DnsCache | ||
{ | ||
/** | ||
* Resolved hostnames (hostname => IP address). | ||
* | ||
* @var string[] | ||
*/ | ||
public $hostnames = []; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
public $removals = []; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
public $evictions = []; | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Symfony/Component/HttpClient/Internal/NativeClientState.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpClient\Internal; | ||
|
||
use Symfony\Component\HttpClient\Response\NativeResponse; | ||
|
||
/** | ||
* Internal representation of the native client's state. | ||
* | ||
* @author Alexander M. Turek <me@derrabus.de> | ||
* | ||
* @internal | ||
*/ | ||
final class NativeClientState extends ClientState | ||
{ | ||
/** @var int */ | ||
public $id; | ||
/** @var NativeResponse[] */ | ||
public $pendingResponses = []; | ||
/** @var int */ | ||
public $maxHostConnections = PHP_INT_MAX; | ||
/** @var int */ | ||
public $responseCount = 0; | ||
/** @var string[] */ | ||
public $dnsCache = []; | ||
/** @var resource[] */ | ||
public $handles = []; | ||
/** @var bool */ | ||
public $sleep = false; | ||
|
||
public function __construct() | ||
{ | ||
$this->id = random_int(PHP_INT_MIN, PHP_INT_MAX); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Symfony/Component/HttpClient/Internal/PushedResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpClient\Internal; | ||
|
||
use Symfony\Component\HttpClient\Response\CurlResponse; | ||
|
||
/** | ||
* A pushed response with headers. | ||
* | ||
* @author Alexander M. Turek <me@derrabus.de> | ||
* | ||
* @internal | ||
*/ | ||
final class PushedResponse | ||
{ | ||
/** @var CurlResponse */ | ||
public $response; | ||
|
||
/** @var string[] */ | ||
public $headers; | ||
|
||
public function __construct(CurlResponse $response, array $headers) | ||
{ | ||
$this->response = $response; | ||
$this->headers = $headers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.