3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); // ─── Identity Package ───────────────────────────────────────────────────────── interface ContextResolver { public function resolve(): Context; } interface Context { } final readonly class IdentityContext implements Context { public function __construct( public readonly UserId $userId, public readonly TeamId $teamId, ) { } } final readonly class IdentityContextResolver implements ContextResolver { public function __construct( private Request $request, private JwtParser $jwt, ) { } public function resolve(): IdentityContext { $payload = $this->jwt->parse($this->request->bearerToken()); return new IdentityContext( userId: new UserId($payload->sub), teamId: new TeamId($payload->teamId), ); } } // ─── Payment Package ────────────────────────────────────────────────────────── final readonly class StripeActor { public function __construct( public readonly string $stripeEventId, public readonly string $stripeAccountId, ) { } } final readonly class PaymentContext implements Context { public function __construct( public readonly IdentityContext $identity, // composed public readonly StripeActor $actor, // composed ) { } } final readonly class PaymentContextResolver implements ContextResolver { public function __construct( private ContextResolver $inner, private Request $request, private StripeSignatureVerifier $verifier, ) { } public function resolve(): PaymentContext { $this->verifier->verify($this->request); $event = json_decode($this->request->getContent()); return new PaymentContext( identity: $this->inner->resolve(), actor: new StripeActor( stripeEventId: $event->id, stripeAccountId: $event->account, ), ); } } // ─── VoiceLead Package ──────────────────────────────────────────────────────── final readonly class VapiActor { public function __construct( public readonly string $botUuid, public readonly string $botId, ) { } } final readonly class VoiceLeadContext implements Context { public function __construct( public readonly IdentityContext $identity, // composed public readonly VapiActor $actor, // composed ) { } } final readonly class VoiceLeadContextResolver implements ContextResolver { public function __construct( private ContextResolver $inner, private Request $request, private HmacVerifier $verifier, private BotRepository $bots, ) { } public function resolve(): VoiceLeadContext { $this->verifier->verify($this->request); $botUuid = $this->request->input('botUuid'); $bot = $this->bots->findByUuid($botUuid); return new VoiceLeadContext( identity: $this->inner->resolve(), actor: new VapiActor( botUuid: $botUuid, botId: $bot->getId(), ), ); } } // ─── Controllers ────────────────────────────────────────────────────────────── final readonly class PaymentWebhookController { public function __construct( private PaymentContextResolver $resolver, ) { } public function __invoke(): void { $context = $this->resolver->resolve(); $context->identity->teamId; // from composed IdentityContext $context->actor->stripeEventId; // from composed StripeActor } } final readonly class VapiWebhookController { public function __construct( private VoiceLeadContextResolver $resolver, ) { } public function __invoke(): void { $context = $this->resolver->resolve(); $context->identity->teamId; // from composed IdentityContext $context->actor->botId; // from composed VapiActor } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   DECLARE_CLASS                                            'identitycontext'
   26     1        DECLARE_CLASS                                            'identitycontextresolver'
   58     2        DECLARE_CLASS                                            'paymentcontext'
   68     3        DECLARE_CLASS                                            'paymentcontextresolver'
  106     4        DECLARE_CLASS                                            'voiceleadcontext'
  116     5        DECLARE_CLASS                                            'voiceleadcontextresolver'
  178     6      > RETURN                                                   1

Class ContextResolver:
Function resolve:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  resolve
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   VERIFY_RETURN_TYPE                                       
          1      > RETURN                                                   null

End of function resolve

End of class ContextResolver.

Class Context: [no user functions]
Class IdentityContext:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __construct
number of ops:  7
compiled vars:  !0 = $userId, !1 = $teamId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ASSIGN_OBJ                                               'userId'
          3        OP_DATA                                                  !0
          4        ASSIGN_OBJ                                               'teamId'
          5        OP_DATA                                                  !1
   23     6      > RETURN                                                   null

End of function __construct

End of class IdentityContext.

Class IdentityContextResolver:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __construct
number of ops:  7
compiled vars:  !0 = $request, !1 = $jwt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ASSIGN_OBJ                                               'request'
          3        OP_DATA                                                  !0
          4        ASSIGN_OBJ                                               'jwt'
          5        OP_DATA                                                  !1
   33     6      > RETURN                                                   null

End of function __construct

