3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace texdc\cicerone; /** * Provides encapsulation and validation of HTTP method values * * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html */ final class HttpMethod { /**#@+ * method constants * @var string */ const ANY = '*'; const GET = 'GET'; const HEAD = 'HEAD'; const POST = 'POST'; const PUT = 'PUT'; const DELETE = 'DELETE'; const OPTIONS = 'OPTIONS'; const TRACE = 'TRACE'; /**#@- */ /** @var string[] */ private static $allValues = [ self::ANY, self::GET, self::HEAD, self::POST, self::PUT, self::DELETE, self::OPTIONS, self::TRACE, ]; /** @var self[] */ private static $instances = []; /** @var string */ private $value; /** * @param string $aValue * @throws InvalidArgumentException */ private function HttpMethod($aValue) { if (!self::validate($aValue)) { throw new InvalidArgumentException("Invalid method [$aValue]"); } $this->value = self::sanitize($aValue); } /** * @param string $aMethod * @param array $arguments * @return self */ public static function __callStatic($aMethod, $arguments = []) { if (!isset(self::$instances[$aMethod]) && $instance = new static($aMethod)) { self::$instances[$aMethod] = $instance; } var_dump($aMethod, $instance); return self::$instances[$aMethod]; } /** * @param string $aValue * @return string */ private static function sanitize($aValue) { return strtoupper(trim($aValue)); } /** * @param string $aValue * @return bool */ public static function validate($aValue) { return in_array(self::sanitize($aValue), self::$allValues); } /** * @param string $aValue * @return bool */ public function hasValue($aValue) { return $this->value === (string) $aValue; } /** @return bool */ public function isAny() { return $this->hasValue(self::ANY); } /** @return bool */ public function isGet() { return $this->hasValue(self::GET) || $this->isAny(); } /** @return bool */ public function isHead() { return $this->hasValue(self::HEAD) || $this->isAny(); } /** @return bool */ public function isPost() { return $this->hasValue(self::POST) || $this->isAny(); } /** @return bool */ public function isPut() { return $this->hasValue(self::PUT) || $this->isAny(); } /** @return bool */ public function isDelete() { return $this->hasValue(self::DELETE) || $this->isAny(); } /** @return bool */ public function isOptions() { return $this->hasValue(self::OPTIONS) || $this->isAny(); } /** @return bool */ public function isTrace() { return $this->hasValue(self::TRACE) || $this->isAny(); } /** @return string */ public function __toString() { return $this->value; } } var_dump(HttpMethod::PUT());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tdp3i
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                            'texdc%5Ccicerone%5Chttpmethod'
  152     1        INIT_NS_FCALL_BY_NAME                                    'texdc%5Ccicerone%5Cvar_dump'
          2        INIT_STATIC_METHOD_CALL                                  'texdc%5Ccicerone%5CHttpMethod', 'PUT'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR_NO_REF_EX                                       $0
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Class texdc\cicerone\HttpMethod:
Function httpmethod:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tdp3i
function name:  HttpMethod
number of ops:  19
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
   50     1        INIT_STATIC_METHOD_CALL                                  'validate'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4        BOOL_NOT                                         ~2      $1
          5      > JMPZ                                                     ~2, ->13
   51     6    >   NEW                                              $3      'texdc%5Ccicerone%5CInvalidArgumentException'
          7        ROPE_INIT                                     3  ~5      'Invalid+method+%5B'
          8        ROPE_ADD                                      1  ~5      ~5, !0
          9        ROPE_END                                      2  ~4      ~5, '%5D'
         10        SEND_VAL_EX                                              ~4
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $3
   53    13    >   INIT_STATIC_METHOD_CALL                                  'sanitize'
         14        SEND_VAR_EX                                              !0
         15        DO_FCALL                                      0  $9      
         16        ASSIGN_OBJ                                               'value'
         17        OP_DATA                                                  $9
   54    18      > RETURN                                                   null

End of function httpmethod

