Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64618 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82497 invoked from network); 7 Jan 2013 00:19:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jan 2013 00:19:37 -0000 Authentication-Results: pb1.pair.com header.from=g.b.yahav@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=g.b.yahav@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.178 as permitted sender) X-PHP-List-Original-Sender: g.b.yahav@gmail.com X-Host-Fingerprint: 209.85.214.178 mail-ob0-f178.google.com Received: from [209.85.214.178] ([209.85.214.178:45347] helo=mail-ob0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/F0-12349-5941AE05 for ; Sun, 06 Jan 2013 19:19:34 -0500 Received: by mail-ob0-f178.google.com with SMTP id eh20so16869622obb.9 for ; Sun, 06 Jan 2013 16:19:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=ZhbTfjMkAd2xZQYvwfb1wmz1wmcFFmp2PDXTiNLpFFo=; b=UpRcw5ADXWeBP9NfzAgR3Ha6WWtFr+AxivnpTvx5HNrzCwh5Np7sfdcx7+02TV7iz8 Dr5B3jO0q5HKTvJuCB7Hu5j6Jku1rbARxbxdk/PVIsY05Sv7dczCLuLQxJtCDlBJ4fcZ NZ9B7x9WwfG7bwetaC+6YUB7+0Hnfs183wSgYfAD0eZpfv6Any8qE+JU/5sXH0zZAKhD mSjkjnCdZj6Sgjb6K2HXnwZ1CObiFCNcME9ycqbNbEy9dIPH4s0WbJF79Xpjl/M5czhI Iw/b7TaGt781WdK+byT5W6yozt9nWiAd0UHYHKXtYSNcS1whTg/C9Buz7qvzqcuFXNQf 4LYw== Received: by 10.60.32.200 with SMTP id l8mr34313048oei.43.1357517971079; Sun, 06 Jan 2013 16:19:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.76.151.4 with HTTP; Sun, 6 Jan 2013 16:19:10 -0800 (PST) In-Reply-To: References: <45FD2112-5469-48A2-8941-92415EC711E1@strojny.net> Date: Mon, 7 Jan 2013 02:19:10 +0200 Message-ID: To: Sebastian Krebs Cc: PHP internals list Content-Type: multipart/alternative; boundary=e89a8fb1f5b071429904d2a7c810 Subject: Re: [PHP-DEV] [RFC] Reflection annotations reader From: g.b.yahav@gmail.com (Yahav Gindi Bar) --e89a8fb1f5b071429904d2a7c810 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jan 7, 2013 at 1:11 AM, Sebastian Krebs wrote: > 2013/1/6 Yahav Gindi Bar > > > On Mon, Jan 7, 2013 at 12:41 AM, Marco Pivetta > wrote: > > > > > > > > I think that our work is to isolate each annotation so it'll be easy to > > >> access, then, it'll be easy enough to write the code that creates > > "complex > > >> annotations", such as constructors and so on, in userland. > > >> > > > > > > In fact, there's probably no need (now) to go on and build a full > > > annotation reader that instantiates classes and does fancy stuff as we > > > currently do in doctrine/common. > > > A fast parser is more than enough I suppose. That's our bottleneck > > > (besides scanning files). > > > > > > > > > Marco Pivetta > > > > > > http://twitter.com/Ocramius > > > > > > http://ocramius.github.com/ > > > > > > > So the problem is the syntax which is difference? > > When wrote this RFC, I just though about basic cases... > > > > Though I agree with you that the main problem is the syntax. > > We can extract the entire doc-comment and only isolate between > annotations, > > so doc-comment like: > > /** > > * @Route("/") > > * @ORM(Key="foo") > > * @var string > > */ > > > > Will be : array( 'Route("/")' => "", 'ORM(Key="foo")' => "", "var" => > > "string" ) > > But the question is it really worth it, since you'll probably need to > > create some sort of "sub-parser" that uses this isolated annotations > array > > and apply on them your syntax. > > > > As a suggestion, that should cover most (all?) cases: The identifier could > be defined as "between @ and the first non-alphanumeric character" (it > should probably allow some special like "/", or "\" to allow namespace-like > annotations). @Route("/") would be array( 'Route' => '("/")'. Now a > secondary parser only needs to take care about ("/"), but for example it > can already directly test, whether or not the annotation exists. > > I've thought about two types of solutions: - The first one is to add another argument that supplies additional characters for the annotation key, so for example getAnnotation("name", "\\/!") Wil match any alphanumericlal values and \, / and !. From the moment it'll catch another tag - it'll be the value. So @var String @param2/param2("bar") Will be array('var' => 'String', 'param2/param2' => '("bar")' ); - The second option, is to built some pre-defined parsing ways, so for example we can define REFLECTION_PARSE_DEFAULT which will parse the annotations just with alphanumerical characters. REFLECTION_PARSE_FUNCTION which will make the parsing of the parameters in the brackets so @ORM(Key="foo") Will be parsed to array( 'ORM' => array( 'key' => "foo" )) and @MaxLength(255) will be parsed to array ('MaxLength' => 255). What do you think? > > > > > > That's being said, if we'll see performance improvements, I really think > > that it's a good solution to start with, since because its not an > > Attributes, I don't think that we should dictate the syntax for each > > application. Each application will get the doc-comment annotation and > will > > be able to apply on it its own syntax and fancy stuff... I think that > it's > > the best solution because of BC too. > > > > To throw that in: Multiline-annotations must be taken into account too :) > > Sure! :) To tell the truth, I've implemented this parsing, too, in userland for documenting application API's, and including it in PHP can make API (web-services) documentations really easy! > > Regards, > Sebastian > > > > > > What do you think? > > > > > > -- > github.com/KingCrunch > --e89a8fb1f5b071429904d2a7c810--