Function resolve:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  resolve
number of ops:  27
compiled vars:  !0 = $payload
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   FETCH_OBJ_R                                      ~1      'jwt'
          1        INIT_METHOD_CALL                                         ~1, 'parse'
          2        FETCH_OBJ_R                                      ~2      'request'
          3        INIT_METHOD_CALL                                         ~2, 'bearerToken'
          4        DO_FCALL                                      0  $3      
          5        SEND_VAR_NO_REF_EX                                       $3
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !0, $4
   39     8        NEW                                              $6      'IdentityContext'
   40     9        NEW                                              $7      'UserId'
         10        CHECK_FUNC_ARG                                           
         11        FETCH_OBJ_FUNC_ARG                               $8      !0, 'sub'
         12        SEND_FUNC_ARG                                            $8
         13        DO_FCALL                                      0          
         14        SEND_VAR_NO_REF_EX                                       $7, 'userId'
   41    15        NEW                                              $10     'TeamId'
         16        CHECK_FUNC_ARG                                           
         17        FETCH_OBJ_FUNC_ARG                               $11     !0, 'teamId'
         18        SEND_FUNC_ARG                                            $11
         19        DO_FCALL                                      0          
         20        SEND_VAR_NO_REF_EX                                       $10, 'teamId'
         21        CHECK_UNDEF_ARGS                                         
   39    22        DO_FCALL                                      1          
   41    23        VERIFY_RETURN_TYPE                                       $6
         24      > RETURN                                                   $6
   43    25*       VERIFY_RETURN_TYPE                                       
         26*     > RETURN                                                   null

End of function resolve

End of class IdentityContextResolver.

Class StripeActor:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __construct
number of ops:  7
compiled vars:  !0 = $stripeEventId, !1 = $stripeAccountId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ASSIGN_OBJ                                               'stripeEventId'
          3        OP_DATA                                                  !0
          4        ASSIGN_OBJ                                               'stripeAccountId'
          5        OP_DATA                                                  !1
   55     6      > RETURN                                                   null

End of function __construct

End of class StripeActor.

Class PaymentContext:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __construct
number of ops:  7
compiled vars:  !0 = $identity, !1 = $actor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ASSIGN_OBJ                                               'identity'
          3        OP_DATA                                                  !0
          4        ASSIGN_OBJ                                               'actor'
          5        OP_DATA                                                  !1
   65     6      > RETURN                                                   null

End of function __construct

End of class PaymentContext.

Class PaymentContextResolver:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __construct
number of ops:  10
compiled vars:  !0 = $inner, !1 = $request, !2 = $verifier
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        ASSIGN_OBJ                                               'inner'
          4        OP_DATA                                                  !0
          5        ASSIGN_OBJ                                               'request'
          6        OP_DATA                                                  !1
          7        ASSIGN_OBJ                                               'verifier'
          8        OP_DATA                                                  !2
   76     9      > RETURN                                                   null

End of function __construct

Function resolve:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  resolve
number of ops:  34
compiled vars:  !0 = $event
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   FETCH_OBJ_R                                      ~1      'verifier'
          1        INIT_METHOD_CALL                                         ~1, 'verify'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $2      'request'
          4        SEND_FUNC_ARG                                            $2
          5        DO_FCALL                                      0          
   82     6        INIT_FCALL                                               'json_decode'
          7        FETCH_OBJ_R                                      ~4      'request'
          8        INIT_METHOD_CALL                                         ~4, 'getContent'
          9        DO_FCALL                                      0  $5      
         10        SEND_VAR                                                 $5
         11        DO_ICALL                                         $6      
         12        ASSIGN                                                   !0, $6
   84    13        NEW                                              $8      'PaymentContext'
   85    14        FETCH_OBJ_R                                      ~9      'inner'
         15        INIT_METHOD_CALL                                         ~9, 'resolve'
         16        DO_FCALL                                      0  $10     
         17        SEND_VAR_NO_REF_EX                                       $10, 'identity'
   86    18        NEW                                              $11     'StripeActor'
         19        CHECK_FUNC_ARG                                           'stripeEventId'
   87    20        FETCH_OBJ_FUNC_ARG                               $12     !0, 'id'
         21        SEND_FUNC_ARG                                            $12, 'stripeEventId'
         22        CHECK_FUNC_ARG                                           'stripeAccountId'
   88    23        FETCH_OBJ_FUNC_ARG                               $13     !0, 'account'
         24        SEND_FUNC_ARG                                            $13, 'stripeAccountId'
         25        CHECK_UNDEF_ARGS                                         
   86    26        DO_FCALL                                      1          
   88    27        SEND_VAR_NO_REF_EX                                       $11, 'actor'
         28        CHECK_UNDEF_ARGS                                         
   84    29        DO_FCALL                                      1          
   88    30        VERIFY_RETURN_TYPE                                       $8
         31      > RETURN                                                   $8
   91    32*       VERIFY_RETURN_TYPE                                       
         33*     > RETURN                                                   null

End of function resolve

End of class PaymentContextResolver.

Class VapiActor:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __construct
number of ops:  7
compiled vars:  !0 = $botUuid, !1 = $botId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   98     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ASSIGN_OBJ                                               'botUuid'
          3        OP_DATA                                                  !0
          4        ASSIGN_OBJ                                               'botId'
          5        OP_DATA                                                  !1
  103     6      > RETURN                                                   null

End of function __construct

End of class VapiActor.

