3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); /* * This file is part of Guzzle Factory. * * (c) Graham Campbell <graham@alt-three.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace GrahamCampbell\GuzzleFactory; use GuzzleHttp\Client; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\TransferException; use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; /** * This is the guzzle factory class. * * @author Graham Campbell <graham@alt-three.com> */ final class GuzzleFactory { /** * The default connect timeout. * * @var int */ const CONNECT_TIMEOUT = 10; /** * The default connect timeout. * * @var int */ const TIMEOUT = 15; /** * The default backoff multiplier. * * @var int */ const BACKOFF = 1000; /** * The default 4xx retry codes. * * @var int[] */ const CODES = [429]; /** * Create a new guzzle client. * * @param array $options * @param int|null $backoff * @param int[]|null $codes * * @return \GuzzleHttp\Client */ public static function make(array $options = [], int $backoff = null, array $codes = null) { return new Client(array_merge(['handler' => self::handler($backoff, $codes), 'connect_timeout' => self::CONNECT_TIMEOUT, 'timeout' => self::TIMEOUT], $options)); } /** * Create a new guzzle handler stack. * * @param int|null $backoff * @param int[]|null $codes * * @return \GuzzleHttp\Client */ public static function handler(int $backoff = null, array $codes = null) { $stack = HandlerStack::create(); $stack->push(Middleware::retry(function ($retries, RequestInterface $request, ResponseInterface $response = null, TransferException $exception = null) { return $retries < 3 && ($exception instanceof ConnectException || ($response && ($response->getStatusCode() >= 500 || in_array($codes === null ? self::CODES : $codes, $response->getStatusCode())))); }, function ($retries) use ($backoff) { return (int) pow(2, $retries) * ($backoff === null ? self::BACKOFF : $backoff); })); return $stack; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hhQOV
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   93     0  E > > RETURN                                                   1

Function %00grahamcampbell%5Cguzzlefactory%5C%7Bclosure%7D%2Fin%2FhhQOV%3A85%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 29
Branch analysis from position: 6
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 28
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 27
Branch analysis from position: 9
2 jumps found. (Code = 47) Position 1 = 13, Position 2 = 26
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 27
Branch analysis from position: 28
Branch analysis from position: 29
filename:       /in/hhQOV
function name:  GrahamCampbell\GuzzleFactory\{closure}
number of ops:  31
compiled vars:  !0 = $retries, !1 = $request, !2 = $response, !3 = $exception, !4 = $codes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
          3        RECV_INIT                                        !3      null
   86     4        IS_SMALLER                                       ~5      !0, 3
          5      > JMPZ_EX                                          ~5      ~5, ->29
          6    >   INSTANCEOF                                       ~6      !3, 'GuzzleHttp%5CException%5CConnectException'
          7      > JMPNZ_EX                                         ~6      ~6, ->28
          8    > > JMPZ_EX                                          ~7      !2, ->27
          9    >   INIT_METHOD_CALL                                         !2, 'getStatusCode'
         10        DO_FCALL                                      0  $8      
         11        IS_SMALLER_OR_EQUAL                              ~9      500, $8
         12      > JMPNZ_EX                                         ~9      ~9, ->26
         13    >   INIT_NS_FCALL_BY_NAME                                    'GrahamCampbell%5CGuzzleFactory%5Cin_array'
         14        TYPE_CHECK                                    2          !4
         15      > JMPZ                                                     ~10, ->19
         16    >   FETCH_CLASS_CONSTANT                             ~11     'CODES'
         17        QM_ASSIGN                                        ~12     ~11
         18      > JMP                                                      ->20
         19    >   QM_ASSIGN                                        ~12     !4
         20    >   SEND_VAL_EX                                              ~12
         21        INIT_METHOD_CALL                                         !2, 'getStatusCode'
         22        DO_FCALL                                      0  $13     
         23        SEND_VAR_NO_REF_EX                                       $13
         24        DO_FCALL                                      0  $14     
         25        BOOL                                             ~9      $14
         26    >   BOOL                                             ~7      ~9
         27    >   BOOL                                             ~6      ~7
         28    >   BOOL                                             ~5      ~6
         29    > > RETURN                                                   ~5
   87    30*     > RETURN                                                   null

End of function %00grahamcampbell%5Cguzzlefactory%5C%7Bclosure%7D%2Fin%2FhhQOV%3A85%240

Function %00grahamcampbell%5Cguzzlefactory%5C%7Bclosure%7D%2Fin%2FhhQOV%3A87%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hhQOV
function name:  GrahamCampbell\GuzzleFactory\{closure}
number of ops:  16
compiled vars:  !0 = $retries, !1 = $backoff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
          0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   88     2        INIT_NS_FCALL_BY_NAME                                    'GrahamCampbell%5CGuzzleFactory%5Cpow'
          3        SEND_VAL_EX                                              2
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $2      
          6        CAST                                          4  ~3      $2
          7        TYPE_CHECK                                    2          !1
          8      > JMPZ                                                     ~4, ->12
          9    >   FETCH_CLASS_CONSTANT                             ~5      'BACKOFF'
         10        QM_ASSIGN                                        ~6      ~5
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~6      !1
         13    >   MUL                                              ~7      ~3, ~6
         14      > RETURN                                                   ~7
   89    15*     > RETURN                                                   null

End of function %00grahamcampbell%5Cguzzlefactory%5C%7Bclosure%7D%2Fin%2FhhQOV%3A87%241

Class GrahamCampbell\GuzzleFactory\GuzzleFactory:
Function make:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hhQOV
function name:  make
number of ops:  21
compiled vars:  !0 = $options, !1 = $backoff, !2 = $codes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   RECV_INIT                                        !0      <array>
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
   70     3        NEW                                              $3      'GuzzleHttp%5CClient'
          4        INIT_NS_FCALL_BY_NAME                                    'GrahamCampbell%5CGuzzleFactory%5Carray_merge'
          5        INIT_STATIC_METHOD_CALL                                  'handler'
          6        SEND_VAR_EX                                              !1
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0  $4      
          9        INIT_ARRAY                                       ~5      $4, 'handler'
         10        FETCH_CLASS_CONSTANT                             ~6      'CONNECT_TIMEOUT'
         11        ADD_ARRAY_ELEMENT                                ~5      ~6, 'connect_timeout'
         12        FETCH_CLASS_CONSTANT                             ~7      'TIMEOUT'
         13        ADD_ARRAY_ELEMENT                                ~5      ~7, 'timeout'
         14        SEND_VAL_EX                                              ~5
         15        SEND_VAR_EX                                              !0
         16        DO_FCALL                                      0  $8      
         17        SEND_VAR_NO_REF_EX                                       $8
         18        DO_FCALL                                      0          
         19      > RETURN                                                   $3
   71    20*     > RETURN                                                   null

End of function make

Function handler:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hhQOV
function name:  handler
number of ops:  17
compiled vars:  !0 = $backoff, !1 = $codes, !2 = $stack
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      null
   83     2        INIT_STATIC_METHOD_CALL                                  'GuzzleHttp%5CHandlerStack', 'create'
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !2, $3
   85     5        INIT_METHOD_CALL                                         !2, 'push'
          6        INIT_STATIC_METHOD_CALL                                  'GuzzleHttp%5CMiddleware', 'retry'
          7        DECLARE_LAMBDA_FUNCTION                                  '%00grahamcampbell%5Cguzzlefactory%5C%7Bclosure%7D%2Fin%2FhhQOV%3A85%240'
   87     8        SEND_VAL_EX                                              ~5
          9        DECLARE_LAMBDA_FUNCTION                                  '%00grahamcampbell%5Cguzzlefactory%5C%7Bclosure%7D%2Fin%2FhhQOV%3A87%241'
         10        BIND_LEXICAL                                             ~6, !0
   89    11        SEND_VAL_EX                                              ~6
         12        DO_FCALL                                      0  $7      
         13        SEND_VAR_NO_REF_EX                                       $7
         14        DO_FCALL                                      0          
   91    15      > RETURN                                                   !2
   92    16*     > RETURN                                                   null

End of function handler

End of class GrahamCampbell\GuzzleFactory\GuzzleFactory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.1 ms | 1408 KiB | 19 Q