Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108570 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 21094 invoked from network); 14 Feb 2020 13:41:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Feb 2020 13:41:13 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B286A180533 for ; Fri, 14 Feb 2020 03:55:52 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f172.google.com (mail-il1-f172.google.com [209.85.166.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 14 Feb 2020 03:55:52 -0800 (PST) Received: by mail-il1-f172.google.com with SMTP id f5so7850836ilq.5 for ; Fri, 14 Feb 2020 03:55:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=rtz3loXA13Ne0N/GJwkJ2416HJSfGOzXqaDHOQNcQc4=; b=NH9q6lDMEi8lRowtkoVw+xinxQsCFkHwVUNV/Dg/QUhDJ8TWl5JOxe+Ut9fxXgEZBs QsULxdmRkvEazdSGDfBP+Bd9we2XrzFa3Ai5awkri0G0GCFdJ+F5nwkQwvAw2PJFEovi Dqz1h5MnQmQwBTVhDurnbj7Tk6ck3KoQSsUNyZM4DD0IMewiFLGJv4YDwCarHMCSuDje ogVNic9k4y030tvfpSxr9D4ppHIMeXTC6DAH/n5K54jvDDaT63gVv+BD3tUjqLHhSboH /h5uXjSw3oeyVBzK/HljL1uVYIsNZVqGnFOqwx8P9xk2mKvZ7urBt+/wRtj9b+2lsDjl rvcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=rtz3loXA13Ne0N/GJwkJ2416HJSfGOzXqaDHOQNcQc4=; b=IH1OnK9QELbdk36vWodm0h2sNDnGvsuI+v8XJZVWIXQfNQXBjvompF4Nhi3ihYgN6R 1Li0lMw53Fm7pSozfFWwyTRFGoMJgZCQ/PQXm40vxoZtsmkDcM4AXgFhbWN1pUL22rz3 cPjK4XMbC70Q5d6opJmwwNzgBmpSZTyzycnfcCu3uqCuNvxOEBAt3AwYps+Ht0mYkUpu OYiSKjs511VQ5ba9IAbmnwsH5Ea/6uy/xoZdtZu80OlXNjUJuHCAuFdlJgzYRhD9k4Fe kNGk8a+g0+L5VFUlHy/Jg4ry95BB8r4us94GthQQaYhovy6fHG9lv28bDtkIX5fdbUs5 MsNA== X-Gm-Message-State: APjAAAWpoSUVFmPVzeymGWxKPtT1/k+CfPRms5EQjs3cxHloNUUkI5eP DqCUYjjANgj3abky1DGidOIc03irz9VWYwvfHRNaUdHA X-Google-Smtp-Source: APXvYqxycNaCMpC/RBBeoyzQckbtTPRyXv3DW2NSc3PGEuLTZ0hILMYYLfRYxW5KumijvURD0yek0f68Ac6Cf93mqlA= X-Received: by 2002:a92:d702:: with SMTP id m2mr2431058iln.149.1581681351559; Fri, 14 Feb 2020 03:55:51 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 14 Feb 2020 11:55:40 +0000 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="0000000000001b908d059e87e359" Subject: Re: [PHP-DEV] [Pre-RFC] Support for decorator patterns From: rowan.collins@gmail.com (Rowan Tommins) --0000000000001b908d059e87e359 Content-Type: text/plain; charset="UTF-8" On Fri, 14 Feb 2020 at 11:09, Rowan Tommins 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] --0000000000001b908d059e87e359--