3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Client { private $language = ''; private $hashing_key = ''; function __construct($hashing_key, $language='en-US') { $this->language = $language; $this->hashing_key = $hashing_key; } public function call($url, $method, $vars, $headers) { if (!array_key_exists('app_key', $headers)) $headers['app_key'] = $vars['app_key']; if (!array_key_exists('user_email', $headers)) $headers['user_email'] = $vars['user_email']; if (!array_key_exists('auth_token', $headers)) $headers['auth_token'] = ''; $headers['Accept-Language'] = $this->language; $headers['request_timestamp'] = gmdate('c'); $headers['request_body'] = $vars; $headers['request_url'] = $url; $headers['request_method'] = $method; $headers['api_signature'] = $this->get_signature($headers); $request_body = $this->encode_post_data($vars); $headers['request_body'] = $request_body; $url = $this->encode_query_string($url); $headers['request_url'] = $url; $curl = new Curl(); $curl->headers = $headers; $response = $curl->request(strtoupper($method), $url, $vars); $rv = array(); $rv['body'] = json_decode($response->body, true); $rv['headers'] = $response->headers; $rv['exception'] =$rv['body']['exception']; $rv['http_status_code'] = $rv['body']['http_status_code']; $rv['auth_token'] = $rv['body']['auth_token']; $rv['body'] = $rv['body']['body']; return $rv; } function encode_query_string($url) { $pos = strpos($url, '?',0); if ($pos !== false) { $qs = substr($url,$pos+1); $qs = rawurlencode(urldecode($qs)); $url = substr($url,0, $pos+1) . $qs; } return $url; } function encode_post_data($vars) { $request_body = ''; if ($vars) { foreach ($vars AS $key=>$value) { if (is_array($value)) $request_body .= $this->urlencode_array($value, $key).'&'; else $request_body .= $key.'='.$value.'&'; } $request_body = rtrim($request_body, '&'); } return $request_body; } function get_signature($vars) { $key = $this->hashing_key; $message = $vars['auth_token'] . $vars['app_key'] . $vars['user_email'] . $vars['request_timestamp'] . $this->encode_post_data($vars['request_body']) .$this->encode_query_string($vars['request_url']) . $vars['request_method']; return base64_encode(hash_hmac('sha512', $message, hash('sha512', $this->hashing_key))); } function urlencode_array($var, $varName, $separator = '&') { $toImplode = array(); foreach ($var as $key => $value) { if (is_array($value)) $toImplode[] = urlencode_array($value, "{$varName}[{$key}]", $separator); else $toImplode[] = "{$varName}[{$key}]=".rawurlencode(urldecode($value)); } return implode($separator, $toImplode); } } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WMGv7
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  111     0  E > > RETURN                                                   1

Class Client:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WMGv7
function name:  __construct
number of ops:  7
compiled vars:  !0 = $hashing_key, !1 = $language
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'en-US'
   10     2        ASSIGN_OBJ                                               'language'
          3        OP_DATA                                                  !1
   11     4        ASSIGN_OBJ                                               'hashing_key'
          5        OP_DATA                                                  !0
   12     6      > RETURN                                                   null

End of function __construct

