Last active
October 6, 2017 07:33
-
-
Save tajulasri/e152c61ffd5e02c2857e9c1ccd7f4a85 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 HasherContract | |
{ | |
public function encrypt($string); | |
} | |
class Aes implements HasherContract{ | |
public function encrypt($string) | |
{ | |
return var_dump('encrypting using ' . __CLASS__); | |
} | |
} | |
class Bcrypt implements HasherContract{ | |
public function encrypt($string) | |
{ | |
return var_dump('encrypting using ' . __CLASS__); | |
} | |
} | |
class Md5 implements HasherContract{ | |
public function encrypt($string) | |
{ | |
return var_dump('encrypting using ' . __CLASS__); | |
} | |
} | |
class Argon implements HasherContract | |
{ | |
public function encrypt($string) | |
{ | |
return var_dump('encrypting using ' . __CLASS__); | |
} | |
} | |
// core modules component | |
class Authentication | |
{ | |
protected $hasher; | |
public function __construct(HasherContract $hasher) | |
{ | |
$this->hasher = $hasher; | |
} | |
public function setPassword($password) | |
{ | |
return $this->hasher->encrypt($password); | |
} | |
} | |
// login | |
(new Authentication(new Argon))->setPassword('testing'); |
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 ProviderInterface | |
{ | |
public function shouldHave(); | |
} | |
interface TotalLegInterface | |
{ | |
public function leg(); | |
} | |
abstract class ServiceProvider | |
{ | |
abstract function mustHave(); | |
public function check() | |
{ | |
if((method_exists($this,'canFly'))) { | |
return var_dump($this->canFly()); | |
} | |
} | |
} | |
trait Flyable | |
{ | |
public function canFly() | |
{ | |
return 'i can fly'; | |
} | |
public function increaseSpeed() | |
{ | |
return 'speeding'; | |
} | |
} | |
class Bird extends ServiceProvider implements ProviderInterface,TotalLegInterface | |
{ | |
use Flyable; | |
public function mustHave() | |
{ | |
var_dump('abstract'); | |
} | |
public function shouldHave() | |
{ | |
var_dump('shouldHave interface'); | |
} | |
public function increaseSpeed() | |
{ | |
return 'who cares about slow speed.'; | |
} | |
public function feed() | |
{ | |
return 'sushi'; | |
} | |
public function leg() | |
{ | |
return 2; | |
} | |
} | |
class Chiken extends ServiceProvider implements ProviderInterface,TotalLegInterface | |
{ | |
use Flyable; | |
public function mustHave() | |
{ | |
var_dump('abstract'); | |
} | |
public function shouldHave() | |
{ | |
var_dump('shouldHave interface'); | |
} | |
public function canFly() | |
{ | |
return 'i cant fly right now'; | |
} | |
public function feed() | |
{ | |
return 'stik'; | |
} | |
public function leg() | |
{ | |
return 2; | |
} | |
} | |
class Rimau extends ServiceProvider implements ProviderInterface,TotalLegInterface | |
{ | |
use Flyable; | |
public function mustHave() | |
{ | |
var_dump('abstract'); | |
} | |
public function shouldHave() | |
{ | |
var_dump('shouldHave interface'); | |
} | |
public function canFly() | |
{ | |
return 'i cant fly right now'; | |
} | |
public function feed() | |
{ | |
return 'deer'; | |
} | |
public function leg() | |
{ | |
return 4; | |
} | |
} | |
class FoodSelection | |
{ | |
public function feed(TotalLegInterface $interface) | |
{ | |
return $interface->feed(); | |
} | |
} | |
$animal = new FoodSelection; | |
var_dump($animal->feed(new Chiken)); | |
var_dump($animal->feed(new Bird)); | |
var_dump($animal->feed(new Rimau)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks!