3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace texdc\cicerone; use InvalidArgumentException; /** * 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 __construct($aValue) { if (!self::validate($aValue)) { throw new InvalidArgumentException("Invalid method [$aValue]"); } $this->value = self::sanitize($aValue); self::$instances[$this->value] = $this; } /** * @param string $aMethod * @param array $arguments * @return self */ public static function __callStatic($aMethod, $arguments = []) { if (!isset(self::$instances[$aMethod])) { $instance = new static($aMethod); $aMethod = $instance->value; } 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::POST());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Eq4dJ
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   DECLARE_CLASS                                            'texdc%5Ccicerone%5Chttpmethod'
  156     1        INIT_NS_FCALL_BY_NAME                                    'texdc%5Ccicerone%5Cvar_dump'
          2        INIT_STATIC_METHOD_CALL                                  'texdc%5Ccicerone%5CHttpMethod', 'POST'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR_NO_REF_EX                                       $0
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Class texdc\cicerone\HttpMethod:
Function __construct:
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/Eq4dJ
function name:  __construct
number of ops:  24
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   52     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
   53     6    >   NEW                                              $3      'InvalidArgumentException'
          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
   55    13    >   INIT_STATIC_METHOD_CALL                                  'sanitize'
         14        SEND_VAR_EX                                              !0
         15        DO_FCALL                                      0  $9      
         16        ASSIGN_OBJ                                               'value'
         17        OP_DATA                                                  $9
   56    18        FETCH_OBJ_R                                      ~11     'value'
         19        FETCH_THIS                                       ~13     
         20        FETCH_STATIC_PROP_W          unknown             $10     'instances'
         21        ASSIGN_DIM                                               $10, ~11
         22        OP_DATA                                                  ~13
   57    23      > RETURN                                                   null

End of function __construct

Function __callstatic:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/Eq4dJ
function name:  __callStatic
number of ops:  16
compiled vars:  !0 = $aMethod, !1 = $arguments, !2 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   66     2        FETCH_STATIC_PROP_IS                             ~3      'instances'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~4      ~3, !0
          4        BOOL_NOT                                         ~5      ~4
          5      > JMPZ                                                     ~5, ->12
   67     6    >   NEW                          static              $6      
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !2, $6
   68    10        FETCH_OBJ_R                                      ~9      !2, 'value'
         11        ASSIGN                                                   !0, ~9
   70    12    >   FETCH_STATIC_PROP_R          unknown             ~11     'instances'
         13        FETCH_DIM_R                                      ~12     ~11, !0
         14      > RETURN                                                   ~12
   71    15*     > 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/Eq4dJ
function name:  sanitize
number of ops:  9
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   RECV                                             !0      
   79     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
   80     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/Eq4dJ
function name:  validate
number of ops:  12
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   RECV                                             !0      
   88     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
   89    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/Eq4dJ
function name:  hasValue
number of ops:  6
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   95     0  E >   RECV                                             !0      
   97     1        FETCH_OBJ_R                                      ~1      'value'
          2        CAST                                          6  ~2      !0
          3        IS_IDENTICAL                                     ~3      ~1, ~2
          4      > RETURN                                                   ~3
   98     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/Eq4dJ
function name:  isAny
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  103     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
  104     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/Eq4dJ
function name:  isGet
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  109     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
  110     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/Eq4dJ
function name:  isHead
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  115     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
  116     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/Eq4dJ
function name:  isPost
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  121     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
  122     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/Eq4dJ
function name:  isPut
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  127     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
  128     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/Eq4dJ
function name:  isDelete
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  133     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
  134     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/Eq4dJ
function name:  isOptions
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  139     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
  140     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/Eq4dJ
function name:  isTrace
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  145     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
  146     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/Eq4dJ
function name:  __toString
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  151     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
  152     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:
183.46 ms | 1404 KiB | 21 Q