Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

update annotations reference #2

Closed
wants to merge 2 commits into from

2 participants

Fabio B. Silva Benjamin Eberlei
Fabio B. Silva

No description provided.

en/reference/annotations.rst
@@ -297,7 +297,139 @@ in the AnnotationRegistry. Annotation classes have to contain a class-level docb
/** @Annotation */
class Bar
{
- public $foo;
+ //some code
+ }
+
+Inject annotation values
+------------------------
+
+The annotation parser check if we the annotation constructor has arguments,
Benjamin Eberlei Owner

If we the?

Fabio B. Silva Owner

Sorry, done !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Fabio B. Silva

i'll open one new with constants support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 26, 2011
  1. Fabio B. Silva
Commits on Dec 27, 2011
  1. Fabio B. Silva

    fix typo

    FabioBatSilva authored
This page is out of date. Refresh to see the latest.
Showing with 133 additions and 1 deletion.
  1. +133 −1 en/reference/annotations.rst
134 en/reference/annotations.rst
View
@@ -297,7 +297,139 @@ in the AnnotationRegistry. Annotation classes have to contain a class-level docb
/** @Annotation */
class Bar
{
- public $foo;
+ //some code
+ }
+
+Inject annotation values
+------------------------
+
+The annotation parser check if the annotation constructor has arguments,
+if so then we will pass the value array, otherwise will try to inject values into public properties directly:
+
+
+.. code-block :: php
+
+ <?php
+ namespace MyCompany\Annotations;
+
+ /**
+ * @Annotation
+ *
+ * Some Annotation using a constructor
+ */
+ class Bar
+ {
+ private $foo;
+ public function __construct(array $values)
+ {
+ $this->foo = $values['foo'];
+ }
+ }
+
+ /**
+ * @Annotation
+ *
+ * Some Annotation without a constructor
+ */
+ class Foo
+ {
+ public $bar;
+ }
+
+Annotation Target
+-----------------
+
+``@Target`` indicates the kinds of class element to which an annotation type is applicable.
+Then you could define one or more targets :
+
+- ``CLASS`` Allowed in the class docblock
+- ``PROPERTY`` Allowed in the property docblock
+- ``METHOD`` Allowed in the method docblock
+- ``ALL`` Allowed in the class, property and method docblock
+
+If the annotations is not allowed in the current context you got an ``AnnotationException``
+
+.. code-block :: php
+
+ <?php
+ namespace MyCompany\Annotations;
+
+ /**
+ * @Annotation
+ * @Target({"METHOD","PROPERTY"})
+ */
+ class Bar
+ {
+ //some code
+ }
+
+ /**
+ * @Annotation
+ * @Target("CLASS")
+ */
+ class Foo
+ {
+ //some code
+ }
+
+Attribute types
+---------------
+
+Annotation parser check the given parameters using the phpdoc annotation ``@var``,
+The data type could be validated using the ``@var`` annotation on the annotation properties
+or using the annotations ``@Attributes`` and ``@Attribute``.
+
+If the data type not match you got an ``AnnotationException``
+
+.. code-block :: php
+
+ <?php
+ namespace MyCompany\Annotations;
+
+ /**
+ * @Annotation
+ * @Target({"METHOD","PROPERTY"})
+ */
+ class Bar
+ {
+ /** @var mixed */
+ public $mixed;
+ /** @var boolean */
+ public $boolean;
+ /** @var bool */
+ public $bool;
+ /** @var float */
+ public $float;
+ /** @var string */
+ public $string;
+ /** @var integer */
+ public $integer;
+ /** @var array */
+ public $array;
+ /** @var SomeAnnotationClass */
+ public $annotation;
+ /** @var array<integer> */
+ public $arrayOfIntegers;
+ /** @var array<SomeAnnotationClass> */
+ public $arrayOfAnnotations;
+ }
+
+ /**
+ * @Annotation
+ * @Target({"METHOD","PROPERTY"})
+ * @Attributes({
+ * @Attribute("stringProperty", type = "string"),
+ * @Attribute("annotProperty", type = "SomeAnnotationClass"),
+ * })
+ */
+ class Foo
+ {
+ public function __construct(array $values)
+ {
+ $this->stringProperty = $values['stringProperty'];
+ $this->annotProperty = $values['annotProperty'];
+ }
+ // some code
}
Usage
Something went wrong with that request. Please try again.