Skip to content

Instantly share code, notes, and snippets.

@WordpressDev
Forked from JeffreyWay/decorator.php
Created July 17, 2014 07:38
Show Gist options
  • Save WordpressDev/47aff5e62a921c5459a9 to your computer and use it in GitHub Desktop.
Save WordpressDev/47aff5e62a921c5459a9 to your computer and use it in GitHub Desktop.
<?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