Advertisement
Guest User

Untitled

a guest
Mar 13th, 2012
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. <?php
  2.  
  3. interface IAuthenticationService
  4. {
  5.     function authenticate($username, $password);
  6. }
  7.  
  8. class DbAuthenticationService implements IAuthenticationService
  9. {
  10.     public function authenticate($username, $password)
  11.     {
  12.         // prihlasit
  13.     }
  14. }
  15.  
  16. class LazyAuthenticationService implements IAuthenticationService
  17. {
  18.     private $realAuthService;
  19.     private $container;
  20.    
  21.     public function __construct(IContainer $container)
  22.     {
  23.         $this->container = $container;
  24.     }
  25.    
  26.     public function authenticate($username, $password)
  27.     {
  28.         $this->initRealService();
  29.         return $this->realAuthService();
  30.     }
  31.    
  32.     private function initRealService()
  33.     {
  34.         if (null === $this->realAuthService) {
  35.             $this->$realAuthService = $this->container->getService("authService");
  36.         }
  37.     }
  38. }
  39.  
  40. class AuthPresenter extends BasePresenter
  41. {
  42.     private $authService;
  43.  
  44.     function __construct(IAuthenticationService $authService)
  45.     {
  46.             $this->authService = $authService;
  47.     }
  48.  
  49.     function formSubmitted()
  50.     {
  51.             $this->authService->authenticate();
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement