3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ContentSecurityPolicy { const DEFAULT_SRC = 'default-src'; const SCRIPT_SRC = 'script-src'; const OBJECT_SRC = 'object-src'; const STYLE_SRC = 'style-src'; const IMG_SRC = 'img-src'; const MEDIA_SRC = 'media-src'; const FRAME_SRC = 'frame-src'; const FONT_SRC = 'font-src'; const CONNECT_SRC = 'connect-src'; const SOURCE_NONE = "'none'"; const SOURCE_SELF = "'self'"; const SOURCE_UNSAFE_INLINE = "'unsafe-inline'"; const SOURCE_UNSAFE_EVAL = "'unsafe-eval'"; private $policy; public function __construct() { $this->policy = array(); $this->policy[self::DEFAULT_SRC] = array(); $this->policy[self::SCRIPT_SRC] = array(); $this->policy[self::OBJECT_SRC] = array(); $this->policy[self::STYLE_SRC] = array(); $this->policy[self::IMG_SRC] = array(); $this->policy[self::MEDIA_SRC] = array(); $this->policy[self::FRAME_SRC] = array(); $this->policy[self::FONT_SRC] = array(); $this->policy[self::CONNECT_SRC] = array(); } private function copy() { $retval = new ContentSecurityPolicy(); foreach ($this->policy as $directive => $sources) { foreach ($sources as $source) { array_push($retval->policy[$directive], $source); } } return $retval; } function addSource($directive, $source) { if (!isset($this->policy[$directive])) { throw new CSPException("Invalid directive"); } $this->policy[$directive][] = $source; return $this; } function toString() { $retval = array(); foreach ($this->policy as $directive => $sources) { if (sizeof($sources) > 0) { $retval[] = join(' ', [$directive, join(' ', $sources)]); } } return join('; ', $retval); } } class CSPException extends \Exception {} $CSP = new ContentSecurityPolicy(); $csp->addSource(ContentSecurityPolicy::DEFAULT_SRC, ContentSecurityPolicy::SOURCE_SELF); $csp->addSource(ContentSecurityPolicy::STYLE_SRC, 'something else'); echo $CSP->toString(); exit("\nDone!\n");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/N8k0m
function name:  (null)
number of ops:  16
compiled vars:  !0 = $CSP, !1 = $csp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   NEW                                              $2      'ContentSecurityPolicy'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   65     3        INIT_METHOD_CALL                                         !1, 'addSource'
          4        SEND_VAL_EX                                              'default-src'
          5        SEND_VAL_EX                                              '%27self%27'
          6        DO_FCALL                                      0          
   66     7        INIT_METHOD_CALL                                         !1, 'addSource'
          8        SEND_VAL_EX                                              'style-src'
          9        SEND_VAL_EX                                              'something+else'
         10        DO_FCALL                                      0          
   67    11        INIT_METHOD_CALL                                         !0, 'toString'
         12        DO_FCALL                                      0  $7      
         13        ECHO                                                     $7
   69    14      > EXIT                                                     '%0ADone%21%0A'
         15*     > RETURN                                                   1

Class ContentSecurityPolicy:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N8k0m
function name:  __construct
number of ops:  30
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN_OBJ                                               'policy'
          1        OP_DATA                                                  <array>
   21     2        FETCH_OBJ_W                                      $1      'policy'
          3        ASSIGN_DIM                                               $1, 'default-src'
          4        OP_DATA                                                  <array>
   22     5        FETCH_OBJ_W                                      $3      'policy'
          6        ASSIGN_DIM                                               $3, 'script-src'
          7        OP_DATA                                                  <array>
   23     8        FETCH_OBJ_W                                      $5      'policy'
          9        ASSIGN_DIM                                               $5, 'object-src'
         10        OP_DATA                                                  <array>
   24    11        FETCH_OBJ_W                                      $7      'policy'
         12        ASSIGN_DIM                                               $7, 'style-src'
         13        OP_DATA                                                  <array>
   25    14        FETCH_OBJ_W                                      $9      'policy'
         15        ASSIGN_DIM                                               $9, 'img-src'
         16        OP_DATA                                                  <array>
   26    17        FETCH_OBJ_W                                      $11     'policy'
         18        ASSIGN_DIM                                               $11, 'media-src'
         19        OP_DATA                                                  <array>
   27    20        FETCH_OBJ_W                                      $13     'policy'
         21        ASSIGN_DIM                                               $13, 'frame-src'
         22        OP_DATA                                                  <array>
   28    23        FETCH_OBJ_W                                      $15     'policy'
         24        ASSIGN_DIM                                               $15, 'font-src'
         25        OP_DATA                                                  <array>
   29    26        FETCH_OBJ_W                                      $17     'policy'
         27        ASSIGN_DIM                                               $17, 'connect-src'
         28        OP_DATA                                                  <array>
   30    29      > RETURN                                                   null

