Advertisement
Guest User

DDD user demo

a guest
May 18th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <?php
  2.  
  3. class User {
  4.  
  5.     /** @var string */
  6.     protected $password;
  7.    
  8.     /**
  9.      * @return string
  10.      */
  11.     public function getPassword()
  12.     {
  13.         return $this->password;
  14.     }
  15.    
  16.     /**
  17.      * @param string $password
  18.      */
  19.     public function __construct(string $password)
  20.     {
  21.         $this->password = $password;
  22.     }
  23.    
  24.     /**
  25.      * @param string $password
  26.      *
  27.      * @return User
  28.      */
  29.     public static function create(string $password)
  30.     {
  31.         return new self($password);
  32.     }
  33.    
  34.     /**
  35.      * @param User   $user
  36.      * @param string $password
  37.      */
  38.     public function changePassword(User &$user, string $password)
  39.     {
  40.         $user = self::create($password);
  41.     }
  42. }
  43.  
  44. $user = User::create("pass1");
  45. print_r($user->getPassword());
  46.  
  47. $user->changePassword($user, 'pass2');
  48. print_r($user->getPassword());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement