3v4l.org

run code in 300+ PHP versions simultaneously
<?php //implementácia rozhrania Mediator //metoda odoslat() je volaná zamestnancom a slúži k odoslaniu správ interface Mediator { public function send($message, AbstractEmployee $employee); } //definovanie rozhrania abstraktnej triedy AbstractEmployee //trieda obsahuje jedinečný atribút - identifikátor ID, metódu pre čítanie a zápis atribútu //metóda send($message) volá metódu send() sprostredkovateľa na odosielanie správ //metóda receive($message) prijíma správy a je definovaná pre každého potomka triedy //AbstractEmployee abstract class AbstractEmployee { protected $ID; protected $mediator; public function __construct ($ID, Mediator $mediator) { $this -> SetID($ID); $this -> SetMediator($mediator); } public function SetID($ID) { $this -> ID = $ID; } public function GetID() { return $this -> ID; } public function SetMediator(Mediator $mediator) { $this -> mediator = $mediator; } public function GetMediator() { return $this -> mediator ; } public function send($message) { $this -> mediator -> send($message, $this); } public abstract function receive($message); } //trieda Mediator – zabezpečuje registráciu zamestnancov, odosielanie a prijímanie správ class NewMediator implements Mediator { protected $employee = array(); public function registerEmployee (AbstractEmployee $employee) { $this -> employees[] = $employee; } public function send($message, AbstractEmployee $sender) { foreach ($this -> employees as $employee) { if($employee !== $sender) { $employee ->receive($message); } } } } //potomok triedy AbstractEmployee – trieda Employee //metódou receive($message) sa volá sprostredkovateľ, ktorému sa odovzdá posielaná správa class Employee extends AbstractEmployee { public function receive($message) { printf("Prijatie správy: \n", $this -> GetID, $message); } } //testovací script $mediator = new NewMediator(); $employee1 = new Employee('Zamestnanec 1', $mediator); $employee2 = new Employee('Zamestnanec 2', $mediator); $employee3 = new Employee('Zamestnanec 3', $mediator); $employee3 = new Employee('Zamestnanec 4', $mediator); $mediator -> registerEmployee($employee1); $mediator -> registerEmployee($employee2); $mediator -> registerEmployee($employee3); $mediator -> registerEmployee($employee4); $employee3 -> send('Správa zaslaná od ZAM3'); $employee1 -> send('Správa prijatá od ZAM1'); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  (null)
number of ops:  43
compiled vars:  !0 = $mediator, !1 = $employee1, !2 = $employee2, !3 = $employee3, !4 = $employee4
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   DECLARE_CLASS                                            'newmediator'
   89     1        NEW                                              $5      'NewMediator'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $5
   90     4        NEW                                              $8      'Employee'
          5        SEND_VAL_EX                                              'Zamestnanec+1'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $8
   91     9        NEW                                              $11     'Employee'
         10        SEND_VAL_EX                                              'Zamestnanec+2'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !2, $11
   92    14        NEW                                              $14     'Employee'
         15        SEND_VAL_EX                                              'Zamestnanec+3'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !3, $14
   93    19        NEW                                              $17     'Employee'
         20        SEND_VAL_EX                                              'Zamestnanec+4'
         21        SEND_VAR_EX                                              !0
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !3, $17
   94    24        INIT_METHOD_CALL                                         !0, 'registerEmployee'
         25        SEND_VAR_EX                                              !1
         26        DO_FCALL                                      0          
   95    27        INIT_METHOD_CALL                                         !0, 'registerEmployee'
         28        SEND_VAR_EX                                              !2
         29        DO_FCALL                                      0          
   96    30        INIT_METHOD_CALL                                         !0, 'registerEmployee'
         31        SEND_VAR_EX                                              !3
         32        DO_FCALL                                      0          
   97    33        INIT_METHOD_CALL                                         !0, 'registerEmployee'
         34        SEND_VAR_EX                                              !4
         35        DO_FCALL                                      0          
   99    36        INIT_METHOD_CALL                                         !3, 'send'
         37        SEND_VAL_EX                                              'Spr%C3%A1va+zaslan%C3%A1+od+ZAM3'
         38        DO_FCALL                                      0          
  100    39        INIT_METHOD_CALL                                         !1, 'send'
         40        SEND_VAL_EX                                              'Spr%C3%A1va+prijat%C3%A1+od+ZAM1'
         41        DO_FCALL                                      0          
  102    42      > RETURN                                                   1

Class Mediator:
Function send:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  send
number of ops:  3
compiled vars:  !0 = $message, !1 = $employee
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2      > RETURN                                                   null

End of function send

End of class Mediator.

Class AbstractEmployee:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  __construct
number of ops:  9
compiled vars:  !0 = $ID, !1 = $mediator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        INIT_METHOD_CALL                                         'SetID'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   23     5        INIT_METHOD_CALL                                         'SetMediator'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
   24     8      > RETURN                                                   null

End of function __construct

Function setid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  SetID
number of ops:  4
compiled vars:  !0 = $ID
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        ASSIGN_OBJ                                               'ID'
          2        OP_DATA                                                  !0
   29     3      > RETURN                                                   null

End of function setid

Function getid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  GetID
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   FETCH_OBJ_R                                      ~0      'ID'
          1      > RETURN                                                   ~0
   34     2*     > RETURN                                                   null

End of function getid

Function setmediator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  SetMediator
number of ops:  4
compiled vars:  !0 = $mediator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        ASSIGN_OBJ                                               'mediator'
          2        OP_DATA                                                  !0
   39     3      > RETURN                                                   null

End of function setmediator

Function getmediator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  GetMediator
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   FETCH_OBJ_R                                      ~0      'mediator'
          1      > RETURN                                                   ~0
   44     2*     > RETURN                                                   null

End of function getmediator

Function send:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  send
number of ops:  8
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        FETCH_OBJ_R                                      ~1      'mediator'
          2        INIT_METHOD_CALL                                         ~1, 'send'
          3        SEND_VAR_EX                                              !0
          4        FETCH_THIS                                       $2      
          5        SEND_VAR_EX                                              $2
          6        DO_FCALL                                      0          
   49     7      > RETURN                                                   null

End of function send

Function receive:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  receive
number of ops:  2
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function receive

End of class AbstractEmployee.

Class NewMediator:
Function registeremployee:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  registerEmployee
number of ops:  5
compiled vars:  !0 = $employee
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
   62     1        FETCH_OBJ_W                                      $1      'employees'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   63     4      > RETURN                                                   null

End of function registeremployee

Function send:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/RCrOb
function name:  send
number of ops:  13
compiled vars:  !0 = $message, !1 = $sender, !2 = $employee
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   67     2        FETCH_OBJ_R                                      ~3      'employees'
          3      > FE_RESET_R                                       $4      ~3, ->11
          4    > > FE_FETCH_R                                               $4, !2, ->11
   69     5    >   IS_NOT_IDENTICAL                                         !2, !1
          6      > JMPZ                                                     ~5, ->10
   71     7    >   INIT_METHOD_CALL                                         !2, 'receive'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
   67    10    > > JMP                                                      ->4
         11    >   FE_FREE                                                  $4
   74    12      > RETURN                                                   null

End of function send

End of class NewMediator.

Class Employee:
Function receive:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  receive
number of ops:  8
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   RECV                                             !0      
   84     1        INIT_FCALL                                               'printf'
          2        SEND_VAL                                                 'Prijatie+spr%C3%A1vy%3A+%0A'
          3        FETCH_OBJ_R                                      ~1      'GetID'
          4        SEND_VAL                                                 ~1
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
   85     7      > RETURN                                                   null

End of function receive

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  __construct
number of ops:  9
compiled vars:  !0 = $ID, !1 = $mediator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        INIT_METHOD_CALL                                         'SetID'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   23     5        INIT_METHOD_CALL                                         'SetMediator'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
   24     8      > RETURN                                                   null

End of function __construct

Function setid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  SetID
number of ops:  4
compiled vars:  !0 = $ID
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        ASSIGN_OBJ                                               'ID'
          2        OP_DATA                                                  !0
   29     3      > RETURN                                                   null

End of function setid

Function getid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  GetID
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   FETCH_OBJ_R                                      ~0      'ID'
          1      > RETURN                                                   ~0
   34     2*     > RETURN                                                   null

End of function getid

Function setmediator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  SetMediator
number of ops:  4
compiled vars:  !0 = $mediator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        ASSIGN_OBJ                                               'mediator'
          2        OP_DATA                                                  !0
   39     3      > RETURN                                                   null

End of function setmediator

Function getmediator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  GetMediator
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   FETCH_OBJ_R                                      ~0      'mediator'
          1      > RETURN                                                   ~0
   44     2*     > RETURN                                                   null

End of function getmediator

Function send:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCrOb
function name:  send
number of ops:  8
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        FETCH_OBJ_R                                      ~1      'mediator'
          2        INIT_METHOD_CALL                                         ~1, 'send'
          3        SEND_VAR_EX                                              !0
          4        FETCH_THIS                                       $2      
          5        SEND_VAR_EX                                              $2
          6        DO_FCALL                                      0          
   49     7      > RETURN                                                   null

End of function send

End of class Employee.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.8 ms | 1412 KiB | 15 Q