Function call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
Branch analysis from position: 16
Branch analysis from position: 10
filename:       /in/WMGv7
function name:  call
number of ops:  95
compiled vars:  !0 = $url, !1 = $method, !2 = $vars, !3 = $headers, !4 = $request_body, !5 = $curl, !6 = $response, !7 = $rv
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   16     4        ARRAY_KEY_EXISTS                                 ~8      'app_key', !3
          5        BOOL_NOT                                         ~9      ~8
          6      > JMPZ                                                     ~9, ->10
   17     7    >   FETCH_DIM_R                                      ~11     !2, 'app_key'
          8        ASSIGN_DIM                                               !3, 'app_key'
          9        OP_DATA                                                  ~11
   19    10    >   ARRAY_KEY_EXISTS                                 ~12     'user_email', !3
         11        BOOL_NOT                                         ~13     ~12
         12      > JMPZ                                                     ~13, ->16
   20    13    >   FETCH_DIM_R                                      ~15     !2, 'user_email'
         14        ASSIGN_DIM                                               !3, 'user_email'
         15        OP_DATA                                                  ~15
   23    16    >   ARRAY_KEY_EXISTS                                 ~16     'auth_token', !3
         17        BOOL_NOT                                         ~17     ~16
         18      > JMPZ                                                     ~17, ->21
   24    19    >   ASSIGN_DIM                                               !3, 'auth_token'
         20        OP_DATA                                                  ''
   26    21    >   FETCH_OBJ_R                                      ~20     'language'
         22        ASSIGN_DIM                                               !3, 'Accept-Language'
         23        OP_DATA                                                  ~20
   27    24        INIT_FCALL                                               'gmdate'
         25        SEND_VAL                                                 'c'
         26        DO_ICALL                                         $22     
         27        ASSIGN_DIM                                               !3, 'request_timestamp'
         28        OP_DATA                                                  $22
   28    29        ASSIGN_DIM                                               !3, 'request_body'
         30        OP_DATA                                                  !2
   29    31        ASSIGN_DIM                                               !3, 'request_url'
         32        OP_DATA                                                  !0
   30    33        ASSIGN_DIM                                               !3, 'request_method'
         34        OP_DATA                                                  !1
   31    35        INIT_METHOD_CALL                                         'get_signature'
         36        SEND_VAR_EX                                              !3
         37        DO_FCALL                                      0  $27     
         38        ASSIGN_DIM                                               !3, 'api_signature'
         39        OP_DATA                                                  $27
   33    40        INIT_METHOD_CALL                                         'encode_post_data'
         41        SEND_VAR_EX                                              !2
         42        DO_FCALL                                      0  $28     
         43        ASSIGN                                                   !4, $28
   34    44        ASSIGN_DIM                                               !3, 'request_body'
         45        OP_DATA                                                  !4
   36    46        INIT_METHOD_CALL                                         'encode_query_string'
         47        SEND_VAR_EX                                              !0
         48        DO_FCALL                                      0  $31     
         49        ASSIGN                                                   !0, $31
   37    50        ASSIGN_DIM                                               !3, 'request_url'
         51        OP_DATA                                                  !0
   39    52        NEW                                              $34     'Curl'
         53        DO_FCALL                                      0          
         54        ASSIGN                                                   !5, $34
   40    55        ASSIGN_OBJ                                               !5, 'headers'
         56        OP_DATA                                                  !3
   41    57        INIT_METHOD_CALL                                         !5, 'request'
         58        INIT_FCALL                                               'strtoupper'
         59        SEND_VAR                                                 !1
         60        DO_ICALL                                         $38     
         61        SEND_VAR_NO_REF_EX                                       $38
         62        SEND_VAR_EX                                              !0
         63        SEND_VAR_EX                                              !2
         64        DO_FCALL                                      0  $39     
         65        ASSIGN                                                   !6, $39
   43    66        ASSIGN                                                   !7, <array>
   44    67        INIT_FCALL                                               'json_decode'
         68        FETCH_OBJ_R                                      ~43     !6, 'body'
         69        SEND_VAL                                                 ~43
         70        SEND_VAL                                                 <true>
         71        DO_ICALL                                         $44     
         72        ASSIGN_DIM                                               !7, 'body'
         73        OP_DATA                                                  $44
   45    74        FETCH_OBJ_R                                      ~46     !6, 'headers'
         75        ASSIGN_DIM                                               !7, 'headers'
         76        OP_DATA                                                  ~46
   47    77        FETCH_DIM_R                                      ~48     !7, 'body'
         78        FETCH_DIM_R                                      ~49     ~48, 'exception'
         79        ASSIGN_DIM                                               !7, 'exception'
         80        OP_DATA                                                  ~49
   48    81        FETCH_DIM_R                                      ~51     !7, 'body'
         82        FETCH_DIM_R                                      ~52     ~51, 'http_status_code'
         83        ASSIGN_DIM                                               !7, 'http_status_code'
         84        OP_DATA                                                  ~52
   49    85        FETCH_DIM_R                                      ~54     !7, 'body'
         86        FETCH_DIM_R                                      ~55     ~54, 'auth_token'
         87        ASSIGN_DIM                                               !7, 'auth_token'
         88        OP_DATA                                                  ~55
   51    89        FETCH_DIM_R                                      ~57     !7, 'body'
         90        FETCH_DIM_R                                      ~58     ~57, 'body'
         91        ASSIGN_DIM                                               !7, 'body'
         92        OP_DATA                                                  ~58
   53    93      > RETURN                                                   !7
   54    94*     > RETURN                                                   null

