On Fri, 14 Feb 2020 at 11:09, Rowan Tommins <rowan.coll...@gmail.com> wrote:
> > That would also cover the fluent interface case: > > after delegate setFoo { > $this->delegated = $return; > return $this; > } > I just realised that this could be easily extended to share an implementation across multiple methods, making a really succinct decorator definition: class FluentThingDecorator implements FluentThing { private int $setterCount=0; private int $getterCount =0; private delegate FluentThing $delegated; public function __construct(FluentThing $delegate) { $this->delegated = $delegate; } public function getSetterCount() { return $this->setterCount; } public function getGetterCount() { return $this->getterCount; } after delegate getFoo, getBar, getBaz { $this->getterCount++; return $return; } after delegate setFoo, setBar, setBaz { $this->setterCount++; $this->delegated = $return; return $this; } } It might be useful to have access to the name of the function actually called, e.g. for an audit log decorator; maybe the de-sugaring could happen early enough that __METHOD__ took on the right value for each case. Regards, -- Rowan Tommins [IMSoP]