3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Grada\REST; use \Grada\REST\Curl; 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/R5T0P
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  114     0  E > > RETURN                                                   1

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

End of function __construct

Function call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 22
Branch analysis from position: 13
filename:       /in/R5T0P
function name:  call
number of ops:  105
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
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   19     4        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Carray_key_exists'
          5        SEND_VAL_EX                                              'app_key'
          6        SEND_VAR_EX                                              !3
          7        DO_FCALL                                      0  $8      
          8        BOOL_NOT                                         ~9      $8
          9      > JMPZ                                                     ~9, ->13
   20    10    >   FETCH_DIM_R                                      ~11     !2, 'app_key'
         11        ASSIGN_DIM                                               !3, 'app_key'
         12        OP_DATA                                                  ~11
   22    13    >   INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Carray_key_exists'
         14        SEND_VAL_EX                                              'user_email'
         15        SEND_VAR_EX                                              !3
         16        DO_FCALL                                      0  $12     
         17        BOOL_NOT                                         ~13     $12
         18      > JMPZ                                                     ~13, ->22
   23    19    >   FETCH_DIM_R                                      ~15     !2, 'user_email'
         20        ASSIGN_DIM                                               !3, 'user_email'
         21        OP_DATA                                                  ~15
   26    22    >   INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Carray_key_exists'
         23        SEND_VAL_EX                                              'auth_token'
         24        SEND_VAR_EX                                              !3
         25        DO_FCALL                                      0  $16     
         26        BOOL_NOT                                         ~17     $16
         27      > JMPZ                                                     ~17, ->30
   27    28    >   ASSIGN_DIM                                               !3, 'auth_token'
         29        OP_DATA                                                  ''
   29    30    >   FETCH_OBJ_R                                      ~20     'language'
         31        ASSIGN_DIM                                               !3, 'Accept-Language'
         32        OP_DATA                                                  ~20
   30    33        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Cgmdate'
         34        SEND_VAL_EX                                              'c'
         35        DO_FCALL                                      0  $22     
         36        ASSIGN_DIM                                               !3, 'request_timestamp'
         37        OP_DATA                                                  $22
   31    38        ASSIGN_DIM                                               !3, 'request_body'
         39        OP_DATA                                                  !2
   32    40        ASSIGN_DIM                                               !3, 'request_url'
         41        OP_DATA                                                  !0
   33    42        ASSIGN_DIM                                               !3, 'request_method'
         43        OP_DATA                                                  !1
   34    44        INIT_METHOD_CALL                                         'get_signature'
         45        SEND_VAR_EX                                              !3
         46        DO_FCALL                                      0  $27     
         47        ASSIGN_DIM                                               !3, 'api_signature'
         48        OP_DATA                                                  $27
   36    49        INIT_METHOD_CALL                                         'encode_post_data'
         50        SEND_VAR_EX                                              !2
         51        DO_FCALL                                      0  $28     
         52        ASSIGN                                                   !4, $28
   37    53        ASSIGN_DIM                                               !3, 'request_body'
         54        OP_DATA                                                  !4
   39    55        INIT_METHOD_CALL                                         'encode_query_string'
         56        SEND_VAR_EX                                              !0
         57        DO_FCALL                                      0  $31     
         58        ASSIGN                                                   !0, $31
   40    59        ASSIGN_DIM                                               !3, 'request_url'
         60        OP_DATA                                                  !0
   42    61        NEW                                              $34     'Grada%5CREST%5CCurl'
         62        DO_FCALL                                      0          
         63        ASSIGN                                                   !5, $34
   43    64        ASSIGN_OBJ                                               !5, 'headers'
         65        OP_DATA                                                  !3
   44    66        INIT_METHOD_CALL                                         !5, 'request'
         67        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Cstrtoupper'
         68        SEND_VAR_EX                                              !1
         69        DO_FCALL                                      0  $38     
         70        SEND_VAR_NO_REF_EX                                       $38
         71        SEND_VAR_EX                                              !0
         72        SEND_VAR_EX                                              !2
         73        DO_FCALL                                      0  $39     
         74        ASSIGN                                                   !6, $39
   46    75        ASSIGN                                                   !7, <array>
   47    76        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Cjson_decode'
         77        CHECK_FUNC_ARG                                           
         78        FETCH_OBJ_FUNC_ARG                               $43     !6, 'body'
         79        SEND_FUNC_ARG                                            $43
         80        SEND_VAL_EX                                              <true>
         81        DO_FCALL                                      0  $44     
         82        ASSIGN_DIM                                               !7, 'body'
         83        OP_DATA                                                  $44
   48    84        FETCH_OBJ_R                                      ~46     !6, 'headers'
         85        ASSIGN_DIM                                               !7, 'headers'
         86        OP_DATA                                                  ~46
   50    87        FETCH_DIM_R                                      ~48     !7, 'body'
         88        FETCH_DIM_R                                      ~49     ~48, 'exception'
         89        ASSIGN_DIM                                               !7, 'exception'
         90        OP_DATA                                                  ~49
   51    91        FETCH_DIM_R                                      ~51     !7, 'body'
         92        FETCH_DIM_R                                      ~52     ~51, 'http_status_code'
         93        ASSIGN_DIM                                               !7, 'http_status_code'
         94        OP_DATA                                                  ~52
   52    95        FETCH_DIM_R                                      ~54     !7, 'body'
         96        FETCH_DIM_R                                      ~55     ~54, 'auth_token'
         97        ASSIGN_DIM                                               !7, 'auth_token'
         98        OP_DATA                                                  ~55
   54    99        FETCH_DIM_R                                      ~57     !7, 'body'
        100        FETCH_DIM_R                                      ~58     ~57, 'body'
        101        ASSIGN_DIM                                               !7, 'body'
        102        OP_DATA                                                  ~58
   56   103      > RETURN                                                   !7
   57   104*     > 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/R5T0P
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
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
   61     1        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Cstrpos'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              '%3F'
          4        SEND_VAL_EX                                              0
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !1, $3
   62     7        TYPE_CHECK                                  1018          !1
          8      > JMPZ                                                     ~5, ->30
   64     9    >   INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Csubstr'
         10        SEND_VAR_EX                                              !0
         11        ADD                                              ~6      !1, 1
         12        SEND_VAL_EX                                              ~6
         13        DO_FCALL                                      0  $7      
         14        ASSIGN                                                   !2, $7
   65    15        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Crawurlencode'
         16        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Curldecode'
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0  $9      
         19        SEND_VAR_NO_REF_EX                                       $9
         20        DO_FCALL                                      0  $10     
         21        ASSIGN                                                   !2, $10
   66    22        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Csubstr'
         23        SEND_VAR_EX                                              !0
         24        SEND_VAL_EX                                              0
         25        ADD                                              ~12     !1, 1
         26        SEND_VAL_EX                                              ~12
         27        DO_FCALL                                      0  $13     
         28        CONCAT                                           ~14     $13, !2
         29        ASSIGN                                                   !0, ~14
   68    30    > > RETURN                                                   !0
   69    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 = 28
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 22
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 28
filename:       /in/R5T0P
function name:  encode_post_data
number of ops:  30
compiled vars:  !0 = $vars, !1 = $request_body, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   RECV                                             !0      
   73     1        ASSIGN                                                   !1, ''
   74     2      > JMPZ                                                     !0, ->28
   76     3    > > FE_RESET_R                                       $5      !0, ->22
          4    > > FE_FETCH_R                                       ~6      $5, !2, ->22
          5    >   ASSIGN                                                   !3, ~6
   78     6        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Cis_array'
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0  $8      
          9      > JMPZ                                                     $8, ->17
   79    10    >   INIT_METHOD_CALL                                         'urlencode_array'
         11        SEND_VAR_EX                                              !2
         12        SEND_VAR_EX                                              !3
         13        DO_FCALL                                      0  $9      
         14        CONCAT                                           ~10     $9, '%26'
         15        ASSIGN_OP                                     8          !1, ~10
         16      > JMP                                                      ->21
   81    17    >   CONCAT                                           ~12     !3, '%3D'
         18        CONCAT                                           ~13     ~12, !2
         19        CONCAT                                           ~14     ~13, '%26'
         20        ASSIGN_OP                                     8          !1, ~14
   76    21    > > JMP                                                      ->4
         22    >   FE_FREE                                                  $5
   84    23        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Crtrim'
         24        SEND_VAR_EX                                              !1
         25        SEND_VAL_EX                                              '%26'
         26        DO_FCALL                                      0  $16     
         27        ASSIGN                                                   !1, $16
   87    28    > > RETURN                                                   !1
   88    29*     > 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/R5T0P
