3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace App\EventSubscriber; use App\Controller\TokenAuthenticatedController; use App\Repository\UserRepository; use App\Repository\UserTokenRepository; use App\Response\Json\ErrorJsonResponse; use App\Response\Json\SuccessJsonResponse; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\FilterControllerEvent; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\KernelEvents; class TokenSubscriber implements EventSubscriberInterface { private $tokens; /** * @var UserTokenRepository */ private $userTokenRepository; /** * @var UserRepository */ private $userRepository; public function __construct( UserRepository $userRepository, UserTokenRepository $userTokenRepository ) { $this->userRepository = $userRepository; $this->userTokenRepository = $userTokenRepository; } public function onKernelController(FilterControllerEvent $event) { $controller = $event->getController(); // when a controller class defines multiple action methods, the controller // is returned as [$controllerInstance, 'methodName'] if (is_array($controller)) { $controller = $controller[0]; } if (in_array("App\Controller\TokenAuthenticatedController", class_implements($controller))) { $user = $this->userRepository->getAuthUser($this->userTokenRepository); if (!is_object($user)) { return new ErrorJsonResponse("Пожалуйста авторизуйтесь.", [ ], 403); } die("we have token. go next"); } else { var_dump($controller); die; } } public static function getSubscribedEvents() { return [ KernelEvents::CONTROLLER => 'onKernelController', ]; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2b1aS
function name:  (null)
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   DECLARE_CLASS                                            'app%5Ceventsubscriber%5Ctokensubscriber'
   58     1      > RETURN                                                   1

Class App\EventSubscriber\TokenSubscriber:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2b1aS
function name:  __construct
number of ops:  7
compiled vars:  !0 = $userRepository, !1 = $userTokenRepository
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   29     2        ASSIGN_OBJ                                               'userRepository'
          3        OP_DATA                                                  !0
   30     4        ASSIGN_OBJ                                               'userTokenRepository'
          5        OP_DATA                                                  !1
   31     6      > RETURN                                                   null

End of function __construct

Function onkernelcontroller:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 38
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 38
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 10
filename:       /in/2b1aS
function name:  onKernelController
number of ops:  43
compiled vars:  !0 = $event, !1 = $controller, !2 = $user
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   34     1        INIT_METHOD_CALL                                         !0, 'getController'
          2        DO_FCALL                                      0  $3      
          3        ASSIGN                                                   !1, $3
   37     4        INIT_NS_FCALL_BY_NAME                                    'App%5CEventSubscriber%5Cis_array'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $5      
          7      > JMPZ                                                     $5, ->10
   38     8    >   FETCH_DIM_R                                      ~6      !1, 0
          9        ASSIGN                                                   !1, ~6
   40    10    >   INIT_NS_FCALL_BY_NAME                                    'App%5CEventSubscriber%5Cin_array'
         11        SEND_VAL_EX                                              'App%5CController%5CTokenAuthenticatedController'
         12        INIT_NS_FCALL_BY_NAME                                    'App%5CEventSubscriber%5Cclass_implements'
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0  $8      
         15        SEND_VAR_NO_REF_EX                                       $8
         16        DO_FCALL                                      0  $9      
         17      > JMPZ                                                     $9, ->38
   41    18    >   FETCH_OBJ_R                                      ~10     'userRepository'
         19        INIT_METHOD_CALL                                         ~10, 'getAuthUser'
         20        CHECK_FUNC_ARG                                           
         21        FETCH_OBJ_FUNC_ARG                               $11     'userTokenRepository'
         22        SEND_FUNC_ARG                                            $11
         23        DO_FCALL                                      0  $12     
         24        ASSIGN                                                   !2, $12
   42    25        INIT_NS_FCALL_BY_NAME                                    'App%5CEventSubscriber%5Cis_object'
         26        SEND_VAR_EX                                              !2
         27        DO_FCALL                                      0  $14     
         28        BOOL_NOT                                         ~15     $14
         29      > JMPZ                                                     ~15, ->36
   43    30    >   NEW                                              $16     'App%5CResponse%5CJson%5CErrorJsonResponse'
         31        SEND_VAL_EX                                              '%D0%9F%D0%BE%D0%B6%D0%B0%D0%BB%D1%83%D0%B9%D1%81%D1%82%D0%B0+%D0%B0%D0%B2%D1%82%D0%BE%D1%80%D0%B8%D0%B7%D1%83%D0%B9%D1%82%D0%B5%D1%81%D1%8C.'
   44    32        SEND_VAL_EX                                              <array>
         33        SEND_VAL_EX                                              403
   43    34        DO_FCALL                                      0          
   44    35      > RETURN                                                   $16
   46    36    > > EXIT                                                     'we+have+token.+go+next'
   40    37*       JMP                                                      ->42
   48    38    >   INIT_NS_FCALL_BY_NAME                                    'App%5CEventSubscriber%5Cvar_dump'
         39        SEND_VAR_EX                                              !1
         40        DO_FCALL                                      0          
   49    41      > EXIT                                                     
   51    42*     > RETURN                                                   null

End of function onkernelcontroller

Function getsubscribedevents:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2b1aS
function name:  getSubscribedEvents
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_CLASS_CONSTANT                             ~0      'Symfony%5CComponent%5CHttpKernel%5CKernelEvents', 'CONTROLLER'
          1        INIT_ARRAY                                       ~1      'onKernelController', ~0
          2      > RETURN                                                   ~1
   57     3*     > RETURN                                                   null

End of function getsubscribedevents

End of class App\EventSubscriber\TokenSubscriber.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
279.07 ms | 1020 KiB | 18 Q