3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace Crell\ObjectAnalyzer; class ObjectAnalyzer { public function analyze(string|object $class, string $attribute): object { $subject = match (is_string($class)) { true => new \ReflectionClass($class), false => new \ReflectionObject($class), }; $classDef = $this->getAttribute($subject, $attribute) ?? new $attribute; if ($classDef instanceof ReflectionPopulatable) { $classDef->fromReflection($subject); } if ($classDef instanceof Fieldable) { $fields = $this->getPropertyDefinitions($subject, $classDef::propertyAttribute()); $classDef->setFields($fields); } return $classDef; } /** * @return Field[] */ protected function getPropertyDefinitions(\ReflectionObject|\ReflectionClass $subject, string $propertyAttribute): array { // The list of filters here is going to grow, so wants pipes. $rProperties = $subject->getProperties(); // Wants PFA $properties = array_map(fn(\ReflectionProperty $p) => $this->getPropertyDefinition($p, $propertyAttribute), $rProperties); //$fields = array_filter($fields, fn(Field $f): bool => !$f->skip); return $properties; } // Wants a generic return. protected function getPropertyDefinition(\ReflectionProperty $property, string $propertyAttribute): object { $propDef = $this->getAttribute($property, $propertyAttribute) ?? new $propertyAttribute(); if ($propDef instanceof ReflectionPopulatable) { $propDef->fromReflection($property); } return $propDef; } protected function getAttribute(\Reflector $target, string $name): ?object { return $this->getAttributes($target, $name)[0] ?? null; } protected function getAttributes(\Reflector $target, string $name): array { return array_map(fn(\ReflectionAttribute $attrib) => $attrib->newInstance(), $target->getAttributes($name, \ReflectionAttribute::IS_INSTANCEOF)); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEpac
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E > > RETURN                                                   1

Function %00crell%5Cobjectanalyzer%5C%7Bclosure%7D%2Fin%2FjEpac%3A39%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEpac
function name:  Crell\ObjectAnalyzer\{closure}
number of ops:  9
compiled vars:  !0 = $p, !1 = $propertyAttribute
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        FETCH_THIS                                       $2      
          3        INIT_METHOD_CALL                                         $2, 'getPropertyDefinition'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
          8*     > RETURN                                                   null

End of function %00crell%5Cobjectanalyzer%5C%7Bclosure%7D%2Fin%2FjEpac%3A39%240

Function %00crell%5Cobjectanalyzer%5C%7Bclosure%7D%2Fin%2FjEpac%3A62%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEpac
function name:  Crell\ObjectAnalyzer\{closure}
number of ops:  5
compiled vars:  !0 = $attrib
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
   63     1        INIT_METHOD_CALL                                         !0, 'newInstance'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
          4*     > RETURN                                                   null

End of function %00crell%5Cobjectanalyzer%5C%7Bclosure%7D%2Fin%2FjEpac%3A62%241

Class Crell\ObjectAnalyzer\ObjectAnalyzer:
Function analyze:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 197) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 51
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
Branch analysis from position: 38
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
filename:       /in/jEpac
function name:  analyze
number of ops:  55
compiled vars:  !0 = $class, !1 = $attribute, !2 = $subject, !3 = $classDef, !4 = $fields
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        INIT_NS_FCALL_BY_NAME                                    'Crell%5CObjectAnalyzer%5Cis_string'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $5      
          5        CASE_STRICT                                              $5, <true>
          6      > JMPNZ                                                    ~6, ->11
   14     7    >   CASE_STRICT                                              $5, <false>
          8      > JMPNZ                                                    ~6, ->16
          9    > > JMP                                                      ->10
         10    > > MATCH_ERROR                                              $5
   13    11    >   NEW                                              $7      'ReflectionClass'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
         14        QM_ASSIGN                                        ~9      $7
         15      > JMP                                                      ->21
   14    16    >   NEW                                              $10     'ReflectionObject'
         17        SEND_VAR_EX                                              !0
         18        DO_FCALL                                      0          
         19        QM_ASSIGN                                        ~9      $10
         20      > JMP                                                      ->21
         21    >   FREE                                                     $5
   12    22        ASSIGN                                                   !2, ~9
   17    23        INIT_METHOD_CALL                                         'getAttribute'
         24        SEND_VAR_EX                                              !2
         25        SEND_VAR_EX                                              !1
         26        DO_FCALL                                      0  $13     
         27        COALESCE                                         ~14     $13
         28        FETCH_CLASS                                   0  $15     !1
         29        NEW                                              $16     $15
         30        DO_FCALL                                      0          
         31        QM_ASSIGN                                        ~14     $16
         32        ASSIGN                                                   !3, ~14
   19    33        INSTANCEOF                                               !3, 'Crell%5CObjectAnalyzer%5CReflectionPopulatable'
         34      > JMPZ                                                     ~19, ->38
   20    35    >   INIT_METHOD_CALL                                         !3, 'fromReflection'
         36        SEND_VAR_EX                                              !2
         37        DO_FCALL                                      0          
   23    38    >   INSTANCEOF                                               !3, 'Crell%5CObjectAnalyzer%5CFieldable'
         39      > JMPZ                                                     ~21, ->51
   24    40    >   INIT_METHOD_CALL                                         'getPropertyDefinitions'
         41        SEND_VAR_EX                                              !2
         42        FETCH_CLASS                                   0  $22     !3
         43        INIT_STATIC_METHOD_CALL                                  $22, 'propertyAttribute'
         44        DO_FCALL                                      0  $23     
         45        SEND_VAR_NO_REF_EX                                       $23
         46        DO_FCALL                                      0  $24     
         47        ASSIGN                                                   !4, $24
   25    48        INIT_METHOD_CALL                                         !3, 'setFields'
         49        SEND_VAR_EX                                              !4
         50        DO_FCALL                                      0          
   28    51    >   VERIFY_RETURN_TYPE                                       !3
         52      > RETURN                                                   !3
   29    53*       VERIFY_RETURN_TYPE                                       
         54*     > RETURN                                                   null

End of function analyze

Function getpropertydefinitions:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEpac
function name:  getPropertyDefinitions
number of ops:  16
compiled vars:  !0 = $subject, !1 = $propertyAttribute, !2 = $rProperties, !3 = $properties
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   37     2        INIT_METHOD_CALL                                         !0, 'getProperties'
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !2, $4
   39     5        INIT_NS_FCALL_BY_NAME                                    'Crell%5CObjectAnalyzer%5Carray_map'
          6        DECLARE_LAMBDA_FUNCTION                                  '%00crell%5Cobjectanalyzer%5C%7Bclosure%7D%2Fin%2FjEpac%3A39%240'
          7        BIND_LEXICAL                                             ~6, !1
          8        SEND_VAL_EX                                              ~6
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !3, $7
   41    12        VERIFY_RETURN_TYPE                                       !3
         13      > RETURN                                                   !3
   42    14*       VERIFY_RETURN_TYPE                                       
         15*     > RETURN                                                   null

End of function getpropertydefinitions

Function getpropertydefinition:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/jEpac
function name:  getPropertyDefinition
number of ops:  21
compiled vars:  !0 = $property, !1 = $propertyAttribute, !2 = $propDef
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   47     2        INIT_METHOD_CALL                                         'getAttribute'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $3      
          6        COALESCE                                         ~4      $3
          7        FETCH_CLASS                                   0  $5      !1
          8        NEW                                              $6      $5
          9        DO_FCALL                                      0          
         10        QM_ASSIGN                                        ~4      $6
         11        ASSIGN                                                   !2, ~4
   48    12        INSTANCEOF                                               !2, 'Crell%5CObjectAnalyzer%5CReflectionPopulatable'
         13      > JMPZ                                                     ~9, ->17
   49    14    >   INIT_METHOD_CALL                                         !2, 'fromReflection'
         15        SEND_VAR_EX                                              !0
         16        DO_FCALL                                      0          
   52    17    >   VERIFY_RETURN_TYPE                                       !2
         18      > RETURN                                                   !2
   53    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function getpropertydefinition

Function getattribute:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEpac
function name:  getAttribute
number of ops:  13
compiled vars:  !0 = $target, !1 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   57     2        INIT_METHOD_CALL                                         'getAttributes'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $2      
          6        FETCH_DIM_IS                                     ~3      $2, 0
          7        COALESCE                                         ~4      ~3
          8        QM_ASSIGN                                        ~4      null
          9        VERIFY_RETURN_TYPE                                       ~4
         10      > RETURN                                                   ~4
   58    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function getattribute

Function getattributes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEpac
function name:  getAttributes
number of ops:  15
compiled vars:  !0 = $target, !1 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   62     2        INIT_NS_FCALL_BY_NAME                                    'Crell%5CObjectAnalyzer%5Carray_map'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00crell%5Cobjectanalyzer%5C%7Bclosure%7D%2Fin%2FjEpac%3A62%241'
   63     4        SEND_VAL_EX                                              ~2
          5        INIT_METHOD_CALL                                         !0, 'getAttributes'
          6        SEND_VAR_EX                                              !1
          7        SEND_VAL_EX                                              2
          8        DO_FCALL                                      0  $3      
          9        SEND_VAR_NO_REF_EX                                       $3
         10        DO_FCALL                                      0  $4      
         11        VERIFY_RETURN_TYPE                                       $4
         12      > RETURN                                                   $4
   64    13*       VERIFY_RETURN_TYPE                                       
         14*     > RETURN                                                   null

End of function getattributes

End of class Crell\ObjectAnalyzer\ObjectAnalyzer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
125.46 ms | 1413 KiB | 17 Q