<?php
interface IUser
{
function changePassword( $password );
}
class User implements IUser
{
private $password;
public static function find($id)
{
return new User();
}
function changePassword( $password )
{
$this->password = $password;
// Do some database persistant
}
}
class SecurityUser implements IUser
{
private $user;
function __construct(IUser $user)
{
$this->user = $user;
}
function changePassword( $password )
{
$password = password_hash( $password, PASSWORD_DEFAULT );
$this->user->changePassword( $password );
return $password; // This line is not necessary, I added if for the sake of seeing the new hashed password
}
}
$user = new SecurityUser( User::find(1) );
echo $user->changePassword ( 'new secret' );
Last active
August 24, 2017 07:21
-
-
Save nezarfadle/89899c5151c3cae610df064a1ef0b551 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment