Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d064a2

Browse files
bug #35025 [HttpClient][Psr18Client] Remove Psr18ExceptionTrait (fancyweb)
This PR was merged into the 4.3 branch. Discussion ---------- [HttpClient][Psr18Client] Remove Psr18ExceptionTrait | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Interesting case. Declared trait are instantly loaded by PHP. When ClassExistenceResource fails to load this class because of a thrown \LogicException (when a dependency is missing, cf the top of this class) the trait is loaded. Then, to display the exception, this class is reaccessed (I guess by the duplicated request 🤔) and it results in a fatal error "Cannot redeclare trait...". Basically ClassExistenceResource does not support this kind of structure (thrown exception + trait). Let's do the easy fix first, and then revert if someone finds a fix for the root problem? Commits ------- c1746d8 [HttpClient][Psr18Client] Remove Psr18ExceptionTrait
2 parents bbf7ed1 + c1746d8 commit 4d064a2

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/Symfony/Component/HttpClient/Psr18Client.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function sendRequest(RequestInterface $request): ResponseInterface
105105
/**
106106
* @internal
107107
*/
108-
trait Psr18ExceptionTrait
108+
class Psr18NetworkException extends \RuntimeException implements NetworkExceptionInterface
109109
{
110110
private $request;
111111

@@ -121,18 +121,21 @@ public function getRequest(): RequestInterface
121121
}
122122
}
123123

124-
/**
125-
* @internal
126-
*/
127-
class Psr18NetworkException extends \RuntimeException implements NetworkExceptionInterface
128-
{
129-
use Psr18ExceptionTrait;
130-
}
131-
132124
/**
133125
* @internal
134126
*/
135127
class Psr18RequestException extends \InvalidArgumentException implements RequestExceptionInterface
136128
{
137-
use Psr18ExceptionTrait;
129+
private $request;
130+
131+
public function __construct(TransportExceptionInterface $e, RequestInterface $request)
132+
{
133+
parent::__construct($e->getMessage(), 0, $e);
134+
$this->request = $request;
135+
}
136+
137+
public function getRequest(): RequestInterface
138+
{
139+
return $this->request;
140+
}
138141
}

0 commit comments

Comments
 (0)