function name:  get_signature
number of ops:  41
compiled vars:  !0 = $vars, !1 = $key, !2 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   90     0  E >   RECV                                             !0      
   92     1        FETCH_OBJ_R                                      ~3      'hashing_key'
          2        ASSIGN                                                   !1, ~3
   93     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
   94    25        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Cbase64_encode'
         26        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Chash_hmac'
         27        SEND_VAL_EX                                              'sha512'
         28        SEND_VAR_EX                                              !2
         29        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Chash'
         30        SEND_VAL_EX                                              'sha512'
         31        CHECK_FUNC_ARG                                           
         32        FETCH_OBJ_FUNC_ARG                               $21     'hashing_key'
         33        SEND_FUNC_ARG                                            $21
         34        DO_FCALL                                      0  $22     
         35        SEND_VAR_NO_REF_EX                                       $22
         36        DO_FCALL                                      0  $23     
         37        SEND_VAR_NO_REF_EX                                       $23
         38        DO_FCALL                                      0  $24     
         39      > RETURN                                                   $24
   96    40*     > 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 = 37
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 37
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 23
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/R5T0P
function name:  urlencode_array
number of ops:  44
compiled vars:  !0 = $var, !1 = $varName, !2 = $separator, !3 = $toImplode, !4 = $value, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   98     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      '%26'
  100     3        ASSIGN                                                   !3, <array>
  101     4      > FE_RESET_R                                       $7      !0, ->37
          5    > > FE_FETCH_R                                       ~8      $7, !4, ->37
          6    >   ASSIGN                                                   !5, ~8
  103     7        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Cis_array'
          8        SEND_VAR_EX                                              !4
          9        DO_FCALL                                      0  $10     
         10      > JMPZ                                                     $10, ->23
  104    11    >   INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Curlencode_array'
         12        SEND_VAR_EX                                              !4
         13        ROPE_INIT                                     4  ~13     !1
         14        ROPE_ADD                                      1  ~13     ~13, '%5B'
         15        ROPE_ADD                                      2  ~13     ~13, !5
         16        ROPE_END                                      3  ~12     ~13, '%5D'
         17        SEND_VAL_EX                                              ~12
         18        SEND_VAR_EX                                              !2
         19        DO_FCALL                                      0  $15     
         20        ASSIGN_DIM                                               !3
         21        OP_DATA                                                  $15
         22      > JMP                                                      ->36
  106    23    >   ROPE_INIT                                     4  ~18     !1
         24        ROPE_ADD                                      1  ~18     ~18, '%5B'
         25        ROPE_ADD                                      2  ~18     ~18, !5
         26        ROPE_END                                      3  ~17     ~18, '%5D%3D'
         27        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Crawurlencode'
         28        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Curldecode'
         29        SEND_VAR_EX                                              !4
         30        DO_FCALL                                      0  $20     
         31        SEND_VAR_NO_REF_EX                                       $20
         32        DO_FCALL                                      0  $21     
         33        CONCAT                                           ~22     ~17, $21
         34        ASSIGN_DIM                                               !3
         35        OP_DATA                                                  ~22
  101    36    > > JMP                                                      ->5
         37    >   FE_FREE                                                  $7
  108    38        INIT_NS_FCALL_BY_NAME                                    'Grada%5CREST%5Cimplode'
         39        SEND_VAR_EX                                              !2
         40        SEND_VAR_EX                                              !3
         41        DO_FCALL                                      0  $23     
         42      > RETURN                                                   $23
  109    43*     > RETURN                                                   null

End of function urlencode_array

End of class Grada\REST\Client.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.14 ms | 1423 KiB | 42 Q