Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93083 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 953 invoked from network); 5 May 2016 07:24:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 May 2016 07:24:46 -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.215.47 as permitted sender) X-PHP-List-Original-Sender: lisachenko.it@gmail.com X-Host-Fingerprint: 209.85.215.47 mail-lf0-f47.google.com Received: from [209.85.215.47] ([209.85.215.47:34982] helo=mail-lf0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7D/29-16256-C35FA275 for ; Thu, 05 May 2016 03:24:45 -0400 Received: by mail-lf0-f47.google.com with SMTP id j8so86240484lfd.2 for ; Thu, 05 May 2016 00:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=JZBI+d52oMXq49B5PhcUTpeQ+FvSW55K09Lty9cxxNQ=; b=VdNCtDncYk9gvG/pmVW3gCuVAsN0/52dAY5XzUA3FiGzPnsy08k/AuaSbB6gKwZDPq x/4no+xedBo2YQHWvMSGMmxVLohTmoFckYFBU6mre/8Y0J3zvuzCdBF9010EcOOvMAA4 3DgOeyKo58qCllGBTkalJN6WFsfehbWI20sHD5rWr/hyScZkmIByPFMG93scEtQMhliP 786Sq1I3FyKWLk/Nfhq5QltlCsl/bER41FUzwedHbbGoxKAnHNKRvVT5gJseI7f2+R5k 7JyXw6qjQ3VhTZYqqDr07M+OHQgvABZ+3y9ryByD8xa0IfcQcpMRQoCXq6HIKgrscvBo +FJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=JZBI+d52oMXq49B5PhcUTpeQ+FvSW55K09Lty9cxxNQ=; b=PymnwI82dO995jn3txTzq08nF2IBfN/XFPsREdGxWYCcYJ6Mov93MxTZIN0c9tp2y0 yAlJYWynEXFTWCjvKRmU0qg0qbH2+UOtukxTYgwhELQbzfldrGe5QzIh/gPMIjlr3LcS HtiKQY1gfTH/BjvkllWiCW1kyt0yanTcjjL3qOdHswJNhd23la54YT1+WcgTVObiDlVo E2B08YsIvqkw1XH9qD/Gx5n/274P4Epjl/lwXNRn2bPi2KE5xTYm8C2VYMNY2BQIEK6D dLckJKaBP+Av1MEiKrI9vX66IPk+DBVBKcLaiA6/gYVkYNdFXUaZwQYbfY0tMC4PeNoY H6pw== X-Gm-Message-State: AOPr4FWco3jhZwms6j6NGBzF10uFeNSc63uE3PPTYd3YM8KALLyoGvhYUMyqCQWXnWrqi44acRdznGHUy0i8sQ== MIME-Version: 1.0 X-Received: by 10.25.17.234 with SMTP id 103mr6054548lfr.145.1462433081679; Thu, 05 May 2016 00:24:41 -0700 (PDT) Received: by 10.25.218.65 with HTTP; Thu, 5 May 2016 00:24:41 -0700 (PDT) In-Reply-To: <8a7d1e8a-1e9e-0bbd-912a-21201638b989@gmail.com> References: <5723F2AE.2020806@garfieldtech.com> <8a7d1e8a-1e9e-0bbd-912a-21201638b989@gmail.com> Date: Thu, 5 May 2016 10:24:41 +0300 Message-ID: To: Stanislav Malyshev Cc: Dmitry Stogov , Larry Garfield , PHP internals Content-Type: multipart/alternative; boundary=001a113fb5805764bd0532133c51 Subject: Re: [PHP-DEV] Attributes/Annotations Case Study: Drupal From: lisachenko.it@gmail.com (Alexander Lisachenko) --001a113fb5805764bd0532133c51 Content-Type: text/plain; charset=UTF-8 Hello, internals! 2016-05-05 9:48 GMT+03:00 Stanislav Malyshev : > Maybe that's what we want to have here - freedom for everybody to invent > their own languages - but I fear the danger of fragmentation here and > also people implementing tons of slightly different incompatible parsers > for ASTs that are generated. We'd have Drupal attributes and Symphony > attributes and Doctrine attributes and Zend attributes and so on, and > each of them would have different semantics. Not sure this would be > good. But maybe it avoids arguing about the syntax now. > AST for attributes is a nice thing for abstracting from the concrete details about how attribute is handling by the concrete implementation. I can see a lot of common with class autoloading - earlier there were a lot of custom loaders, thanks to spl_autoload_register() that defines a stack of callbacks responsible for loading classes by their names. And everyone uses custom class loader, but later PSR-0 and PSR-4 were described and adopted in composer, so now we have one general tool for that. What if we select the same direction with the stack of callback? How it should work: PHP engine stores all attributes in the plain AST without any transformations. This data should be accessible via ReflectionXXX->getAttributes(ReflectionAttribute::RETURN_AST). After that userland library can register a hook as attribute loader: e.g ReflectionAttribute::registerProcessor(SomeHandler::class, $isPrepend = true) or spl_attribute_handler_register(SomeProcessor::class, $isPrepend = true) Each processor is a class with two methods: interface AttributeProcessorInterface { public function supports(Php\Ast\Node $attributeNode) : boolean; /** @return mixed */ public function process(Php\Ast\Node $attributeNode); } After that if we call ReflectionXXX->getAttributes(ReflectionAttribute::RETURN_VALUE) PHP engine will call each processor and asks it if it supports this AST node. If processor supports this node, then engine call it's process($attributeNode) method, returning the result as a result, otherwise looks for another processor. If no processors can handle this AST then PHP can throw an exception about with information about missing processors for attributes. I think this way can give a good start point with possibility to standardize handling of attributes in the future. From the PHP engine side, all attributes are AST nodes that can be processed later on the userland side. --001a113fb5805764bd0532133c51--