public function testDecorator() { $expect = "<strong>I am component!</strong>"; $decorator = new ConcreteDecorator(new ConcreteComponent()); $result = $decorator->Operation(); $this->assertEquals($result, $expect); }
} class ConcreteComponent extends AbstractComponent { public function operation() { // ... } } abstract class AbstractDecorator extends AbstractComponent { private $_component; public function __construct(AbstractComponent $component) { $this->_component = $component; } public function operation() { $this->_component->operation(); } } class ConcreteDecorator extends AbstractDecorator { public function operation() { // ... расширенная функциональность ... parent::operation(); // ... расширенная функциональность ... } } $decoratedComponent = new ConcreteDecorator(new ConcreteComponent()); $decoratedComponent->operation();