Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64635 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60845 invoked from network); 7 Jan 2013 14:45:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jan 2013 14:45:49 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.45 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.212.45 mail-vb0-f45.google.com Received: from [209.85.212.45] ([209.85.212.45:37781] helo=mail-vb0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BA/01-52518-B9FDAE05 for ; Mon, 07 Jan 2013 09:45:48 -0500 Received: by mail-vb0-f45.google.com with SMTP id p1so19634076vbi.32 for ; Mon, 07 Jan 2013 06:45:45 -0800 (PST) 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:content-type; bh=vPsJZNfJU+Nb0HryOfy6UXya9k2LDWtcVfE9TwuzItg=; b=o0O4S6BhKjz6Bsyk5X6Xrr9uYTWFqxpx+2Exv5+vMZvw6EEdW/Vf4ooRpVUKll+tpb m0Grq6zHeN8iH5JGT+bdoJVFkLnVWgCxzgy/yMYVONtUij23b4iI0hE3SGu4W3KRiwMl 73JkDGeg+uDb6pfi+o8j1UzJBAfRbUbi5WmWVrh3GBkxqDB2St/E4nUyAavD74SqQ/df 2S5GrF1aPSI2VcAZWF2p0CDHB25V+4ex3Ph/bclYzvIbDiNcZdx5xytMwCMDq/4WvfHF FLZB6PTz9zdufQOHbaMndvNawljzynWHTT4we1Rg8RSV7ISltUYvOpUDP5wHU6DIwMT3 tBOw== MIME-Version: 1.0 Received: by 10.52.22.107 with SMTP id c11mr73058349vdf.73.1357569944770; Mon, 07 Jan 2013 06:45:44 -0800 (PST) Received: by 10.58.56.137 with HTTP; Mon, 7 Jan 2013 06:45:44 -0800 (PST) In-Reply-To: References: Date: Mon, 7 Jan 2013 09:45:44 -0500 Message-ID: To: Yahav Gindi Bar Cc: PHP internals Content-Type: multipart/alternative; boundary=20cf307c9eaa50d9a104d2b3e2ce Subject: Re: [PHP-DEV] [RFC] Reflection annotations reader From: ircmaxell@gmail.com (Anthony Ferrara) --20cf307c9eaa50d9a104d2b3e2ce Content-Type: text/plain; charset=ISO-8859-1 Yahav and all, On Sun, Jan 6, 2013 at 4:58 PM, Yahav Gindi Bar wrote: > Hi internals! > > In one of the discussions (about the "deprecated" keyword, to be specific), > it was been said that adding ability to read doc-comment annotation could > be handy. Personally, I really think it can be great. > > So, I've created an RFC that propose to improve the Reflection extension by > adding the ability to read annotations decorated in the doc-comment. > > https://wiki.php.net/rfc/reflection_doccomment_annotations > > What is your opinion about this? > > Regards, > Yahav. > Why does this need to be part of Reflection? Seems a rather odd place for it IMHO, since it basically hard-codes the functionality into part of the core that's not trivially extendable (at least $class->getMethods() is hard to override)... Instead, what about adding a SPL class to parse the comment. Something like class SplAnnotationParser { const PARSE_DEFAULT = 1; const PARSE_FUNCTION = 2; public function __construct($rules = self::PARSE_DEFAULT); /** * @param string $comment The comment to parse * @returns array An array of parsed annotations, pursuant to the ruleset used public function parseAnnotations($comment); } That way, you'd do: $parser = new SplAnnotationParser(SplAnnotationParser::PARE_FUNCTION); foreach ($class->getMethods() as $method) { $annotations = $parser->parseAnnotations($method->getDocComment()); } It decouples the implementation, and allows for people to polymorphically substitute different parsers for different needs. Thoughts? Anthony --20cf307c9eaa50d9a104d2b3e2ce--