3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace WoohooLabs\Yang\JsonApi\Request; use Psr\Http\Message\RequestInterface; class RequestBuilder { /** * @var \Psr\Http\Message\RequestInterface */ protected $request; /** * @var string */ protected $method; /** * @var array */ protected $queryString; /** * @param \Psr\Http\Message\RequestInterface $request */ public function __construct() { $this->initialize(); } public function initialize() { $this->method = "GET"; $this->queryString = []; } public function fetch() { $this->method = "GET"; } public function create() { $this->method = "POST"; } public function update() { $this->method = "PATCH"; } public function delete() { $this->method = "DELETE"; } /** * @param array|string $fields */ public function fields($fields) { $this->setQueryParam("fields", $fields); } /** * @param array|string $fields */ public function sort($fields) { $this->setQueryParam("sort", $fields); } /** * @param array|string $paginate */ public function paginate($paginate) { $this->setQueryParam("page", $paginate); } /** * @param array|string $filter */ public function filter($filter) { $this->setQueryParam("filter", $filter); } /** * @param array|string $includes */ public function includes($includes) { if (is_array($includes)) { $this->queryString["includes"] = implode(",", $includes); } else { $this->queryString["includes"] = $includes; } } /** * @return \Psr\Http\Message\RequestInterface */ public function getRequest() { $request = $this->request->withMethod($this->method); $request = $request->withUri($request->getUri()->withQuery($this->getQueryString())); return $request; } /** * @return string */ public function getQueryString() { return http_build_query($this->queryString); } /** * @param string $name * @param array|string $queryParam */ protected function setQueryParam($name, $queryParam) { if (is_array($queryParam)) { foreach ($queryParam as $key => $value) { $this->queryString[$name][$key] = $queryParam; } } else { $this->queryString[$name] = $queryParam; } } /** * @param array $array * @return bool */ protected function isAssociativeArray(array $array) { return (bool)count(array_filter(array_keys($array), 'is_string')); } } $builder = new RequestBuilder(); $builder->fields(["kaka" => "1,2,3,4", "shohoh" => "6,5,4,3"]); echo url_decode($builder->getQueryString());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  (null)
number of ops:  13
compiled vars:  !0 = $builder
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  146     0  E >   NEW                                              $1      'WoohooLabs%5CYang%5CJsonApi%5CRequest%5CRequestBuilder'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
  147     3        INIT_METHOD_CALL                                         !0, 'fields'
          4        SEND_VAL_EX                                              <array>
          5        DO_FCALL                                      0          
  148     6        INIT_NS_FCALL_BY_NAME                                    'WoohooLabs%5CYang%5CJsonApi%5CRequest%5Curl_decode'
          7        INIT_METHOD_CALL                                         !0, 'getQueryString'
          8        DO_FCALL                                      0  $5      
          9        SEND_VAR_NO_REF_EX                                       $5
         10        DO_FCALL                                      0  $6      
         11        ECHO                                                     $6
         12      > RETURN                                                   1

Class WoohooLabs\Yang\JsonApi\Request\RequestBuilder:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_METHOD_CALL                                         'initialize'
          1        DO_FCALL                                      0          
   29     2      > RETURN                                                   null

End of function __construct

Function initialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  initialize
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN_OBJ                                               'method'
          1        OP_DATA                                                  'GET'
   34     2        ASSIGN_OBJ                                               'queryString'
          3        OP_DATA                                                  <array>
   35     4      > RETURN                                                   null

End of function initialize

Function fetch:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  fetch
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   ASSIGN_OBJ                                               'method'
          1        OP_DATA                                                  'GET'
   40     2      > RETURN                                                   null

End of function fetch

Function create:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  create
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   ASSIGN_OBJ                                               'method'
          1        OP_DATA                                                  'POST'
   45     2      > RETURN                                                   null

End of function create

Function update:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  update
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   ASSIGN_OBJ                                               'method'
          1        OP_DATA                                                  'PATCH'
   50     2      > RETURN                                                   null

End of function update

Function delete:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  delete
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   ASSIGN_OBJ                                               'method'
          1        OP_DATA                                                  'DELETE'
   55     2      > RETURN                                                   null

End of function delete

Function fields:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  fields
number of ops:  6
compiled vars:  !0 = $fields
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
   62     1        INIT_METHOD_CALL                                         'setQueryParam'
          2        SEND_VAL_EX                                              'fields'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   63     5      > RETURN                                                   null

End of function fields

Function sort:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  sort
number of ops:  6
compiled vars:  !0 = $fields
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   RECV                                             !0      
   70     1        INIT_METHOD_CALL                                         'setQueryParam'
          2        SEND_VAL_EX                                              'sort'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   71     5      > RETURN                                                   null

End of function sort

Function paginate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  paginate
number of ops:  6
compiled vars:  !0 = $paginate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   RECV                                             !0      
   78     1        INIT_METHOD_CALL                                         'setQueryParam'
          2        SEND_VAL_EX                                              'page'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   79     5      > RETURN                                                   null

End of function paginate