End of function call

Function encode_query_string:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 30
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/WMGv7
function name:  encode_query_string
number of ops:  32
compiled vars:  !0 = $url, !1 = $pos, !2 = $qs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   58     1        INIT_FCALL                                               'strpos'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%3F'
          4        SEND_VAL                                                 0
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !1, $3
   59     7        TYPE_CHECK                                  1018          !1
          8      > JMPZ                                                     ~5, ->30
   61     9    >   INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !0
         11        ADD                                              ~6      !1, 1
         12        SEND_VAL                                                 ~6
         13        DO_ICALL                                         $7      
         14        ASSIGN                                                   !2, $7
   62    15        INIT_FCALL                                               'rawurlencode'
         16        INIT_FCALL                                               'urldecode'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $9      
         19        SEND_VAR                                                 $9
         20        DO_ICALL                                         $10     
         21        ASSIGN                                                   !2, $10
   63    22        INIT_FCALL                                               'substr'
         23        SEND_VAR                                                 !0
         24        SEND_VAL                                                 0
         25        ADD                                              ~12     !1, 1
         26        SEND_VAL                                                 ~12
         27        DO_ICALL                                         $13     
         28        CONCAT                                           ~14     $13, !2
         29        ASSIGN                                                   !0, ~14
   65    30    > > RETURN                                                   !0
   66    31*     > RETURN                                                   null

End of function encode_query_string

Function encode_post_data:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 26
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 26
filename:       /in/WMGv7
function name:  encode_post_data
number of ops:  28
compiled vars:  !0 = $vars, !1 = $request_body, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   RECV                                             !0      
   70     1        ASSIGN                                                   !1, ''
   71     2      > JMPZ                                                     !0, ->26
   73     3    > > FE_RESET_R                                       $5      !0, ->20
          4    > > FE_FETCH_R                                       ~6      $5, !2, ->20
          5    >   ASSIGN                                                   !3, ~6
   75     6        TYPE_CHECK                                  128          !2
          7      > JMPZ                                                     ~8, ->15
   76     8    >   INIT_METHOD_CALL                                         'urlencode_array'
          9        SEND_VAR_EX                                              !2
         10        SEND_VAR_EX                                              !3
         11        DO_FCALL                                      0  $9      
         12        CONCAT                                           ~10     $9, '%26'
         13        ASSIGN_OP                                     8          !1, ~10
         14      > JMP                                                      ->19
   78    15    >   CONCAT                                           ~12     !3, '%3D'
         16        CONCAT                                           ~13     ~12, !2
         17        CONCAT                                           ~14     ~13, '%26'
         18        ASSIGN_OP                                     8          !1, ~14
   73    19    > > JMP                                                      ->4
         20    >   FE_FREE                                                  $5
   81    21        INIT_FCALL                                               'rtrim'
         22        SEND_VAR                                                 !1
         23        SEND_VAL                                                 '%26'
         24        DO_ICALL                                         $16     
         25        ASSIGN                                                   !1, $16
   84    26    > > RETURN                                                   !1
   85    27*     > RETURN                                                   null

End of function encode_post_data

