3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class header { private $secretKey = '123'; private $storeId = 10; public function __construct($content, $url) { $this->setContentMd5($content); $this->setHttpVerb($url); } private function setContentMd5($content) { $this->contentMd5 = md5($content); } private function setHttpVerb($url) { if (parse_url($url, PHP_URL_QUERY)) { $this->httpVerb = parse_url($url, PHP_URL_PATH).'?'.parse_url($url, PHP_URL_QUERY); } else { $this->httpVerb = parse_url($url, PHP_URL_PATH); } } private function generateAuthorization() { return hash_hmac( 'sha256', $this->httpVerb . $this->contentMd5, $this->secretKey ); } public function generateHeader() { $headers = array( 'Accept' => 'application/vnd.boacompra.com.v1+json; charset=UTF-8', 'Content-Type' => 'application/json', 'Content-MD5' => $this->contentMd5, 'Authorization' => $this->storeId . ':' . $this->generateAuthorization() ); return $headers; } } echo 'POST EXAMPLE <br /> <pre>'; $content = '{"payment-method":{"reference":"ID-CND4","direct-token":"eyJkbmEiOiJjMWRkMzliYTY4YjY0MjlkOTRmNTQzM2YwMTFiNTRlZiIsImlwIjoiMTcyLjIxLjExMi4xNjEiLCJkZiI6IjJmOTExZjdkOTgyZDQzMDY4YTNmYjc2MWRlZWQzZjI1In0=","notify-url":"https://virtual-store.com/notifications/","test-mode":0,"payment-group":"credit_card","country":"BR","language":"en-US"},"payer":{"name":"João Pagão","email":"payer@uolinc.com","phone-area-code":"11","phone-number":"988881234","document":{"type":"CPF","number":"00000000191"},"birth-date":"1982-12-20"}}'; $headerPost = new header($content, 'https://api.boacompra.com/payment-methods'); print_r($headerPost->generateHeader());
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 62) Position 1 = -2
filename:       /in/LDfCm
function name:  (null)
number of ops:  14
compiled vars:  !0 = $content, !1 = $headerPost
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   NOP                                                      
  51     1        ECHO                                                     'POST+EXAMPLE+%3Cbr+%2F%3E+%3Cpre%3E'
  52     2        ASSIGN                                                   !0, '%7B%22payment-method%22%3A%7B%22reference%22%3A%22ID-CND4%22%2C%22direct-token%22%3A%22eyJkbmEiOiJjMWRkMzliYTY4YjY0MjlkOTRmNTQzM2YwMTFiNTRlZiIsImlwIjoiMTcyLjIxLjExMi4xNjEiLCJkZiI6IjJmOTExZjdkOTgyZDQzMDY4YTNmYjc2MWRlZWQzZjI1In0%3D%22%2C%22notify-url%22%3A%22https%3A%2F%2Fvirtual-store.com%2Fnotifications%2F%22%2C%22test-mode%22%3A0%2C%22payment-group%22%3A%22credit_card%22%2C%22country%22%3A%22BR%22%2C%22language%22%3A%22en-US%22%7D%2C%22payer%22%3A%7B%22name%22%3A%22Jo%C3%A3o+Pag%C3%A3o%22%2C%22email%22%3A%22payer%40uolinc.com%22%2C%22phone-area-code%22%3A%2211%22%2C%22phone-number%22%3A%22988881234%22%2C%22document%22%3A%7B%22type%22%3A%22CPF%22%2C%22number%22%3A%2200000000191%22%7D%2C%22birth-date%22%3A%221982-12-20%22%7D%7D'
  54     3        NEW                                              $4      :-3
         4        SEND_VAR_EX                                              !0
         5        SEND_VAL_EX                                              'https%3A%2F%2Fapi.boacompra.com%2Fpayment-methods'
         6        DO_FCALL                                      0          
         7        ASSIGN                                                   !1, $4
  55     8        INIT_FCALL                                               'print_r'
         9        INIT_METHOD_CALL                                         !1, 'generateHeader'
        10        DO_FCALL                                      0  $7      
        11        SEND_VAR                                                 $7
        12        DO_ICALL                                                 
        13      > RETURN                                                   1

Class header:
Function __construct:
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 62) Position 1 = -2
filename:       /in/LDfCm
function name:  __construct
number of ops:  9
compiled vars:  !0 = $content, !1 = $url
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   7     0  E >   RECV                                             !0      
         1        RECV                                             !1      
   9     2        INIT_METHOD_CALL                                         'setContentMd5'
         3        SEND_VAR_EX                                              !0
         4        DO_FCALL                                      0          
  10     5        INIT_METHOD_CALL                                         'setHttpVerb'
         6        SEND_VAR_EX                                              !1
         7        DO_FCALL                                      0          
  11     8      > RETURN                                                   null

