Skip to content

Instantly share code, notes, and snippets.

@RimonEkjon
Forked from JeffreyWay/decorator.php
Created August 26, 2014 07:45
Show Gist options
  • Save RimonEkjon/79c6e1c6bd1bfb2a58cf to your computer and use it in GitHub Desktop.
Save RimonEkjon/79c6e1c6bd1bfb2a58cf 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