Function __callstatic:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 11
filename:       /in/Tdp3i
function name:  __callStatic
number of ops:  23
compiled vars:  !0 = $aMethod, !1 = $arguments, !2 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   63     2        FETCH_STATIC_PROP_IS                             ~3      'instances'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~4      ~3, !0
          4        BOOL_NOT                                         ~5      ~4
          5      > JMPZ_EX                                          ~5      ~5, ->11
          6    >   NEW                          static              $6      
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
          9        ASSIGN                                           ~8      !2, $6
         10        BOOL                                             ~5      ~8
         11    > > JMPZ                                                     ~5, ->15
   64    12    >   FETCH_STATIC_PROP_W          unknown             $9      'instances'
         13        ASSIGN_DIM                                               $9, !0
         14        OP_DATA                                                  !2
   65    15    >   INIT_NS_FCALL_BY_NAME                                    'texdc%5Ccicerone%5Cvar_dump'
         16        SEND_VAR_EX                                              !0
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0          
   66    19        FETCH_STATIC_PROP_R          unknown             ~12     'instances'
         20        FETCH_DIM_R                                      ~13     ~12, !0
         21      > RETURN                                                   ~13
   67    22*     > RETURN                                                   null

End of function __callstatic

Function sanitize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tdp3i
function name:  sanitize
number of ops:  9
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   RECV                                             !0      
   75     1        INIT_NS_FCALL_BY_NAME                                    'texdc%5Ccicerone%5Cstrtoupper'
          2        INIT_NS_FCALL_BY_NAME                                    'texdc%5Ccicerone%5Ctrim'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $1      
          5        SEND_VAR_NO_REF_EX                                       $1
          6        DO_FCALL                                      0  $2      
          7      > RETURN                                                   $2
   76     8*     > RETURN                                                   null

End of function sanitize

Function validate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tdp3i
function name:  validate
number of ops:  12
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   RECV                                             !0      
   84     1        INIT_NS_FCALL_BY_NAME                                    'texdc%5Ccicerone%5Cin_array'
          2        INIT_STATIC_METHOD_CALL                                  'sanitize'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $1      
          5        SEND_VAR_NO_REF_EX                                       $1
          6        CHECK_FUNC_ARG                                           
          7        FETCH_STATIC_PROP_FUNC_ARG   unknown             $2      'allValues'
          8        SEND_FUNC_ARG                                            $2
          9        DO_FCALL                                      0  $3      
         10      > RETURN                                                   $3
   85    11*     > RETURN                                                   null

End of function validate

Function hasvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tdp3i
function name:  hasValue
number of ops:  6
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   RECV                                             !0      
   93     1        FETCH_OBJ_R                                      ~1      'value'
          2        CAST                                          6  ~2      !0
          3        IS_IDENTICAL                                     ~3      ~1, ~2
          4      > RETURN                                                   ~3
   94     5*     > RETURN                                                   null

End of function hasvalue

Function isany:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tdp3i
function name:  isAny
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   99     0  E >   INIT_METHOD_CALL                                         'hasValue'
          1        FETCH_CLASS_CONSTANT                             ~0      'ANY'
          2        SEND_VAL_EX                                              ~0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
  100     5*     > RETURN                                                   null

End of function isany

Function isget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/Tdp3i
function name:  isGet
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  105     0  E >   INIT_METHOD_CALL                                         'hasValue'
          1        FETCH_CLASS_CONSTANT                             ~0      'GET'
          2        SEND_VAL_EX                                              ~0
          3        DO_FCALL                                      0  $1      
          4      > JMPNZ_EX                                         ~2      $1, ->8
          5    >   INIT_METHOD_CALL                                         'isAny'
          6        DO_FCALL                                      0  $3      
          7        BOOL                                             ~2      $3
          8    > > RETURN                                                   ~2
  106     9*     > RETURN                                                   null

End of function isget