Function get_signature:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WMGv7
function name:  get_signature
number of ops:  40
compiled vars:  !0 = $vars, !1 = $key, !2 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   RECV                                             !0      
   89     1        FETCH_OBJ_R                                      ~3      'hashing_key'
          2        ASSIGN                                                   !1, ~3
   90     3        FETCH_DIM_R                                      ~5      !0, 'auth_token'
          4        FETCH_DIM_R                                      ~6      !0, 'app_key'
          5        CONCAT                                           ~7      ~5, ~6
          6        FETCH_DIM_R                                      ~8      !0, 'user_email'
          7        CONCAT                                           ~9      ~7, ~8
          8        FETCH_DIM_R                                      ~10     !0, 'request_timestamp'
          9        CONCAT                                           ~11     ~9, ~10
         10        INIT_METHOD_CALL                                         'encode_post_data'
         11        CHECK_FUNC_ARG                                           
         12        FETCH_DIM_FUNC_ARG                               $12     !0, 'request_body'
         13        SEND_FUNC_ARG                                            $12
         14        DO_FCALL                                      0  $13     
         15        CONCAT                                           ~14     ~11, $13
         16        INIT_METHOD_CALL                                         'encode_query_string'
         17        CHECK_FUNC_ARG                                           
         18        FETCH_DIM_FUNC_ARG                               $15     !0, 'request_url'
         19        SEND_FUNC_ARG                                            $15
         20        DO_FCALL                                      0  $16     
         21        CONCAT                                           ~17     ~14, $16
         22        FETCH_DIM_R                                      ~18     !0, 'request_method'
         23        CONCAT                                           ~19     ~17, ~18
         24        ASSIGN                                                   !2, ~19
   91    25        INIT_FCALL                                               'base64_encode'
         26        INIT_FCALL                                               'hash_hmac'
         27        SEND_VAL                                                 'sha512'
         28        SEND_VAR                                                 !2
         29        INIT_FCALL                                               'hash'
         30        SEND_VAL                                                 'sha512'
         31        FETCH_OBJ_R                                      ~21     'hashing_key'
         32        SEND_VAL                                                 ~21
         33        DO_ICALL                                         $22     
         34        SEND_VAR                                                 $22
         35        DO_ICALL                                         $23     
         36        SEND_VAR                                                 $23
         37        DO_ICALL                                         $24     
         38      > RETURN                                                   $24
   93    39*     > RETURN                                                   null

End of function get_signature

Function urlencode_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 35
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 35
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 21
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/WMGv7
function name:  urlencode_array
number of ops:  42
compiled vars:  !0 = $var, !1 = $varName, !2 = $separator, !3 = $toImplode, !4 = $value, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   95     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      '%26'
   97     3        ASSIGN                                                   !3, <array>
   98     4      > FE_RESET_R                                       $7      !0, ->35
          5    > > FE_FETCH_R                                       ~8      $7, !4, ->35
          6    >   ASSIGN                                                   !5, ~8
  100     7        TYPE_CHECK                                  128          !4
          8      > JMPZ                                                     ~10, ->21
  101     9    >   INIT_FCALL_BY_NAME                                       'urlencode_array'
         10        SEND_VAR_EX                                              !4
         11        ROPE_INIT                                     4  ~13     !1
         12        ROPE_ADD                                      1  ~13     ~13, '%5B'
         13        ROPE_ADD                                      2  ~13     ~13, !5
         14        ROPE_END                                      3  ~12     ~13, '%5D'
         15        SEND_VAL_EX                                              ~12
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0  $15     
         18        ASSIGN_DIM                                               !3
         19        OP_DATA                                                  $15
         20      > JMP                                                      ->34
  103    21    >   ROPE_INIT                                     4  ~18     !1
         22        ROPE_ADD                                      1  ~18     ~18, '%5B'
         23        ROPE_ADD                                      2  ~18     ~18, !5
         24        ROPE_END                                      3  ~17     ~18, '%5D%3D'
         25        INIT_FCALL                                               'rawurlencode'
         26        INIT_FCALL                                               'urldecode'
         27        SEND_VAR                                                 !4
         28        DO_ICALL                                         $20     
         29        SEND_VAR                                                 $20
         30        DO_ICALL                                         $21     
         31        CONCAT                                           ~22     ~17, $21
         32        ASSIGN_DIM                                               !3
         33        OP_DATA                                                  ~22
   98    34    > > JMP                                                      ->5
         35    >   FE_FREE                                                  $7
  105    36        INIT_FCALL                                               'implode'
         37        SEND_VAR                                                 !2
         38        SEND_VAR                                                 !3
         39        DO_ICALL                                         $23     
         40      > RETURN                                                   $23
  106    41*     > RETURN                                                   null

End of function urlencode_array

End of class Client.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.99 ms | 1420 KiB | 37 Q