3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Route { const RESOURCE_PATTERN = '/'.'\[:(.*)\]'.'/'; const TOKEN_PARA_PATTERN = '/'.'\{:(.*)\}'.'/'; private $methodList; private $url; private $urlTokenList; private $urlTokenCount; private $controller; private $action; private $tokenParameterList; private $resourceList = array(); private $resourceDetailList = array(); public function __construct($httpMethod, $httpUrl, $controller, $action) { $this->methodList = explode('|', $httpMethod); $this->httpUrl = $httpUrl; $this->controller = $controller; $this->action = $action; $this->parseURL($httpUrl); } public function parseURL($url) { $tmpUrl = $url; if (substr($tmpUrl, 0, 1) == '/') { $tmpUrl = substr($tmpUrl, 1); } if (substr($tmpUrl, -1) == '/') { $tmpUrl = substr($tmpUrl, 0, -1); } $this->urlTokenList = explode('/', $tmpUrl); $this->urlTokenCount = count($this->urlTokenList); foreach($this->urlTokenList as $token) { $isMatchedForResourcePattern = preg_match(self::RESOURCE_PATTERN, $token, $resourceMatches, PREG_OFFSET_CAPTURE); if ($isMatchedForResourcePattern === 1) { array_push($this->resourceList, $resourceMatches[1][0]); } $isMatchedForParaPattern = preg_match(self::TOKEN_PARA_PATTERN, $token, $paramMatches, PREG_OFFSET_CAPTURE); } } public function getMethodList() { return $this->methodList; } public function getUrl() { return $this->url; } public function getUrlTokenList() { return $this->urlTokenList; } public function getUrlTokenCount() { return $this->urlTokenCount; } public function getController() { return $this->controller; } public function getAction() { return $this->action; } public function getTokenParameterList() { return $this->tokenParameterList; } public function getResourceList() { return $this->resourceList; } public function getResourceDetailList() { return $this->resourceDetailList; } public function isMatched($url) { return 0; } } $ROUTES = array( array('httpMethod' => 'GET', 'url' => '[:music_category]/xml', 'controller' => 'CategoryController', 'action' => 'xml'), array('httpMethod' => 'GET', 'url' => '[:music_category]/json', 'controller' => 'CategoryController', 'action' => 'json'), array('httpMethod' => 'GET|POST', 'url' => 'xml', 'controller' => 'temp_controller', 'action' => 'xml'), array('httpMethod' => 'GET|POST', 'url' => 'json', 'controller' => 'temp_controller', 'action' => 'json'), array('httpMethod' => 'GET|POST', 'url' => 'post/[:music_category]/{:data}/xml', 'controller' => 'CategoryController', 'action' => 'post') ); foreach ($ROUTES as $route) { $routeObj = new Route($route['httpMethod'], $route['url'], $route['controller'], $route['action']); print_r($routeObj->getMethodList()); printf($routeObj->getUrl()); print_r($routeObj->getUrlTokenList()); printf($routeObj->getController()); printf($routeObj->getAction()); print_r($routeObj->getTokenParameterList()); print_r($routeObj->getResourceList()); print_r($routeObj->getResourceDetailList()); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 59
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 59
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
filename:       /in/lPlhf
function name:  (null)
number of ops:  61
compiled vars:  !0 = $ROUTES, !1 = $route, !2 = $routeObj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   94     0  E >   ASSIGN                                                   !0, <array>
  103     1      > FE_RESET_R                                       $4      !0, ->59
          2    > > FE_FETCH_R                                               $4, !1, ->59
  105     3    >   NEW                                              $5      'Route'
          4        CHECK_FUNC_ARG                                           
          5        FETCH_DIM_FUNC_ARG                               $6      !1, 'httpMethod'
          6        SEND_FUNC_ARG                                            $6
          7        CHECK_FUNC_ARG                                           
          8        FETCH_DIM_FUNC_ARG                               $7      !1, 'url'
          9        SEND_FUNC_ARG                                            $7
         10        CHECK_FUNC_ARG                                           
         11        FETCH_DIM_FUNC_ARG                               $8      !1, 'controller'
         12        SEND_FUNC_ARG                                            $8
         13        CHECK_FUNC_ARG                                           
         14        FETCH_DIM_FUNC_ARG                               $9      !1, 'action'
         15        SEND_FUNC_ARG                                            $9
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !2, $5
  107    18        INIT_FCALL                                               'print_r'
         19        INIT_METHOD_CALL                                         !2, 'getMethodList'
         20        DO_FCALL                                      0  $12     
         21        SEND_VAR                                                 $12
         22        DO_ICALL                                                 
  108    23        INIT_FCALL                                               'printf'
         24        INIT_METHOD_CALL                                         !2, 'getUrl'
         25        DO_FCALL                                      0  $14     
         26        SEND_VAR                                                 $14
         27        DO_ICALL                                                 
  109    28        INIT_FCALL                                               'print_r'
         29        INIT_METHOD_CALL                                         !2, 'getUrlTokenList'
         30        DO_FCALL                                      0  $16     
         31        SEND_VAR                                                 $16
         32        DO_ICALL                                                 
  110    33        INIT_FCALL                                               'printf'
         34        INIT_METHOD_CALL                                         !2, 'getController'
         35        DO_FCALL                                      0  $18     
         36        SEND_VAR                                                 $18
         37        DO_ICALL                                                 
  111    38        INIT_FCALL                                               'printf'
         39        INIT_METHOD_CALL                                         !2, 'getAction'
         40        DO_FCALL                                      0  $20     
         41        SEND_VAR                                                 $20
         42        DO_ICALL                                                 
  112    43        INIT_FCALL                                               'print_r'
         44        INIT_METHOD_CALL                                         !2, 'getTokenParameterList'
         45        DO_FCALL                                      0  $22     
         46        SEND_VAR                                                 $22
         47        DO_ICALL                                                 
  113    48        INIT_FCALL                                               'print_r'
         49        INIT_METHOD_CALL                                         !2, 'getResourceList'
         50        DO_FCALL                                      0  $24     
         51        SEND_VAR                                                 $24
         52        DO_ICALL                                                 
  114    53        INIT_FCALL                                               'print_r'
         54        INIT_METHOD_CALL                                         !2, 'getResourceDetailList'
         55        DO_FCALL                                      0  $26     
         56        SEND_VAR                                                 $26
         57        DO_ICALL                                                 
  103    58      > JMP                                                      ->2
         59    >   FE_FREE                                                  $4
  115    60      > RETURN                                                   1

Class Route:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lPlhf
function name:  __construct
number of ops:  20
compiled vars:  !0 = $httpMethod, !1 = $httpUrl, !2 = $controller, !3 = $action
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   18     4        INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '%7C'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $5      
          8        ASSIGN_OBJ                                               'methodList'
          9        OP_DATA                                                  $5
   19    10        ASSIGN_OBJ                                               'httpUrl'
         11        OP_DATA                                                  !1
   20    12        ASSIGN_OBJ                                               'controller'
         13        OP_DATA                                                  !2
   21    14        ASSIGN_OBJ                                               'action'
         15        OP_DATA                                                  !3
   23    16        INIT_METHOD_CALL                                         'parseURL'
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0          
   25    19      > RETURN                                                   null

End of function __construct

Function parseurl:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 38, Position 2 = 63
Branch analysis from position: 38
2 jumps found. (Code = 78) Position 1 = 39, Position 2 = 63
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 55
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 55
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
Branch analysis from position: 26
Branch analysis from position: 14
filename:       /in/lPlhf
function name:  parseURL
number of ops:  65
compiled vars:  !0 = $url, !1 = $tmpUrl, !2 = $token, !3 = $isMatchedForResourcePattern, !4 = $resourceMatches, !5 = $isMatchedForParaPattern, !6 = $paramMatches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        ASSIGN                                                   !1, !0
   29     2        INIT_FCALL                                               'substr'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 1
          6        DO_ICALL                                         $8      
          7        IS_EQUAL                                                 $8, '%2F'
          8      > JMPZ                                                     ~9, ->14
   30     9    >   INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !1
         11        SEND_VAL                                                 1
         12        DO_ICALL                                         $10     
         13        ASSIGN                                                   !1, $10
   33    14    >   INIT_FCALL                                               'substr'
         15        SEND_VAR                                                 !1
         16        SEND_VAL                                                 -1
         17        DO_ICALL                                         $12     
         18        IS_EQUAL                                                 $12, '%2F'
         19      > JMPZ                                                     ~13, ->26
   34    20    >   INIT_FCALL                                               'substr'
         21        SEND_VAR                                                 !1
         22        SEND_VAL                                                 0
         23        SEND_VAL                                                 -1
         24        DO_ICALL                                         $14     
         25        ASSIGN                                                   !1, $14
   37    26    >   INIT_FCALL                                               'explode'
         27        SEND_VAL                                                 '%2F'
         28        SEND_VAR                                                 !1
         29        DO_ICALL                                         $17     
         30        ASSIGN_OBJ                                               'urlTokenList'
         31        OP_DATA                                                  $17
   39    32        FETCH_OBJ_R                                      ~19     'urlTokenList'
         33        COUNT                                            ~20     ~19
         34        ASSIGN_OBJ                                               'urlTokenCount'
         35        OP_DATA                                                  ~20
   41    36        FETCH_OBJ_R                                      ~21     'urlTokenList'
         37      > FE_RESET_R                                       $22     ~21, ->63
         38    > > FE_FETCH_R                                               $22, !2, ->63
   42    39    >   INIT_FCALL                                               'preg_match'
         40        SEND_VAL                                                 '%2F%5C%5B%3A%28.%2A%29%5C%5D%2F'
         41        SEND_VAR                                                 !2
         42        SEND_REF                                                 !4
         43        SEND_VAL                                                 256
         44        DO_ICALL                                         $23     
         45        ASSIGN                                                   !3, $23
   44    46        IS_IDENTICAL                                             !3, 1
         47      > JMPZ                                                     ~25, ->55
   45    48    >   INIT_FCALL                                               'array_push'
         49        FETCH_OBJ_W                                      $26     'resourceList'
         50        SEND_REF                                                 $26
         51        FETCH_DIM_R                                      ~27     !4, 1
         52        FETCH_DIM_R                                      ~28     ~27, 0
         53        SEND_VAL                                                 ~28
         54        DO_ICALL                                                 
   48    55    >   INIT_FCALL                                               'preg_match'
         56        SEND_VAL                                                 '%2F%5C%7B%3A%28.%2A%29%5C%7D%2F'
         57        SEND_VAR                                                 !2
         58        SEND_REF                                                 !6
         59        SEND_VAL                                                 256
         60        DO_ICALL                                         $30     
         61        ASSIGN                                                   !5, $30
   41    62      > JMP                                                      ->38
         63    >   FE_FREE                                                  $22
   51    64      > RETURN                                                   null

End of function parseurl

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

End of function getmethodlist

Function geturl:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lPlhf
function name:  getUrl
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   FETCH_OBJ_R                                      ~0      'url'
          1      > RETURN                                                   ~0
   59     2*     > RETURN                                                   null

End of function geturl

Function geturltokenlist:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lPlhf
function name:  getUrlTokenList
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   FETCH_OBJ_R                                      ~0      'urlTokenList'
          1      > RETURN                                                   ~0
   63     2*     > RETURN                                                   null

End of function geturltokenlist

Function geturltokencount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lPlhf
function name:  getUrlTokenCount
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   FETCH_OBJ_R                                      ~0      'urlTokenCount'
          1      > RETURN                                                   ~0
   67     2*     > RETURN                                                   null

End of function geturltokencount

Function getcontroller:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lPlhf
function name:  getController
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   FETCH_OBJ_R                                      ~0      'controller'
          1      > RETURN                                                   ~0
   71     2*     > RETURN                                                   null

End of function getcontroller

Function getaction:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lPlhf
function name:  getAction
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   FETCH_OBJ_R                                      ~0      'action'
          1      > RETURN                                                   ~0
   75     2*     > RETURN                                                   null

End of function getaction

Function gettokenparameterlist:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lPlhf
function name:  getTokenParameterList
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   FETCH_OBJ_R                                      ~0      'tokenParameterList'
          1      > RETURN                                                   ~0
   79     2*     > RETURN                                                   null

End of function gettokenparameterlist

Function getresourcelist:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lPlhf
function name:  getResourceList
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   FETCH_OBJ_R                                      ~0      'resourceList'
          1      > RETURN                                                   ~0
   83     2*     > RETURN                                                   null

End of function getresourcelist

Function getresourcedetaillist:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lPlhf
function name:  getResourceDetailList
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   FETCH_OBJ_R                                      ~0      'resourceDetailList'
          1      > RETURN                                                   ~0
   87     2*     > RETURN                                                   null

End of function getresourcedetaillist

Function ismatched:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lPlhf
function name:  isMatched
number of ops:  3
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   RECV                                             !0      
   90     1      > RETURN                                                   0
   91     2*     > RETURN                                                   null

End of function ismatched

End of class Route.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.88 ms | 1416 KiB | 25 Q