Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64636 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62229 invoked from network); 7 Jan 2013 14:48:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jan 2013 14:48:12 -0000 Authentication-Results: pb1.pair.com header.from=v.veselinov@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=v.veselinov@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.182 as permitted sender) X-PHP-List-Original-Sender: v.veselinov@gmail.com X-Host-Fingerprint: 209.85.216.182 mail-qc0-f182.google.com Received: from [209.85.216.182] ([209.85.216.182:57283] helo=mail-qc0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DB/51-52518-B20EAE05 for ; Mon, 07 Jan 2013 09:48:12 -0500 Received: by mail-qc0-f182.google.com with SMTP id k19so12316859qcs.41 for ; Mon, 07 Jan 2013 06:48:08 -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=esx8hhH/mnq65mL9ErTuuxSiAFUucAAyfMVw5gRmtH8=; b=FvfaJi0RXTmYTOf9wRKtOu91poTPPeoFExCAKl3ofzrNx5y5a1P9ZHoXxPZoj3gpSs vRbY875r5HsXotOUbnz0Baes3Ioea5VCLEBm/SU8Pigma+3lS9mSzeC84PDhs2yxmq7m CC55gaUY0PknqsSDqiG+5pmNGdVeQK0sPtou5ZRyrQDfiLTbjrkFsHeqRG2kPV5W9MnA 3OpfxpQj4b0G+aSGv677Av6k+rpI4CTxE+Q4NF1WnRxkz0YWTt7mcmVuI+mkpQLa525M VOvMQsaBUUX1u3fUTFZYnWKAkTDbMGnvJ17tp96tRGQnnRpWclJdeuVNSEpL3kIa3SoB xuHQ== MIME-Version: 1.0 Received: by 10.49.118.162 with SMTP id kn2mr49764364qeb.65.1357570088892; Mon, 07 Jan 2013 06:48:08 -0800 (PST) Received: by 10.49.103.129 with HTTP; Mon, 7 Jan 2013 06:48:08 -0800 (PST) In-Reply-To: References: Date: Mon, 7 Jan 2013 16:48:08 +0200 Message-ID: To: Anthony Ferrara Cc: Yahav Gindi Bar , PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [RFC] Reflection annotations reader From: v.veselinov@gmail.com (Vladislav Veselinov) This is what I was going for. Your idea looks better. On Mon, Jan 7, 2013 at 4:45 PM, Anthony Ferrara wrote: > 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