End of function __construct

Function copy:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 16
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/N8k0m
function name:  copy
number of ops:  21
compiled vars:  !0 = $retval, !1 = $sources, !2 = $directive, !3 = $source
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   NEW                                              $4      'ContentSecurityPolicy'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   34     3        FETCH_OBJ_R                                      ~7      'policy'
          4      > FE_RESET_R                                       $8      ~7, ->18
          5    > > FE_FETCH_R                                       ~9      $8, !1, ->18
          6    >   ASSIGN                                                   !2, ~9
   35     7      > FE_RESET_R                                       $11     !1, ->16
          8    > > FE_FETCH_R                                               $11, !3, ->16
   36     9    >   INIT_FCALL                                               'array_push'
         10        FETCH_OBJ_W                                      $12     !0, 'policy'
         11        FETCH_DIM_W                                      $13     $12, !2
         12        SEND_REF                                                 $13
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                                 
   35    15      > JMP                                                      ->8
         16    >   FE_FREE                                                  $11
   34    17      > JMP                                                      ->5
         18    >   FE_FREE                                                  $8
   40    19      > RETURN                                                   !0
   41    20*     > RETURN                                                   null

End of function copy

Function addsource:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N8k0m
function name:  addSource
number of ops:  17
compiled vars:  !0 = $directive, !1 = $source
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   44     2        FETCH_OBJ_IS                                     ~2      'policy'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      ~2, !0
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->10
   45     6    >   NEW                                              $5      'CSPException'
          7        SEND_VAL_EX                                              'Invalid+directive'
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $5
   47    10    >   FETCH_OBJ_W                                      $7      'policy'
         11        FETCH_DIM_W                                      $8      $7, !0
         12        ASSIGN_DIM                                               $8
         13        OP_DATA                                                  !1
   48    14        FETCH_THIS                                       ~10     
         15      > RETURN                                                   ~10
   49    16*     > RETURN                                                   null

End of function addsource

Function tostring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 21
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 20
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/N8k0m
function name:  toString
number of ops:  28
compiled vars:  !0 = $retval, !1 = $sources, !2 = $directive
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   ASSIGN                                                   !0, <array>
   53     1        FETCH_OBJ_R                                      ~4      'policy'
          2      > FE_RESET_R                                       $5      ~4, ->21
          3    > > FE_FETCH_R                                       ~6      $5, !1, ->21
          4    >   ASSIGN                                                   !2, ~6
   54     5        COUNT                                            ~8      !1
          6        IS_SMALLER                                               0, ~8
          7      > JMPZ                                                     ~9, ->20
   55     8    >   INIT_FCALL                                               'join'
          9        SEND_VAL                                                 '+'
         10        INIT_ARRAY                                       ~11     !2
         11        INIT_FCALL                                               'join'
         12        SEND_VAL                                                 '+'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $12     
         15        ADD_ARRAY_ELEMENT                                ~11     $12
         16        SEND_VAL                                                 ~11
         17        DO_ICALL                                         $13     
         18        ASSIGN_DIM                                               !0
         19        OP_DATA                                                  $13
   53    20    > > JMP                                                      ->3
         21    >   FE_FREE                                                  $5
   58    22        INIT_FCALL                                               'join'
         23        SEND_VAL                                                 '%3B+'
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                         $14     
         26      > RETURN                                                   $14
   59    27*     > RETURN                                                   null

End of function tostring

End of class ContentSecurityPolicy.

Class CSPException: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.79 ms | 1408 KiB | 17 Q