End of function __construct

Function setcontentmd5:
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 62) Position 1 = -2
filename:       /in/LDfCm
function name:  setContentMd5
number of ops:  7
compiled vars:  !0 = $content
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  13     0  E >   RECV                                             !0      
  15     1        INIT_FCALL                                               'md5'
         2        SEND_VAR                                                 !0
         3        DO_ICALL                                         $2      
         4        ASSIGN_OBJ                                               'contentMd5'
         5        OP_DATA                                                  $2
  16     6      > RETURN                                                   null

End of function setcontentmd5

Function sethttpverb:
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 43) Position 1 = 6, Position 2 = 19
Branch analysis from position: 6
Jump found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Jump found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Jump found. (Code = 62) Position 1 = -2
filename:       /in/LDfCm
function name:  setHttpVerb
number of ops:  26
compiled vars:  !0 = $url
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  18     0  E >   RECV                                             !0      
  20     1        INIT_FCALL                                               'parse_url'
         2        SEND_VAR                                                 !0
         3        SEND_VAL                                                 6
         4        DO_ICALL                                         $1      
         5      > JMPZ                                                     $1, ->19
  21     6    >   INIT_FCALL                                               'parse_url'
         7        SEND_VAR                                                 !0
         8        SEND_VAL                                                 5
         9        DO_ICALL                                         $3      
        10        CONCAT                                           ~4      $3, '%3F'
        11        INIT_FCALL                                               'parse_url'
        12        SEND_VAR                                                 !0
        13        SEND_VAL                                                 6
        14        DO_ICALL                                         $5      
        15        CONCAT                                           ~6      ~4, $5
        16        ASSIGN_OBJ                                               'httpVerb'
        17        OP_DATA                                                  ~6
        18      > JMP                                                      ->25
  23    19    >   INIT_FCALL                                               'parse_url'
        20        SEND_VAR                                                 !0
        21        SEND_VAL                                                 5
        22        DO_ICALL                                         $8      
        23        ASSIGN_OBJ                                               'httpVerb'
        24        OP_DATA                                                  $8
  25    25    > > RETURN                                                   null

End of function sethttpverb

Function generateauthorization:
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 62) Position 1 = -2
filename:       /in/LDfCm
function name:  generateAuthorization
number of ops:  11
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  29     0  E >   INIT_FCALL                                               'hash_hmac'
  30     1        SEND_VAL                                                 'sha256'
  31     2        FETCH_OBJ_R                                      $0      'httpVerb'
         3        FETCH_OBJ_R                                      $1      'contentMd5'
         4        CONCAT                                           ~2      $0, $1
         5        SEND_VAL                                                 ~2
  32     6        FETCH_OBJ_R                                      $3      'secretKey'
         7        SEND_VAR                                                 $3
         8        DO_ICALL                                         $4      
         9      > RETURN                                                   $4
  34    10*     > RETURN                                                   null

End of function generateauthorization

Function generateheader:
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 62) Position 1 = -2
filename:       /in/LDfCm
function name:  generateHeader
number of ops:  13
compiled vars:  !0 = $headers
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  42     0  E >   INIT_ARRAY                                       ~1      'application%2Fvnd.boacompra.com.v1%2Bjson%3B+charset%3DUTF-8', 'Accept'
  43     1        ADD_ARRAY_ELEMENT                                ~1      'application%2Fjson', 'Content-Type'
  44     2        FETCH_OBJ_R                                      $2      'contentMd5'
         3        ADD_ARRAY_ELEMENT                                ~1      $2, 'Content-MD5'
  45     4        FETCH_OBJ_R                                      $3      'storeId'
         5        CONCAT                                           ~4      $3, '%3A'
         6        INIT_METHOD_CALL                                         'generateAuthorization'
         7        DO_FCALL                                      0  $5      
         8        CONCAT                                           ~6      ~4, $5
         9        ADD_ARRAY_ELEMENT                                ~1      ~6, 'Authorization'
        10        ASSIGN                                                   !0, ~1
  47    11      > RETURN                                                   !0
  48    12*     > RETURN                                                   null

End of function generateheader

End of class header.

Generated using Vulcan Logic Dumper, using php 7.2.0