Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97482 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13692 invoked from network); 29 Dec 2016 13:44:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Dec 2016 13:44:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=lisachenko.it@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=lisachenko.it@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.43 as permitted sender) X-PHP-List-Original-Sender: lisachenko.it@gmail.com X-Host-Fingerprint: 209.85.213.43 mail-vk0-f43.google.com Received: from [209.85.213.43] ([209.85.213.43:34486] helo=mail-vk0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 54/B3-04761-63315685 for ; Thu, 29 Dec 2016 08:44:22 -0500 Received: by mail-vk0-f43.google.com with SMTP id x186so231836224vkd.1 for ; Thu, 29 Dec 2016 05:44:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=FHBCOidLk941wPOTkfoVWf5+m8ysV2Lb56WAXtPi/aw=; b=h0n9liQlV4o9iBJBnIsWjo92K73nZAM3WfqGPRmTH7SDC4RPejyrFLjPZvGtELQ16Q /ionLDmgqZy2JZuZAxZ8XbDLJ9JaZXmSypzStfV84/afuq3qOuFGskSrXcCgjR+yyZU7 iw823UWIaLXGJhgf71osc6Y+Zt733fQ6DP2/Edido4ssg5R+o5LI2ksru0OFH0kLuj7O UoFen6F78AGDFkovORpie0EkXyEOJjGVzMq5LSmzJtF+LHNo4P8hKT6xHL/OrJExjvPv 6ItyDGKNOQbaQIWJVn0m1cPjhsw9AuzCxY49NxDWRCedoBcb17vSe2hznrtYD2V9gAf3 r50Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=FHBCOidLk941wPOTkfoVWf5+m8ysV2Lb56WAXtPi/aw=; b=Vr/lxIAZ4KQggnCyBEJbwyPja2njtXO5KnrS+bbqheddfXNjhcFnkfbl0vY3joS/xh 0MGS6qLl3Ign5mUZosmDFP2WGOLDmAGKr1+rM6FI619WrHbo/VnMM8gdEJ17bFCoELUw ZnbJrikzUFUSaMenr3ue1/lQiDUyY0oAmyK+7zJWNQyY8v8waxVpCCGxn68AIvKHUqia rDmeIG2OILIbeRMVUMmHxCvxSaTlwRqjRsR8lf7PzMcouvpYw+4akg9bsPQ0TBo6XS5S BWsiC4kJ8KxfTW9RP6YaMFHOy0OWWXx5j2s6deJLRXXhuV3pvfCDeUC/nrDljikuAyRb U41Q== X-Gm-Message-State: AIkVDXKNG01x93F8q5IFlcuCi94gYlPV4Gk6v79VoHLJQi0ccsBEObDDC9xfE/9jhIwuJqKOb6QYXIbyj2q6Ug== X-Received: by 10.31.158.81 with SMTP id h78mr15189890vke.34.1483019060254; Thu, 29 Dec 2016 05:44:20 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.168.14 with HTTP; Thu, 29 Dec 2016 05:44:19 -0800 (PST) In-Reply-To: <2aecc3f2-5e9d-907f-029b-5c60eb134b33@rochette.cc> References: <2aecc3f2-5e9d-907f-029b-5c60eb134b33@rochette.cc> Date: Thu, 29 Dec 2016 16:44:19 +0300 Message-ID: To: Mathieu Rochette Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11427400481c720544cc4858 Subject: Re: [PHP-DEV] Decorator classes From: lisachenko.it@gmail.com (Alexander Lisachenko) --001a11427400481c720544cc4858 Content-Type: text/plain; charset=UTF-8 2016-12-29 16:12 GMT+03:00 Mathieu Rochette : > I find that using the decorator pattern is very verbose and maybe > something could be done about that, > an article[1] I saw proposed a "decorates" keyword to solves this, here is > how it might look like in PHP: > > * the constructor is optional and default to take the first argument and > put it in $decorated > * if the constructor is provided PHP check that $decorated is set and > implements the decorated interface or class > * all public methods not overridden are automatically proxied to the > decorated object > > There is at least a few different ways to go about this, the previous > example was just to give you a preview of what it could be. If there is > interest I'd like to write an RFC for this :) > > What do you think about this ? > Hi! I think that language doesn't need any additional keywords for that. What you describe is pure class inheritance and it's already available in the language. To be honest I use class inheritance in Go! AOP to define decorators because of some nice features: 1. No overhead for calling non-decorated method (we can wrap only required methods) 2. Only one single instance of class, whereas traditional proxy and decorator pattern will use two instances (one for the original instance itself and one more instance for proxy/decorator) What your want can be implemented with the help of one single aspect, applied to your codebase. Then framework will automatically create decorators for every required class in your system. For logging decorator example see my blogpost here: http://go.aopphp.com/blog/2013/07/21/implementing-logging-aspect-with-doctrine-annotations/ --001a11427400481c720544cc4858--