-
-
Save RimonEkjon/79c6e1c6bd1bfb2a58cf 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 Thing { | |
public function execute(); | |
} | |
class A implements Thing { | |
public function execute() | |
{ | |
var_dump('Core stuff is executing'); | |
} | |
} | |
class B implements Thing { | |
public function __construct(Thing $thing) | |
{ | |
$this->thing = $thing; | |
} | |
public function execute() | |
{ | |
var_dump('class b is doing something'); | |
$this->thing->execute(); | |
} | |
} | |
class C implements Thing { | |
public function __construct(Thing $thing) | |
{ | |
$this->thing = $thing; | |
} | |
public function execute() | |
{ | |
var_dump('class c is doing something'); | |
$this->thing->execute(); | |
} | |
} | |
(new B(new C(new A)))->execute(); | |
/* | |
"class b is doing something" | |
"class c is doing something" | |
"Core stuff is executing" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment