3v4l.org

run code in 300+ PHP versions simultaneously
<?php const VALUE_FORMAT_RAW = "raw"; const VALUE_FORMAT_TAG_NAME_VALUE_ASSOC = "tagNameValueAssoc"; const VALUE_FORMAT_ARRAY = "array"; function formatArgumentValue(SimpleXMLElement $node, $options) { switch ($options["format"]) { // Associative array from each children of the target node that have the tag name as key and // the tag value as value case VALUE_FORMAT_TAG_NAME_VALUE_ASSOC: $assoc = []; // Recursively get the associative array for the node foreach ($node->children() as $nodePart) { if($nodePart->count() > 0) { $format = VALUE_FORMAT_TAG_NAME_VALUE_ASSOC; if (!empty($nodePart->attributes()->type) && $nodePart->attributes()->type == "array") { $format = VALUE_FORMAT_ARRAY; } $assoc[$nodePart->getName()] = $this->formatArgumentValue($nodePart, ["format" => $format]); } else { // If the value is already defined, we say that the value is an array and add the new value to it if(!empty($assoc[$nodePart->getName()])) { if(!is_array($assoc[$nodePart->getName()])) { $assoc[$nodePart->getName()] = [$assoc[$nodePart->getName()]]; } $assoc[$nodePart->getName()][] = $this->resolveValueString((string) $nodePart); } else { $assoc[$nodePart->getName()] = $this->resolveValueString((string) $nodePart); } } } $argumentValue = $assoc; break; case VALUE_FORMAT_ARRAY: $children = []; $i = 0; foreach($node->children() as $child) { // Get the path for the key $key = $i++; // Set the default key as a regular numbered autoincremented index // NOTE: Here a post-increment is done, the value copied to $key is $i BEFORE // it being incremented. The array will start at 0, even if the increment is done at // the beginning of the string. if(!empty($options['childrenKey'])) { $key = (string) $this->walkNodePath($options['childrenKey'], $child); } $children[$key] = $this->formatArgumentValue($child, ["format" => $options["childrenFormat"]]); } $argumentValue = $children; break; // Raw string value of the tag as value. Default. case VALUE_FORMAT_RAW: default: $argumentValue = $this->resolveValueString((string) $node); break; } return $argumentValue; } $xml = <<<EOL <config> <formatters> <fileformatter> <class>Monolog\Formatter\LineFormatter</class> <format>[%datetime%] %level_name%: %message%&#xA;</format> </fileformatter> <mongoformatter> <class>Bettr\Service\Log\Formatter\MongoDBFormatter</class> </mongoformatter> </formatters> <handlers> <filelog> <class>Monolog\Handler\StreamHandler</class> <level>DEBUG</level> <formatter>fileformatter</formatter> <processors>psr_processor</processors> <stream>../system/var/logs/debug.log</stream> </filelog> <mongolog> <class>Bettr\Service\Log\Handler\MongoServiceHandler</class> <level>ERROR</level> <formatter>mongoformatter</formatter> <mongoManager>{service:mongo}</mongoManager> <processors type="array">psr_processor</processors> <collection>logger</collection> </mongolog> </handlers> <processors> <psr_processor> <class>Monolog\Processor\PsrLogMessageProcessor</class> </psr_processor> </processors> <loggers> <bettr> <handlers type="array"> <handler>filelog</handler> <handler>mongolog</handler> </handlers> </bettr> </loggers> </config> EOL; $simpleXMLElement = new SimpleXMLElement($xml); var_dump(formatArgumentValue($simpleXMLElement, ["format" => VALUE_FORMAT_TAG_NAME_VALUE_ASSOC]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ERLft
function name:  (null)
number of ops:  18
compiled vars:  !0 = $xml, !1 = $simpleXMLElement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                            'VALUE_FORMAT_RAW', 'raw'
    4     1        DECLARE_CONST                                            'VALUE_FORMAT_TAG_NAME_VALUE_ASSOC', 'tagNameValueAssoc'
    5     2        DECLARE_CONST                                            'VALUE_FORMAT_ARRAY', 'array'
   73     3        ASSIGN                                                   !0, '++++%3Cconfig%3E%0A++++++++%3Cformatters%3E%0A++++++++++++%3Cfileformatter%3E%0A++++++++++++++++%3Cclass%3EMonolog%5CFormatter%5CLineFormatter%3C%2Fclass%3E%0A++++++++++++++++%3Cformat%3E%5B%25datetime%25%5D+%25level_name%25%3A+%25message%25%26%23xA%3B%3C%2Fformat%3E%0A++++++++++++%3C%2Ffileformatter%3E%0A%0A++++++++++++%3Cmongoformatter%3E%0A++++++++++++++++%3Cclass%3EBettr%5CService%5CLog%5CFormatter%5CMongoDBFormatter%3C%2Fclass%3E%0A++++++++++++%3C%2Fmongoformatter%3E%0A++++++++%3C%2Fformatters%3E%0A++++++++%0A++++++++%3Chandlers%3E%0A++++++++++++%3Cfilelog%3E%0A++++++++++++++++%3Cclass%3EMonolog%5CHandler%5CStreamHandler%3C%2Fclass%3E%0A++++++++++++++++%3Clevel%3EDEBUG%3C%2Flevel%3E%0A++++++++++++++++%3Cformatter%3Efileformatter%3C%2Fformatter%3E%0A++++++++++++++++%3Cprocessors%3Epsr_processor%3C%2Fprocessors%3E%0A++++++++++++++++%3Cstream%3E..%2Fsystem%2Fvar%2Flogs%2Fdebug.log%3C%2Fstream%3E%0A++++++++++++%3C%2Ffilelog%3E%0A%0A++++++++++++%3Cmongolog%3E%0A++++++++++++++++%3Cclass%3EBettr%5CService%5CLog%5CHandler%5CMongoServiceHandler%3C%2Fclass%3E%0A++++++++++++++++%3Clevel%3EERROR%3C%2Flevel%3E%0A++++++++++++++++%3Cformatter%3Emongoformatter%3C%2Fformatter%3E%0A++++++++++++++++%3CmongoManager%3E%7Bservice%3Amongo%7D%3C%2FmongoManager%3E%0A++++++++++++++++%3Cprocessors+type%3D%22array%22%3Epsr_processor%3C%2Fprocessors%3E%0A++++++++++++++++%3Ccollection%3Elogger%3C%2Fcollection%3E%0A++++++++++++%3C%2Fmongolog%3E%0A++++++++%3C%2Fhandlers%3E%0A%0A++++++++%3Cprocessors%3E%0A++++++++++++%3Cpsr_processor%3E%0A++++++++++++++++%3Cclass%3EMonolog%5CProcessor%5CPsrLogMessageProcessor%3C%2Fclass%3E%0A++++++++++++%3C%2Fpsr_processor%3E%0A++++++++%3C%2Fprocessors%3E%0A%0A++++++++%3Cloggers%3E%0A++++++++++++%3Cbettr%3E%0A++++++++++++++++%3Chandlers+type%3D%22array%22%3E%0A++++++++++++++++++++%3Chandler%3Efilelog%3C%2Fhandler%3E%0A++++++++++++++++++++%3Chandler%3Emongolog%3C%2Fhandler%3E%0A++++++++++++++++%3C%2Fhandlers%3E%0A++++++++++++%3C%2Fbettr%3E%0A++++++++%3C%2Floggers%3E%0A++++%3C%2Fconfig%3E'
  122     4        NEW                                              $3      'SimpleXMLElement'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $3
  124     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'formatargumentvalue'
         10        SEND_VAR                                                 !1
         11        FETCH_CONSTANT                                   ~6      'VALUE_FORMAT_TAG_NAME_VALUE_ASSOC'
         12        INIT_ARRAY                                       ~7      ~6, 'format'
         13        SEND_VAL                                                 ~7
         14        DO_FCALL                                      0  $8      
         15        SEND_VAR                                                 $8
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function formatargumentvalue:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 91
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 124
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 124
Branch analysis from position: 124
1 jumps found. (Code = 42) Position 1 = 131
Branch analysis from position: 131
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 124
Branch analysis from position: 91
2 jumps found. (Code = 77) Position 1 = 96, Position 2 = 121
Branch analysis from position: 96
2 jumps found. (Code = 78) Position 1 = 97, Position 2 = 121
Branch analysis from position: 97
2 jumps found. (Code = 43) Position 1 = 102, Position 2 = 111
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 96
Branch analysis from position: 96
Branch analysis from position: 111
Branch analysis from position: 121
1 jumps found. (Code = 42) Position 1 = 131
Branch analysis from position: 131
Branch analysis from position: 121
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 88
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 88
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 48
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 87
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 37
Branch analysis from position: 34
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 78
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 67
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 87
Branch analysis from position: 87
Branch analysis from position: 67
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 88
1 jumps found. (Code = 42) Position 1 = 131
Branch analysis from position: 131
Branch analysis from position: 88
filename:       /in/ERLft
function name:  formatArgumentValue
number of ops:  134
compiled vars:  !0 = $node, !1 = $options, !2 = $assoc, !3 = $nodePart, !4 = $format, !5 = $argumentValue, !6 = $children, !7 = $i, !8 = $child, !9 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        FETCH_DIM_R                                      ~10     !1, 'format'
   12     3        FETCH_CONSTANT                                   ~12     'VALUE_FORMAT_TAG_NAME_VALUE_ASSOC'
          4        CASE                                                     ~10, ~12
          5      > JMPNZ                                                    ~11, ->13
   42     6    >   FETCH_CONSTANT                                   ~13     'VALUE_FORMAT_ARRAY'
          7        CASE                                                     ~10, ~13
          8      > JMPNZ                                                    ~11, ->91
   64     9    >   FETCH_CONSTANT                                   ~14     'VALUE_FORMAT_RAW'
         10        CASE                                                     ~10, ~14
         11      > JMPNZ                                                    ~11, ->124
         12    > > JMP                                                      ->124
   13    13    >   ASSIGN                                                   !2, <array>
   16    14        INIT_METHOD_CALL                                         !0, 'children'
         15        DO_FCALL                                      0  $16     
         16      > FE_RESET_R                                       $17     $16, ->88
         17    > > FE_FETCH_R                                               $17, !3, ->88
   17    18    >   INIT_METHOD_CALL                                         !3, 'count'
         19        DO_FCALL                                      0  $18     
         20        IS_SMALLER                                               0, $18
         21      > JMPZ                                                     ~19, ->48
   18    22    >   FETCH_CONSTANT                                   ~20     'VALUE_FORMAT_TAG_NAME_VALUE_ASSOC'
         23        ASSIGN                                                   !4, ~20
   20    24        INIT_METHOD_CALL                                         !3, 'attributes'
         25        DO_FCALL                                      0  $22     
         26        ISSET_ISEMPTY_PROP_OBJ                           ~23     $22, 'type'
         27        BOOL_NOT                                         ~24     ~23
         28      > JMPZ_EX                                          ~24     ~24, ->34
         29    >   INIT_METHOD_CALL                                         !3, 'attributes'
         30        DO_FCALL                                      0  $25     
         31        FETCH_OBJ_R                                      ~26     $25, 'type'
         32        IS_EQUAL                                         ~27     ~26, 'array'
         33        BOOL                                             ~24     ~27
         34    > > JMPZ                                                     ~24, ->37
   21    35    >   FETCH_CONSTANT                                   ~28     'VALUE_FORMAT_ARRAY'
         36        ASSIGN                                                   !4, ~28
   24    37    >   INIT_METHOD_CALL                                         !3, 'getName'
         38        DO_FCALL                                      0  $30     
         39        FETCH_THIS                                       $32     
         40        INIT_METHOD_CALL                                         $32, 'formatArgumentValue'
         41        SEND_VAR_EX                                              !3
         42        INIT_ARRAY                                       ~33     !4, 'format'
         43        SEND_VAL_EX                                              ~33
         44        DO_FCALL                                      0  $34     
         45        ASSIGN_DIM                                               !2, $30
         46        OP_DATA                                                  $34
         47      > JMP                                                      ->87
   27    48    >   INIT_METHOD_CALL                                         !3, 'getName'
         49        DO_FCALL                                      0  $35     
         50        ISSET_ISEMPTY_DIM_OBJ                         1  ~36     !2, $35
         51        BOOL_NOT                                         ~37     ~36
         52      > JMPZ                                                     ~37, ->78
   28    53    >   INIT_METHOD_CALL                                         !3, 'getName'
         54        DO_FCALL                                      0  $38     
         55        FETCH_DIM_R                                      ~39     !2, $38
         56        TYPE_CHECK                                  128  ~40     ~39
         57        BOOL_NOT                                         ~41     ~40
         58      > JMPZ                                                     ~41, ->67
   29    59    >   INIT_METHOD_CALL                                         !3, 'getName'
         60        DO_FCALL                                      0  $42     
         61        INIT_METHOD_CALL                                         !3, 'getName'
         62        DO_FCALL                                      0  $44     
         63        FETCH_DIM_R                                      ~45     !2, $44
         64        INIT_ARRAY                                       ~46     ~45
         65        ASSIGN_DIM                                               !2, $42
         66        OP_DATA                                                  ~46
   32    67    >   INIT_METHOD_CALL                                         !3, 'getName'
         68        DO_FCALL                                      0  $47     
         69        FETCH_THIS                                       $50     
         70        INIT_METHOD_CALL                                         $50, 'resolveValueString'
         71        CAST                                          6  ~51     !3
         72        SEND_VAL_EX                                              ~51
         73        DO_FCALL                                      0  $52     
         74        FETCH_DIM_W                                      $48     !2, $47
         75        ASSIGN_DIM                                               $48
         76        OP_DATA                                                  $52
         77      > JMP                                                      ->87
   34    78    >   INIT_METHOD_CALL                                         !3, 'getName'
         79        DO_FCALL                                      0  $53     
         80        FETCH_THIS                                       $55     
         81        INIT_METHOD_CALL                                         $55, 'resolveValueString'
         82        CAST                                          6  ~56     !3
         83        SEND_VAL_EX                                              ~56
         84        DO_FCALL                                      0  $57     
         85        ASSIGN_DIM                                               !2, $53
         86        OP_DATA                                                  $57
   16    87    > > JMP                                                      ->17
         88    >   FE_FREE                                                  $17
   39    89        ASSIGN                                                   !5, !2
   40    90      > JMP                                                      ->131
   43    91    >   ASSIGN                                                   !6, <array>
   44    92        ASSIGN                                                   !7, 0
   45    93        INIT_METHOD_CALL                                         !0, 'children'
         94        DO_FCALL                                      0  $61     
         95      > FE_RESET_R                                       $62     $61, ->121
         96    > > FE_FETCH_R                                               $62, !8, ->121
   48    97    >   POST_INC                                         ~63     !7
         98        ASSIGN                                                   !9, ~63
   53    99        ISSET_ISEMPTY_DIM_OBJ                         1  ~65     !1, 'childrenKey'
        100        BOOL_NOT                                         ~66     ~65
        101      > JMPZ                                                     ~66, ->111
   54   102    >   FETCH_THIS                                       $67     
        103        INIT_METHOD_CALL                                         $67, 'walkNodePath'
        104        CHECK_FUNC_ARG                                           
        105        FETCH_DIM_FUNC_ARG                               $68     !1, 'childrenKey'
        106        SEND_FUNC_ARG                                            $68
        107        SEND_VAR_EX                                              !8
        108        DO_FCALL                                      0  $69     
        109        CAST                                          6  ~70     $69
        110        ASSIGN                                                   !9, ~70
   57   111    >   FETCH_THIS                                       $73     
        112        INIT_METHOD_CALL                                         $73, 'formatArgumentValue'
        113        SEND_VAR_EX                                              !8
        114        FETCH_DIM_R                                      ~74     !1, 'childrenFormat'
        115        INIT_ARRAY                                       ~75     ~74, 'format'
        116        SEND_VAL_EX                                              ~75
        117        DO_FCALL                                      0  $76     
        118        ASSIGN_DIM                                               !6, !9
        119        OP_DATA                                                  $76
   45   120      > JMP                                                      ->96
        121    >   FE_FREE                                                  $62
   60   122        ASSIGN                                                   !5, !6
   61   123      > JMP                                                      ->131
   66   124    >   FETCH_THIS                                       $78     
        125        INIT_METHOD_CALL                                         $78, 'resolveValueString'
        126        CAST                                          6  ~79     !0
        127        SEND_VAL_EX                                              ~79
        128        DO_FCALL                                      0  $80     
        129        ASSIGN                                                   !5, $80
   67   130      > JMP                                                      ->131
        131    >   FREE                                                     ~10
   70   132      > RETURN                                                   !5
   71   133*     > RETURN                                                   null

End of function formatargumentvalue

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.12 ms | 1422 KiB | 17 Q