3v4l.org

run code in 300+ PHP versions simultaneously
<?php class RegexValidator implements ValidatorRuleInterface { private array $reviewResources = [ "formatForSymbols" => 'В этом поле можно использовать следующие символы: %s. Вы использовали символ(ы), который не входит в этот список, а именно - %s', "formatForString" => 'Поле должно иметь следующий вид: %s. Вы написали - %s', ]; public function __construct(string $patternForSymbol, string $patternForString, array $verbalDescriptionOfPatterns) { $this->reviewResources["patternForSymbol"] = $patternForSymbol; $this->reviewResources["patternForString"] = $patternForString; $this->reviewResources["verbalDescriptionOfPatterns"] = $verbalDescriptionOfPatterns; } private function checkSymbols (mixed $value): ?array { $numberOfCharacters = iconv_strlen($value); for ($i=0; $i<$numberOfCharacters; $i++) { $letter = $value[$i]; $result = preg_match($this->reviewResources["patternForSymbol"]); if (!$result) { $invalidSymbols [] = $letter; } } return ($invalidSymbols) ? $invalidSymbols : null; } private function checkString (mixed $value): bool { return preg_match($this->reviewResources["patternForString"], $value); } public function __invoke (mixed $value): ?ValidationError { $resultForSymbol = $this->checkSymbols($value); $resultForString = $this->checkString($value); if ($resultForSymbol) { $result .= sprintf( $this->reviewResources["formatForSymbols"], $this->reviewResources["verbalDescriptionOfPatterns"]["symbols"], implode(", ", $resultForSymbol) ); } if (!$resultForString) { $result .= sprintf( $this->reviewResources["formatForString"], $this->reviewResources["verbalDescriptionOfPatterns"]["string"], $value ); } ($result) ? new ValidationError($result) : null; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/of0e9
function name:  (null)
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'regexvalidator'
   62     1      > RETURN                                                   1

Class RegexValidator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/of0e9
function name:  __construct
number of ops:  13
compiled vars:  !0 = $patternForSymbol, !1 = $patternForString, !2 = $verbalDescriptionOfPatterns
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   12     3        FETCH_OBJ_W                                      $3      'reviewResources'
          4        ASSIGN_DIM                                               $3, 'patternForSymbol'
          5        OP_DATA                                                  !0
   13     6        FETCH_OBJ_W                                      $5      'reviewResources'
          7        ASSIGN_DIM                                               $5, 'patternForString'
          8        OP_DATA                                                  !1
   14     9        FETCH_OBJ_W                                      $7      'reviewResources'
         10        ASSIGN_DIM                                               $7, 'verbalDescriptionOfPatterns'
         11        OP_DATA                                                  !2
   15    12      > RETURN                                                   null

End of function __construct

Function checksymbols:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 7
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 7
Branch analysis from position: 22
Branch analysis from position: 7
Branch analysis from position: 19
filename:       /in/of0e9
function name:  checkSymbols
number of ops:  30
compiled vars:  !0 = $value, !1 = $numberOfCharacters, !2 = $i, !3 = $letter, !4 = $result, !5 = $invalidSymbols
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        INIT_FCALL_BY_NAME                                       'iconv_strlen'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $6      
          4        ASSIGN                                                   !1, $6
   21     5        ASSIGN                                                   !2, 0
          6      > JMP                                                      ->20
   23     7    >   FETCH_DIM_R                                      ~9      !0, !2
          8        ASSIGN                                                   !3, ~9
   24     9        INIT_FCALL                                               'preg_match'
         10        FETCH_OBJ_R                                      ~11     'reviewResources'
         11        FETCH_DIM_R                                      ~12     ~11, 'patternForSymbol'
         12        SEND_VAL                                                 ~12
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !4, $13
   25    15        BOOL_NOT                                         ~15     !4
         16      > JMPZ                                                     ~15, ->19
   27    17    >   ASSIGN_DIM                                               !5
         18        OP_DATA                                                  !3
   21    19    >   PRE_INC                                                  !2
         20    >   IS_SMALLER                                               !2, !1
         21      > JMPNZ                                                    ~18, ->7
   30    22    > > JMPZ                                                     !5, ->25
         23    >   QM_ASSIGN                                        ~19     !5
         24      > JMP                                                      ->26
         25    >   QM_ASSIGN                                        ~19     null
         26    >   VERIFY_RETURN_TYPE                                       ~19
         27      > RETURN                                                   ~19
   31    28*       VERIFY_RETURN_TYPE                                       
         29*     > RETURN                                                   null

End of function checksymbols

Function checkstring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/of0e9
function name:  checkString
number of ops:  11
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   35     1        INIT_FCALL                                               'preg_match'
          2        FETCH_OBJ_R                                      ~1      'reviewResources'
          3        FETCH_DIM_R                                      ~2      ~1, 'patternForString'
          4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        VERIFY_RETURN_TYPE                                       $3
          8      > RETURN                                                   $3
   36     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function checkstring

Function __invoke:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 25
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 38
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 44
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 25
filename:       /in/of0e9
function name:  __invoke
number of ops:  48
compiled vars:  !0 = $value, !1 = $resultForSymbol, !2 = $resultForString, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   40     1        INIT_METHOD_CALL                                         'checkSymbols'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
   41     5        INIT_METHOD_CALL                                         'checkString'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !2, $6
   42     9      > JMPZ                                                     !1, ->25
   44    10    >   INIT_FCALL                                               'sprintf'
   45    11        FETCH_OBJ_R                                      ~8      'reviewResources'
         12        FETCH_DIM_R                                      ~9      ~8, 'formatForSymbols'
         13        SEND_VAL                                                 ~9
   46    14        FETCH_OBJ_R                                      ~10     'reviewResources'
         15        FETCH_DIM_R                                      ~11     ~10, 'verbalDescriptionOfPatterns'
         16        FETCH_DIM_R                                      ~12     ~11, 'symbols'
         17        SEND_VAL                                                 ~12
   47    18        INIT_FCALL                                               'implode'
         19        SEND_VAL                                                 '%2C+'
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                         $13     
         22        SEND_VAR                                                 $13
   44    23        DO_ICALL                                         $14     
   47    24        ASSIGN_OP                                     8          !3, $14
   51    25    >   BOOL_NOT                                         ~16     !2
         26      > JMPZ                                                     ~16, ->38
   53    27    >   INIT_FCALL                                               'sprintf'
   54    28        FETCH_OBJ_R                                      ~17     'reviewResources'
         29        FETCH_DIM_R                                      ~18     ~17, 'formatForString'
         30        SEND_VAL                                                 ~18
   55    31        FETCH_OBJ_R                                      ~19     'reviewResources'
         32        FETCH_DIM_R                                      ~20     ~19, 'verbalDescriptionOfPatterns'
         33        FETCH_DIM_R                                      ~21     ~20, 'string'
         34        SEND_VAL                                                 ~21
   56    35        SEND_VAR                                                 !0
   53    36        DO_ICALL                                         $22     
   56    37        ASSIGN_OP                                     8          !3, $22
   60    38    > > JMPZ                                                     !3, ->44
         39    >   NEW                                              $24     'ValidationError'
         40        SEND_VAR_EX                                              !3
         41        DO_FCALL                                      0          
         42        QM_ASSIGN                                        ~26     $24
         43      > JMP                                                      ->45
         44    >   QM_ASSIGN                                        ~26     null
         45    >   FREE                                                     ~26
   61    46        VERIFY_RETURN_TYPE                                       
         47      > RETURN                                                   null

End of function __invoke

End of class RegexValidator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.71 ms | 1013 KiB | 16 Q