Skip to content

Instantly share code, notes, and snippets.

@samadfcibd
Created July 3, 2020 06:44
Show Gist options
  • Save samadfcibd/9189bad5bbadfa7e035b453278144214 to your computer and use it in GitHub Desktop.
Save samadfcibd/9189bad5bbadfa7e035b453278144214 to your computer and use it in GitHub Desktop.
<?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