3v4l.org

run code in 300+ PHP versions simultaneously
<?php class RPCInterface{ const STATUS_OK = 200; const STATUS_INVALID_CREDENTIALS = 401; const STATUS_RESSOURCE_NOT_FOUND = 404; const STATUS_INTERNAL_ERROR = 500; const STATUS_NOT_IMPLEMENTED = 501; const STATUS_SERVICE_UNAVAILABLE = 503; const ENCAP_RAW = 0; const ENCAP_AES256 = 1; const ENCAP_RSA2048 = 2; protected $encap = 0; public function getRequestStr($auth, $method, $data){ $req = new stdClass(); $req->auth = $auth; $req->method = $method; $req->data = $data; $reqStr = $this->encode($req); return $reqStr; } public function getResponse($respStr){ $resp = $this->decode($respStr); return $resp; } public function encode($obj){ $str = serialize($obj);// json_encode($str); $str = $this->encapsulate($str); return $str; } public function decode($str){ $str = $this->decapsulate($str); $obj = unserialize($str); return $obj; } public function encapsulate($str){ switch($this->encap){ case self::ENCAP_RAW: $str = base64_encode($str); break; case self::ENCAP_AES256: die('TODO IMPL AES245'); // TODO FIXME break; case self::ENCAP_RSA2048: die('TODO IMPL RSA2048'); // TODO FIXME break; default: die('UNKNOWN_ENCAP_ALG'); } return $str; } public function decapsulate($str){ switch($this->encap){ case self::ENCAP_RAW: $str = base64_decode($str); break; case self::ENCAP_AES256: die('TODO IMPL AES245'); // TODO FIXME break; case self::ENCAP_RSA2048: die('TODO IMPL RSA2048'); // TODO FIXME break; default: die('UNKNOWN_ENCAP_ALG'); } return $str; } public function responseOk($resp){ return ($resp->status == self::STATUS_OK); } public function getError($resp){ return $resp->data['error_num'].' '.$resp->data['error_msg']; } public function getErrorDesc($resp){ return $resp->data['error_desc']; } public function sendRequest($url, $auth, $method, $data){ $reqStr = $this->getRequestStr($auth, $method, $data); $request = xmlrpc_encode_request($method, $reqStr); // maybe do not use xmlrpc_ at all... $context = stream_context_create(array('http' => array( 'method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request ))); print_r($context); //$file = file_get_contents($url, false, $context); $resp = $this->getResponse($file); if($this->responseOk($resp)){ $resp->error = false; }else{ $resp->error = true; } return $resp; } } $rpc = new RPCInterface(); $auth = array(); $auth['customer_id'] = '4843929'; $auth['customer_pw'] = 'pw0rdRem0tE0815'; $auth['domain_id'] = '429'; $auth['domain_sec'] = 'a98bf32409cd1fd298e'; $method = 'status.ping'; $url = 'www.example.com'; $data = array(); $req = $rpc->getRequestStr($auth, $method, $data); $dec = $rpc->getResponse($req); echo $req; echo "\r\n"; echo print_r($dec, true); $resp = $rpc->sendRequest($url, $auth, $method, $data); if($resp->error){ echo "Error occured!\r\n"; } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 42
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/JZ2ug
function name:  (null)
number of ops:  43
compiled vars:  !0 = $rpc, !1 = $auth, !2 = $method, !3 = $url, !4 = $data, !5 = $req, !6 = $dec, !7 = $resp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  112     0  E >   NEW                                              $8      'RPCInterface'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $8
  113     3        ASSIGN                                                   !1, <array>
  114     4        ASSIGN_DIM                                               !1, 'customer_id'
          5        OP_DATA                                                  '4843929'
  115     6        ASSIGN_DIM                                               !1, 'customer_pw'
          7        OP_DATA                                                  'pw0rdRem0tE0815'
  116     8        ASSIGN_DIM                                               !1, 'domain_id'
          9        OP_DATA                                                  '429'
  117    10        ASSIGN_DIM                                               !1, 'domain_sec'
         11        OP_DATA                                                  'a98bf32409cd1fd298e'
  119    12        ASSIGN                                                   !2, 'status.ping'
  121    13        ASSIGN                                                   !3, 'www.example.com'
  123    14        ASSIGN                                                   !4, <array>
  125    15        INIT_METHOD_CALL                                         !0, 'getRequestStr'
         16        SEND_VAR_EX                                              !1
         17        SEND_VAR_EX                                              !2
         18        SEND_VAR_EX                                              !4
         19        DO_FCALL                                      0  $19     
         20        ASSIGN                                                   !5, $19
  126    21        INIT_METHOD_CALL                                         !0, 'getResponse'
         22        SEND_VAR_EX                                              !5
         23        DO_FCALL                                      0  $21     
         24        ASSIGN                                                   !6, $21
  128    25        ECHO                                                     !5
  129    26        ECHO                                                     '%0D%0A'
  130    27        INIT_FCALL                                               'print_r'
         28        SEND_VAR                                                 !6
         29        SEND_VAL                                                 <true>
         30        DO_ICALL                                         $23     
         31        ECHO                                                     $23
  134    32        INIT_METHOD_CALL                                         !0, 'sendRequest'
         33        SEND_VAR_EX                                              !3
         34        SEND_VAR_EX                                              !1
         35        SEND_VAR_EX                                              !2
         36        SEND_VAR_EX                                              !4
         37        DO_FCALL                                      0  $24     
         38        ASSIGN                                                   !7, $24
  136    39        FETCH_OBJ_R                                      ~26     !7, 'error'
         40      > JMPZ                                                     ~26, ->42
  137    41    >   ECHO                                                     'Error+occured%21%0D%0A'
  140    42    > > RETURN                                                   1

Class RPCInterface:
Function getrequeststr:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JZ2ug
function name:  getRequestStr
number of ops:  18
compiled vars:  !0 = $auth, !1 = $method, !2 = $data, !3 = $req, !4 = $reqStr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   20     3        NEW                                              $5      'stdClass'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !3, $5
   21     6        ASSIGN_OBJ                                               !3, 'auth'
          7        OP_DATA                                                  !0
   22     8        ASSIGN_OBJ                                               !3, 'method'
          9        OP_DATA                                                  !1
   23    10        ASSIGN_OBJ                                               !3, 'data'
         11        OP_DATA                                                  !2
   25    12        INIT_METHOD_CALL                                         'encode'
         13        SEND_VAR_EX                                              !3
         14        DO_FCALL                                      0  $11     
         15        ASSIGN                                                   !4, $11
   26    16      > RETURN                                                   !4
   27    17*     > RETURN                                                   null

End of function getrequeststr

Function getresponse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JZ2ug
function name:  getResponse
number of ops:  7
compiled vars:  !0 = $respStr, !1 = $resp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        INIT_METHOD_CALL                                         'decode'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !1, $2
   31     5      > RETURN                                                   !1
   32     6*     > RETURN                                                   null

End of function getresponse

Function encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JZ2ug
function name:  encode
number of ops:  11
compiled vars:  !0 = $obj, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        INIT_FCALL                                               'serialize'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !1, $2
   36     5        INIT_METHOD_CALL                                         'encapsulate'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !1, $4
   37     9      > RETURN                                                   !1
   38    10*     > RETURN                                                   null

End of function encode

Function decode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JZ2ug
function name:  decode
number of ops:  11
compiled vars:  !0 = $str, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   40     1        INIT_METHOD_CALL                                         'decapsulate'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
   41     5        INIT_FCALL                                               'unserialize'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !1, $4
   42     9      > RETURN                                                   !1
   43    10*     > RETURN                                                   null

End of function decode

Function encapsulate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JZ2ug
function name:  encapsulate
number of ops:  22
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   46     1        FETCH_OBJ_R                                      ~1      'encap'
          2        CASE                                                     ~1, 0
          3      > JMPNZ                                                    ~2, ->9
          4    >   CASE                                                     ~1, 1
          5      > JMPNZ                                                    ~2, ->14
          6    >   CASE                                                     ~1, 2
          7      > JMPNZ                                                    ~2, ->16
          8    > > JMP                                                      ->18
   48     9    >   INIT_FCALL                                               'base64_encode'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $3      
         12        ASSIGN                                                   !0, $3
   49    13      > JMP                                                      ->19
   51    14    > > EXIT                                                     'TODO+IMPL+AES245'
   52    15*       JMP                                                      ->19
   54    16    > > EXIT                                                     'TODO+IMPL+RSA2048'
   55    17*       JMP                                                      ->19
   57    18    > > EXIT                                                     'UNKNOWN_ENCAP_ALG'
         19    >   FREE                                                     ~1
   59    20      > RETURN                                                   !0
   60    21*     > RETURN                                                   null

End of function encapsulate

Function decapsulate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JZ2ug
function name:  decapsulate
number of ops:  22
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
   63     1        FETCH_OBJ_R                                      ~1      'encap'
          2        CASE                                                     ~1, 0
          3      > JMPNZ                                                    ~2, ->9
          4    >   CASE                                                     ~1, 1
          5      > JMPNZ                                                    ~2, ->14
          6    >   CASE                                                     ~1, 2
          7      > JMPNZ                                                    ~2, ->16
          8    > > JMP                                                      ->18
   65     9    >   INIT_FCALL                                               'base64_decode'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $3      
         12        ASSIGN                                                   !0, $3
   66    13      > JMP                                                      ->19
   68    14    > > EXIT                                                     'TODO+IMPL+AES245'
   69    15*       JMP                                                      ->19
   71    16    > > EXIT                                                     'TODO+IMPL+RSA2048'
   72    17*       JMP                                                      ->19
   74    18    > > EXIT                                                     'UNKNOWN_ENCAP_ALG'
         19    >   FREE                                                     ~1
   76    20      > RETURN                                                   !0
   77    21*     > RETURN                                                   null

End of function decapsulate

Function responseok:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JZ2ug
function name:  responseOk
number of ops:  5
compiled vars:  !0 = $resp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
   80     1        FETCH_OBJ_R                                      ~1      !0, 'status'
          2        IS_EQUAL                                         ~2      ~1, 200
          3      > RETURN                                                   ~2
   81     4*     > RETURN                                                   null

End of function responseok

Function geterror:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JZ2ug
function name:  getError
number of ops:  9
compiled vars:  !0 = $resp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     0  E >   RECV                                             !0      
   84     1        FETCH_OBJ_R                                      ~1      !0, 'data'
          2        FETCH_DIM_R                                      ~2      ~1, 'error_num'
          3        CONCAT                                           ~3      ~2, '+'
          4        FETCH_OBJ_R                                      ~4      !0, 'data'
          5        FETCH_DIM_R                                      ~5      ~4, 'error_msg'
          6        CONCAT                                           ~6      ~3, ~5
          7      > RETURN                                                   ~6
   85     8*     > RETURN                                                   null

End of function geterror

Function geterrordesc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JZ2ug
function name:  getErrorDesc
number of ops:  5
compiled vars:  !0 = $resp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   RECV                                             !0      
   88     1        FETCH_OBJ_R                                      ~1      !0, 'data'
          2        FETCH_DIM_R                                      ~2      ~1, 'error_desc'
          3      > RETURN                                                   ~2
   89     4*     > RETURN                                                   null

End of function geterrordesc

Function sendrequest:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JZ2ug
function name:  sendRequest
number of ops:  41
compiled vars:  !0 = $url, !1 = $auth, !2 = $method, !3 = $data, !4 = $reqStr, !5 = $request, !6 = $context, !7 = $resp, !8 = $file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   92     4        INIT_METHOD_CALL                                         'getRequestStr'
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !2
          7        SEND_VAR_EX                                              !3
          8        DO_FCALL                                      0  $9      
          9        ASSIGN                                                   !4, $9
   93    10        INIT_FCALL_BY_NAME                                       'xmlrpc_encode_request'
         11        SEND_VAR_EX                                              !2
         12        SEND_VAR_EX                                              !4
         13        DO_FCALL                                      0  $11     
         14        ASSIGN                                                   !5, $11
   94    15        INIT_FCALL                                               'stream_context_create'
   95    16        INIT_ARRAY                                       ~13     'POST', 'method'
   96    17        ADD_ARRAY_ELEMENT                                ~13     'Content-Type%3A+text%2Fxml', 'header'
   97    18        ADD_ARRAY_ELEMENT                                ~13     !5, 'content'
         19        INIT_ARRAY                                       ~14     ~13, 'http'
         20        SEND_VAL                                                 ~14
         21        DO_ICALL                                         $15     
   94    22        ASSIGN                                                   !6, $15
   99    23        INIT_FCALL                                               'print_r'
         24        SEND_VAR                                                 !6
         25        DO_ICALL                                                 
  101    26        INIT_METHOD_CALL                                         'getResponse'
         27        SEND_VAR_EX                                              !8
         28        DO_FCALL                                      0  $18     
         29        ASSIGN                                                   !7, $18
  102    30        INIT_METHOD_CALL                                         'responseOk'
         31        SEND_VAR_EX                                              !7
         32        DO_FCALL                                      0  $20     
         33      > JMPZ                                                     $20, ->37
  103    34    >   ASSIGN_OBJ                                               !7, 'error'
         35        OP_DATA                                                  <false>
         36      > JMP                                                      ->39
  105    37    >   ASSIGN_OBJ                                               !7, 'error'
         38        OP_DATA                                                  <true>
  107    39    > > RETURN                                                   !7
  108    40*     > RETURN                                                   null

End of function sendrequest

End of class RPCInterface.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.05 ms | 1416 KiB | 25 Q