Function filter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  filter
number of ops:  6
compiled vars:  !0 = $filter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   RECV                                             !0      
   86     1        INIT_METHOD_CALL                                         'setQueryParam'
          2        SEND_VAL_EX                                              'filter'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   87     5      > RETURN                                                   null

End of function filter

Function includes:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  includes
number of ops:  17
compiled vars:  !0 = $includes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E >   RECV                                             !0      
   94     1        INIT_NS_FCALL_BY_NAME                                    'WoohooLabs%5CYang%5CJsonApi%5CRequest%5Cis_array'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > JMPZ                                                     $1, ->13
   95     5    >   INIT_NS_FCALL_BY_NAME                                    'WoohooLabs%5CYang%5CJsonApi%5CRequest%5Cimplode'
          6        SEND_VAL_EX                                              '%2C'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0  $4      
          9        FETCH_OBJ_W                                      $2      'queryString'
         10        ASSIGN_DIM                                               $2, 'includes'
         11        OP_DATA                                                  $4
         12      > JMP                                                      ->16
   97    13    >   FETCH_OBJ_W                                      $5      'queryString'
         14        ASSIGN_DIM                                               $5, 'includes'
         15        OP_DATA                                                  !0
   99    16    > > RETURN                                                   null

End of function includes

Function getrequest:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  getRequest
number of ops:  20
compiled vars:  !0 = $request
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  106     0  E >   FETCH_OBJ_R                                      ~1      'request'
          1        INIT_METHOD_CALL                                         ~1, 'withMethod'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $2      'method'
          4        SEND_FUNC_ARG                                            $2
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !0, $3
  107     7        INIT_METHOD_CALL                                         !0, 'withUri'
          8        INIT_METHOD_CALL                                         !0, 'getUri'
          9        DO_FCALL                                      0  $5      
         10        INIT_METHOD_CALL                                         $5, 'withQuery'
         11        INIT_METHOD_CALL                                         'getQueryString'
         12        DO_FCALL                                      0  $6      
         13        SEND_VAR_NO_REF_EX                                       $6
         14        DO_FCALL                                      0  $7      
         15        SEND_VAR_NO_REF_EX                                       $7
         16        DO_FCALL                                      0  $8      
         17        ASSIGN                                                   !0, $8
  109    18      > RETURN                                                   !0
  110    19*     > RETURN                                                   null

End of function getrequest

Function getquerystring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  getQueryString
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  117     0  E >   INIT_NS_FCALL_BY_NAME                                    'WoohooLabs%5CYang%5CJsonApi%5CRequest%5Chttp_build_query'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $0      'queryString'
          3        SEND_FUNC_ARG                                            $0
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
  118     6*     > RETURN                                                   null

End of function getquerystring

Function setqueryparam:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  setQueryParam
number of ops:  20
compiled vars:  !0 = $name, !1 = $queryParam, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  124     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  126     2        INIT_NS_FCALL_BY_NAME                                    'WoohooLabs%5CYang%5CJsonApi%5CRequest%5Cis_array'
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0  $4      
          5      > JMPZ                                                     $4, ->16
  127     6    > > FE_RESET_R                                       $5      !1, ->14
          7    > > FE_FETCH_R                                       ~6      $5, !2, ->14
          8    >   ASSIGN                                                   !3, ~6
  128     9        FETCH_OBJ_W                                      $8      'queryString'
         10        FETCH_DIM_W                                      $9      $8, !0
         11        ASSIGN_DIM                                               $9, !3
         12        OP_DATA                                                  !1
  127    13      > JMP                                                      ->7
         14    >   FE_FREE                                                  $5
         15      > JMP                                                      ->19
  131    16    >   FETCH_OBJ_W                                      $11     'queryString'
         17        ASSIGN_DIM                                               $11, !0
         18        OP_DATA                                                  !1
  133    19    > > RETURN                                                   null

End of function setqueryparam

Function isassociativearray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4ddW
function name:  isAssociativeArray
number of ops:  14
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  139     0  E >   RECV                                             !0      
  141     1        INIT_NS_FCALL_BY_NAME                                    'WoohooLabs%5CYang%5CJsonApi%5CRequest%5Ccount'
          2        INIT_NS_FCALL_BY_NAME                                    'WoohooLabs%5CYang%5CJsonApi%5CRequest%5Carray_filter'
          3        INIT_NS_FCALL_BY_NAME                                    'WoohooLabs%5CYang%5CJsonApi%5CRequest%5Carray_keys'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $1      
          6        SEND_VAR_NO_REF_EX                                       $1
          7        SEND_VAL_EX                                              'is_string'
          8        DO_FCALL                                      0  $2      
          9        SEND_VAR_NO_REF_EX                                       $2
         10        DO_FCALL                                      0  $3      
         11        BOOL                                             ~4      $3
         12      > RETURN                                                   ~4
  142    13*     > RETURN                                                   null

End of function isassociativearray

End of class WoohooLabs\Yang\JsonApi\Request\RequestBuilder.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
195.31 ms | 1415 KiB | 26 Q