Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- interface RoleCommand
- {
- public function getRole();
- }
- class AddRoleCommand implements RoleCommand
- {
- public function getRole()
- {
- return 'ROLE_ADMIN';
- }
- }
- interface UserCommand
- {
- public function getUsername();
- }
- class AddUserCommand implements UserCommand
- {
- private $name;
- public function __construct($name)
- {
- $this->name = $name;
- }
- public function getUsername()
- {
- return $this->name;
- }
- }
- class EditUserCommand implements UserCommand
- {
- private $name;
- public function __construct($name)
- {
- $this->name = $name;
- }
- public function getUsername()
- {
- return $this->name;
- }
- }
- interface UserCommandHandler
- {
- public function handle(UserCommand $command);
- }
- class NewUserCommandHandler implements UserCommandHandler
- {
- public function handle(UserCommand $command)
- {
- $username = $command->getUsername();
- var_dump($username);
- }
- }
- class Testowy implements RoleCommand, UserCommand
- {
- private $name;
- public function __construct($name)
- {
- $this->name = $name;
- }
- public function getUsername()
- {
- return $this->name;
- }
- public function getRole()
- {
- return 'ROLE_ADMIN';
- }
- }
- $userCommand = new AddUserCommand('Damian');
- $roleCommand = new AddRoleCommand();
- $editUserCommand = new EditUserCommand('Rysiek');
- $testowyCommnd = new Testowy("tadzio");
- $handler = new NewUserCommandHandler;
- $handler->handle($roleCommand);
- echo "<br/>";
- $handler->handle($userCommand);
- echo "<br/>";
- $handler->handle($editUserCommand);
- echo "<br/>";
- $handler->handle($testowyCommnd);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement