Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.80 KB | None | 0 0
  1. <?php
  2.  
  3. interface RoleCommand
  4. {
  5.  
  6.     public function getRole();
  7. }
  8.  
  9. class AddRoleCommand implements RoleCommand
  10. {
  11.     public function getRole()
  12.     {
  13.         return 'ROLE_ADMIN';
  14.     }
  15. }
  16.  
  17.  
  18. interface UserCommand
  19. {
  20.  
  21.     public function getUsername();
  22. }
  23.  
  24.  
  25. class AddUserCommand implements UserCommand
  26. {
  27.     private $name;
  28.    
  29.     public function __construct($name)
  30.     {
  31.         $this->name = $name;
  32.        
  33.     }
  34.    public function getUsername()
  35.    {
  36.      return $this->name;  
  37.    }
  38. }
  39.  
  40. class EditUserCommand implements UserCommand
  41. {
  42.     private $name;
  43.    
  44.     public function __construct($name)
  45.     {
  46.         $this->name = $name;
  47.        
  48.     }
  49.    public function getUsername()
  50.    {
  51.      return $this->name;  
  52.    }
  53. }
  54.  
  55.  
  56. interface UserCommandHandler
  57. {
  58.     public function handle(UserCommand $command);
  59. }
  60.  
  61.  
  62.  
  63. class NewUserCommandHandler implements UserCommandHandler
  64. {
  65.    
  66.    public function handle(UserCommand $command)  
  67.    {
  68.        $username = $command->getUsername();
  69.        
  70.        var_dump($username);
  71.    }
  72. }
  73.  
  74.  
  75. class Testowy implements RoleCommand, UserCommand
  76. {
  77.     private $name;
  78.    
  79.     public function __construct($name)
  80.     {
  81.         $this->name = $name;
  82.        
  83.     }
  84.    public function getUsername()
  85.    {
  86.      return $this->name;  
  87.    }
  88.    
  89.    
  90.     public function getRole()
  91.     {
  92.         return 'ROLE_ADMIN';
  93.     }
  94. }
  95.  
  96.  
  97. $userCommand = new AddUserCommand('Damian');
  98. $roleCommand = new AddRoleCommand();
  99. $editUserCommand = new EditUserCommand('Rysiek');
  100.  
  101. $testowyCommnd = new Testowy("tadzio");
  102.  
  103. $handler = new NewUserCommandHandler;
  104.  
  105. $handler->handle($roleCommand);
  106. echo "<br/>";
  107. $handler->handle($userCommand);
  108. echo "<br/>";
  109. $handler->handle($editUserCommand);
  110. echo "<br/>";
  111. $handler->handle($testowyCommnd);
  112. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement