Skip to content

Instantly share code, notes, and snippets.

@tajulasri
Last active October 6, 2017 07:33
Show Gist options
  • Save tajulasri/e152c61ffd5e02c2857e9c1ccd7f4a85 to your computer and use it in GitHub Desktop.
Save tajulasri/e152c61ffd5e02c2857e9c1ccd7f4a85 to your computer and use it in GitHub Desktop.
<?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');
<?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));
@syahmiibrahim
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment