99use Elastica \Param ;
1010use Elastica \Request ;
1111use Elastica \Response ;
12+ use Psr \Log \LoggerInterface ;
1213
1314/**
1415 * Elastica Abstract Transport object.
@@ -22,14 +23,22 @@ abstract class AbstractTransport extends Param
2223 */
2324 protected $ _connection ;
2425
26+ /**
27+ * @var LoggerInterface
28+ */
29+ protected $ _logger ;
30+
2531 /**
2632 * Construct transport.
2733 */
28- public function __construct (?Connection $ connection = null )
34+ public function __construct (LoggerInterface $ logger , ?Connection $ connection = null )
2935 {
3036 if ($ connection ) {
3137 $ this ->setConnection ($ connection );
3238 }
39+ if ($ logger ) {
40+ $ this ->setLogger ($ logger );
41+ }
3342 }
3443
3544 public function getConnection (): Connection
@@ -47,6 +56,21 @@ public function setConnection(Connection $connection): AbstractTransport
4756 return $ this ;
4857 }
4958
59+ public function getLogger (): LoggerInterface
60+ {
61+ return $ this ->_logger ;
62+ }
63+
64+ /**
65+ * @return $this
66+ */
67+ public function setLogger (LoggerInterface $ logger ): AbstractTransport
68+ {
69+ $ this ->_logger = $ logger ;
70+
71+ return $ this ;
72+ }
73+
5074 /**
5175 * Executes the transport request.
5276 *
@@ -93,7 +117,7 @@ public function sanityzeQueryStringBool(array $query)
93117 *
94118 * @throws InvalidException
95119 */
96- public static function create ($ transport , Connection $ connection , array $ params = []): AbstractTransport
120+ public static function create ($ transport , Connection $ connection , array $ params = [], LoggerInterface $ logger = null ): AbstractTransport
97121 {
98122 if (\is_array ($ transport ) && isset ($ transport ['type ' ])) {
99123 $ transportParams = $ transport ;
@@ -113,7 +137,11 @@ public static function create($transport, Connection $connection, array $params
113137 $ classNames = ["Elastica \\Transport \\{$ transport }" , $ transport ];
114138 foreach ($ classNames as $ className ) {
115139 if (\class_exists ($ className )) {
116- $ transport = new $ className ();
140+ if ($ transport === 'Http ' ) {
141+ $ transport = new $ className ($ logger , $ connection );
142+ } else {
143+ $ transport = new $ className ();
144+ }
117145 break ;
118146 }
119147 }
0 commit comments