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 */ public function HttpMethod($aValue) { if (!self::validate($aValue)) { throw new InvalidArgumentException("Invalid method [$aValue]"); } $this->value = self::sanitize($aValue); //static::$instances[$this->value] = $this; var_dump($this); } /** * @param string $aMethod * @param array $arguments * @return self */ public static function __callStatic($aMethod, $arguments = []) { if (!isset(static::$instances[$aMethod])) { $instance = new static($aMethod); $aMethod = $instance->value; } return static::$instances[$aMethod]; } /** * @param string $aValue * @return string */ public static function sanitize($aValue) { return trim(strtoupper($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; } } $put = new HttpMethod(HttpMethod::PUT);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EhIUt
function name:  (null)
number of ops:  7
compiled vars:  !0 = $put
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   DECLARE_CLASS                                            'texdc%5Ccicerone%5Chttpmethod'
  157     1        NEW                                              $1      'texdc%5Ccicerone%5CHttpMethod'
          2        FETCH_CLASS_CONSTANT                             ~2      'texdc%5Ccicerone%5CHttpMethod', 'PUT'
          3        SEND_VAL_EX                                              ~2
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
          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/EhIUt
function name:  HttpMethod
number of ops:  23
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
   57    18        INIT_NS_FCALL_BY_NAME                                    'texdc%5Ccicerone%5Cvar_dump'
         19        FETCH_THIS                                       $10     
         20        SEND_VAR_EX                                              $10
         21        DO_FCALL                                      0          
   58    22      > RETURN                                                   null

End of function httpmethod

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/EhIUt
function name:  __callStatic
number of ops:  16
compiled vars:  !0 = $aMethod, !1 = $arguments, !2 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   67     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
   68     6    >   NEW                          static              $6      
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !2, $6
   69    10        FETCH_OBJ_R                                      ~9      !2, 'value'
         11        ASSIGN                                                   !0, ~9
   71    12    >   FETCH_STATIC_PROP_R          unknown             ~11     'instances'
         13        FETCH_DIM_R                                      ~12     ~11, !0
         14      > RETURN                                                   ~12
   72    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/EhIUt
function name:  sanitize
number of ops:  9
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
   80     1        INIT_NS_FCALL_BY_NAME                                    'texdc%5Ccicerone%5Ctrim'
          2        INIT_NS_FCALL_BY_NAME                                    'texdc%5Ccicerone%5Cstrtoupper'
          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
   81     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/EhIUt
function name:  validate
number of ops:  12
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   RECV                                             !0      
   89     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
   90    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/EhIUt
function name:  hasValue
number of ops:  6
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   96     0  E >   RECV                                             !0      
   98     1        FETCH_OBJ_R                                      ~1      'value'
          2        CAST                                          6  ~2      !0
          3        IS_IDENTICAL                                     ~3      ~1, ~2
          4      > RETURN                                                   ~3
   99     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/EhIUt
function name:  isAny
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  104     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
  105     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/EhIUt
function name:  isGet
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  110     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
  111     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/EhIUt
function name:  isHead
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  116     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
  117     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/EhIUt
function name:  isPost
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  122     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
  123     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/EhIUt
function name:  isPut
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  128     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
  129     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/EhIUt
function name:  isDelete
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  134     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
  135     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/EhIUt
function name:  isOptions
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  140     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
  141     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/EhIUt
function name:  isTrace
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  146     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
  147     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/EhIUt
function name:  __toString
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  152     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
  153     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:
170.25 ms | 1412 KiB | 21 Q