Function ishead:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/Tdp3i
function name:  isHead
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  111     0  E >   INIT_METHOD_CALL                                         'hasValue'
          1        FETCH_CLASS_CONSTANT                             ~0      'HEAD'
          2        SEND_VAL_EX                                              ~0
          3        DO_FCALL                                      0  $1      
          4      > JMPNZ_EX                                         ~2      $1, ->8
          5    >   INIT_METHOD_CALL                                         'isAny'
          6        DO_FCALL                                      0  $3      
          7        BOOL                                             ~2      $3
          8    > > RETURN                                                   ~2
  112     9*     > RETURN                                                   null

End of function ishead

Function ispost:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/Tdp3i
function name:  isPost
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  117     0  E >   INIT_METHOD_CALL                                         'hasValue'
          1        FETCH_CLASS_CONSTANT                             ~0      'POST'
          2        SEND_VAL_EX                                              ~0
          3        DO_FCALL                                      0  $1      
          4      > JMPNZ_EX                                         ~2      $1, ->8
          5    >   INIT_METHOD_CALL                                         'isAny'
          6        DO_FCALL                                      0  $3      
          7        BOOL                                             ~2      $3
          8    > > RETURN                                                   ~2
  118     9*     > RETURN                                                   null

End of function ispost

Function isput:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/Tdp3i
function name:  isPut
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  123     0  E >   INIT_METHOD_CALL                                         'hasValue'
          1        FETCH_CLASS_CONSTANT                             ~0      'PUT'
          2        SEND_VAL_EX                                              ~0
          3        DO_FCALL                                      0  $1      
          4      > JMPNZ_EX                                         ~2      $1, ->8
          5    >   INIT_METHOD_CALL                                         'isAny'
          6        DO_FCALL                                      0  $3      
          7        BOOL                                             ~2      $3
          8    > > RETURN                                                   ~2
  124     9*     > RETURN                                                   null

End of function isput

Function isdelete:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/Tdp3i
function name:  isDelete
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  129     0  E >   INIT_METHOD_CALL                                         'hasValue'
          1        FETCH_CLASS_CONSTANT                             ~0      'DELETE'
          2        SEND_VAL_EX                                              ~0
          3        DO_FCALL                                      0  $1      
          4      > JMPNZ_EX                                         ~2      $1, ->8
          5    >   INIT_METHOD_CALL                                         'isAny'
          6        DO_FCALL                                      0  $3      
          7        BOOL                                             ~2      $3
          8    > > RETURN                                                   ~2
  130     9*     > RETURN                                                   null

End of function isdelete

Function isoptions:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/Tdp3i
function name:  isOptions
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  135     0  E >   INIT_METHOD_CALL                                         'hasValue'
          1        FETCH_CLASS_CONSTANT                             ~0      'OPTIONS'
          2        SEND_VAL_EX                                              ~0
          3        DO_FCALL                                      0  $1      
          4      > JMPNZ_EX                                         ~2      $1, ->8
          5    >   INIT_METHOD_CALL                                         'isAny'
          6        DO_FCALL                                      0  $3      
          7        BOOL                                             ~2      $3
          8    > > RETURN                                                   ~2
  136     9*     > RETURN                                                   null

End of function isoptions

Function istrace:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/Tdp3i
function name:  isTrace
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  141     0  E >   INIT_METHOD_CALL                                         'hasValue'
          1        FETCH_CLASS_CONSTANT                             ~0      'TRACE'
          2        SEND_VAL_EX                                              ~0
          3        DO_FCALL                                      0  $1      
          4      > JMPNZ_EX                                         ~2      $1, ->8
          5    >   INIT_METHOD_CALL                                         'isAny'
          6        DO_FCALL                                      0  $3      
          7        BOOL                                             ~2      $3
          8    > > RETURN                                                   ~2
  142     9*     > RETURN                                                   null

End of function istrace

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tdp3i
function name:  __toString
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  147     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
  148     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function __tostring

End of class texdc\cicerone\HttpMethod.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.72 ms | 1412 KiB | 21 Q