Class VoiceLeadContext:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __construct
number of ops:  7
compiled vars:  !0 = $identity, !1 = $actor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  108     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ASSIGN_OBJ                                               'identity'
          3        OP_DATA                                                  !0
          4        ASSIGN_OBJ                                               'actor'
          5        OP_DATA                                                  !1
  113     6      > RETURN                                                   null

End of function __construct

End of class VoiceLeadContext.

Class VoiceLeadContextResolver:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __construct
number of ops:  13
compiled vars:  !0 = $inner, !1 = $request, !2 = $verifier, !3 = $bots
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  118     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        ASSIGN_OBJ                                               'inner'
          5        OP_DATA                                                  !0
          6        ASSIGN_OBJ                                               'request'
          7        OP_DATA                                                  !1
          8        ASSIGN_OBJ                                               'verifier'
          9        OP_DATA                                                  !2
         10        ASSIGN_OBJ                                               'bots'
         11        OP_DATA                                                  !3
  125    12      > RETURN                                                   null

End of function __construct

Function resolve:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  resolve
number of ops:  35
compiled vars:  !0 = $botUuid, !1 = $bot
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  129     0  E >   FETCH_OBJ_R                                      ~2      'verifier'
          1        INIT_METHOD_CALL                                         ~2, 'verify'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $3      'request'
          4        SEND_FUNC_ARG                                            $3
          5        DO_FCALL                                      0          
  131     6        FETCH_OBJ_R                                      ~5      'request'
          7        INIT_METHOD_CALL                                         ~5, 'input'
          8        SEND_VAL_EX                                              'botUuid'
          9        DO_FCALL                                      0  $6      
         10        ASSIGN                                                   !0, $6
  132    11        FETCH_OBJ_R                                      ~8      'bots'
         12        INIT_METHOD_CALL                                         ~8, 'findByUuid'
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0  $9      
         15        ASSIGN                                                   !1, $9
  134    16        NEW                                              $11     'VoiceLeadContext'
  135    17        FETCH_OBJ_R                                      ~12     'inner'
         18        INIT_METHOD_CALL                                         ~12, 'resolve'
         19        DO_FCALL                                      0  $13     
         20        SEND_VAR_NO_REF_EX                                       $13, 'identity'
  136    21        NEW                                              $14     'VapiActor'
  137    22        SEND_VAR_EX                                              !0, 'botUuid'
  138    23        INIT_METHOD_CALL                                         !1, 'getId'
         24        DO_FCALL                                      0  $15     
         25        SEND_VAR_NO_REF_EX                                       $15, 'botId'
         26        CHECK_UNDEF_ARGS                                         
  136    27        DO_FCALL                                      1          
  138    28        SEND_VAR_NO_REF_EX                                       $14, 'actor'
         29        CHECK_UNDEF_ARGS                                         
  134    30        DO_FCALL                                      1          
  138    31        VERIFY_RETURN_TYPE                                       $11
         32      > RETURN                                                   $11
  141    33*       VERIFY_RETURN_TYPE                                       
         34*     > RETURN                                                   null

End of function resolve

End of class VoiceLeadContextResolver.

Class PaymentWebhookController:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __construct
number of ops:  4
compiled vars:  !0 = $resolver
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  148     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'resolver'
          2        OP_DATA                                                  !0
  152     3      > RETURN                                                   null

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __invoke
number of ops:  11
compiled vars:  !0 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  156     0  E >   FETCH_OBJ_R                                      ~1      'resolver'
          1        INIT_METHOD_CALL                                         ~1, 'resolve'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !0, $2
  158     4        FETCH_OBJ_R                                      ~4      !0, 'identity'
          5        FETCH_OBJ_R                                      ~5      ~4, 'teamId'
          6        FREE                                                     ~5
  159     7        FETCH_OBJ_R                                      ~6      !0, 'actor'
          8        FETCH_OBJ_R                                      ~7      ~6, 'stripeEventId'
          9        FREE                                                     ~7
  160    10      > RETURN                                                   null

End of function __invoke

End of class PaymentWebhookController.

Class VapiWebhookController:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __construct
number of ops:  4
compiled vars:  !0 = $resolver
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  165     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'resolver'
          2        OP_DATA                                                  !0
  169     3      > RETURN                                                   null

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K3AJZ
function name:  __invoke
number of ops:  11
compiled vars:  !0 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  173     0  E >   FETCH_OBJ_R                                      ~1      'resolver'
          1        INIT_METHOD_CALL                                         ~1, 'resolve'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !0, $2
  175     4        FETCH_OBJ_R                                      ~4      !0, 'identity'
          5        FETCH_OBJ_R                                      ~5      ~4, 'teamId'
          6        FREE                                                     ~5
  176     7        FETCH_OBJ_R                                      ~6      !0, 'actor'
          8        FETCH_OBJ_R                                      ~7      ~6, 'botId'
          9        FREE                                                     ~7
  177    10      > RETURN                                                   null

End of function __invoke

End of class VapiWebhookController.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.42 ms | 1036 KiB | 14 Q