rfc:annotations-in-docblock
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:annotations-in-docblock [2011/05/11 18:05] – created guilhermeblanco | rfc:annotations-in-docblock [2014/04/08 22:49] – Inactive levim | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Request for Comments: | + | ====== Request for Comments: |
* Version: 1.0 | * Version: 1.0 | ||
* Date: 2011-05-11 | * Date: 2011-05-11 | ||
* Author: Guilherme Blanco < | * Author: Guilherme Blanco < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 42: | Line 42: | ||
[[http:// | [[http:// | ||
- | ===== Proposal | + | ===== Tokens choice |
- | First thing to be decided would be the tokens to be used for categorize an Annotation. | + | First thing to be decided |
* Java uses [[http:// | * Java uses [[http:// | ||
Line 50: | Line 50: | ||
When using meta mapping, less characters is preferred to speed up its construction. | When using meta mapping, less characters is preferred to speed up its construction. | ||
+ | Since it's a de-facto standard on docblocks to use @, we'll stick to this one for compatibility. | ||
+ | |||
+ | ===== How to define annotations ===== | ||
+ | |||
+ | **This section still needs expand on subject, since it's just an idea** | ||
+ | |||
+ | <code php> | ||
+ | /** | ||
+ | * Foo class. | ||
+ | * | ||
+ | * @Entity {" | ||
+ | * @Table | ||
+ | * | ||
+ | * @author " | ||
+ | */ | ||
+ | class Foo | ||
+ | { | ||
+ | // ... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The basic idea is to define an entry name " | ||
+ | That way, we could abstract the ReflectionAnnotation class as a generic implementation: | ||
+ | |||
+ | <code php> | ||
+ | class ReflectionAnnotation | ||
+ | { | ||
+ | private $value; | ||
+ | | ||
+ | public function __construct(\stdClass $value) | ||
+ | { | ||
+ | $this-> | ||
+ | } | ||
+ | | ||
+ | public function getValue() | ||
+ | { | ||
+ | return $this-> | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | And have a public Reflection API: | ||
+ | |||
+ | <code php> | ||
+ | class ReflectionFunction { | ||
+ | // ... | ||
+ | |||
+ | public function getAnnotations(); | ||
+ | public function getAnnotation($name); | ||
+ | public function hasAnnotation($name); | ||
+ | } | ||
+ | |||
+ | class ReflectionClass { | ||
+ | // ... | ||
+ | |||
+ | public function getAnnotations(); | ||
+ | public function getAnnotation($name); | ||
+ | public function hasAnnotation($name); | ||
+ | } | ||
+ | |||
+ | class ReflectionProperty { | ||
+ | // ... | ||
+ | |||
+ | public function getAnnotations(); | ||
+ | public function getAnnotation($name); | ||
+ | public function hasAnnotation($name); | ||
+ | } | ||
+ | |||
+ | class ReflectionMethod { | ||
+ | // ... | ||
+ | |||
+ | public function getAnnotations(); | ||
+ | public function getAnnotation($name); | ||
+ | public function hasAnnotation($name); | ||
+ | } | ||
+ | |||
+ | class ReflectionParameter { | ||
+ | // ... | ||
+ | |||
+ | public function getAnnotations(); | ||
+ | public function getAnnotation($name); | ||
+ | public function hasAnnotation($name); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Please notice that ReflectionParameter would now accept docblock to support Annotations. This is something that still needs to be discussed. | ||
+ | |||
+ | ===== Consuming ===== | ||
+ | |||
+ | <code php> | ||
+ | $reflClass = new \ReflectionClass(' | ||
+ | var_dump($reflClass-> | ||
+ | |||
+ | /* | ||
+ | array(3) { | ||
+ | [" | ||
+ | object(ReflectionAnnotation)# | ||
+ | [" | ||
+ | object(stdClass)# | ||
+ | [" | ||
+ | string(13) " | ||
+ | } | ||
+ | } | ||
+ | [" | ||
+ | object(ReflectionAnnotation)# | ||
+ | [" | ||
+ | object(stdClass)# | ||
+ | [" | ||
+ | string(4) " | ||
+ | } | ||
+ | } | ||
+ | [" | ||
+ | object(ReflectionAnnotation)# | ||
+ | [" | ||
+ | string(16) " | ||
+ | } | ||
+ | } | ||
+ | */ | ||
+ | </ | ||
===== Patch ===== | ===== Patch ===== |
rfc/annotations-in-docblock.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1