Created
July 3, 2020 06:44
-
-
Save samadfcibd/9189bad5bbadfa7e035b453278144214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface AuthenticationService | |
{ | |
public function authenticate($email); | |
} | |
class GoogleAuthenticationService implements AuthenticationService | |
{ | |
public function authenticate($email) | |
{ | |
return 'true'; | |
} | |
} | |
class GithubAuthenticationService implements AuthenticationService | |
{ | |
public function authenticate($email) | |
{ | |
return 'true'; | |
} | |
} | |
class userLogin | |
{ | |
public function login($email, AuthenticationService $authenticationService) | |
{ | |
// DIP | |
// Dependency inverted on abstraction | |
$auth_result = $authenticationService->authenticate($email); | |
if ($auth_result) { | |
return true; | |
} | |
} | |
} | |
$login = new userLogin(); | |
$login->login('samadocpl@gmail.com', new GithubAuthenticationService()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment