|
1 | | -# PHP Platform Annotations |
2 | | -This package provides APIs to access annotations in PHP |
3 | | - |
4 | | -[](https://travis-ci.org/PHPPlatform/annotations) |
5 | | - |
6 | | - |
7 | | -## Usage |
8 | | - |
9 | | -``` PHP |
10 | | -PhpPlatform\Annotations\Annotation::getAnnotations($className, $propertyName="*", $constantName="*", $methodName="*"); |
11 | | -``` |
12 | | -where |
13 | | - - `$className` is complete name of the class for which annotations are needed |
14 | | - - `$propertyName` is a *string* of a property or *array* of properties for which annotations are needed |
15 | | - - `$constantName` is a *string* of a constant or *array* of constants for which annotations are needed |
16 | | - - `$methodName` is a *string* of a method name or *array* of method names for which annotations are needed |
17 | | - |
18 | | -## Example |
19 | | - |
20 | | -For example , please see the test case [TestAnnotation][TestAnnotation] |
21 | | - |
22 | | -[TestAnnotation]:https://github.com/PHPPlatform/annotations/blob/master/tests/Annotations/TestAnnotation.php |
| 1 | +# PHP Platform Annotations |
| 2 | +This package provides APIs to access annotations in PHP |
| 3 | + |
| 4 | +[](https://travis-ci.org/PHPPlatform/annotations) |
| 5 | + |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +### Getting the Annotations |
| 10 | +``` PHP |
| 11 | +PhpPlatform\Annotations\Annotation::getAnnotations($className, $propertyName="*", $constantName="*", $methodName="*"); |
| 12 | +``` |
| 13 | +where |
| 14 | + - `$className` is complete name of the class for which annotations are needed |
| 15 | + - `$propertyName` is a *string* of a property or *array* of properties for which annotations are needed |
| 16 | + - `$constantName` is a *string* of a constant or *array* of constants for which annotations are needed |
| 17 | + - `$methodName` is a *string* of a method name or *array* of method names for which annotations are needed |
| 18 | + |
| 19 | +### Declaring Annotations |
| 20 | + |
| 21 | +This library supports annotations in DocComments |
| 22 | +Annotation declaration has the format of |
| 23 | +``` |
| 24 | + * @KEY VALUE(S) |
| 25 | +``` |
| 26 | +Where `KEY` may contain subkeys seperated by `.` |
| 27 | +and `VALUES` are `space` or `comma` seperated strings |
| 28 | + |
| 29 | + |
| 30 | +## Example |
| 31 | +This Example shows the different forms of annotations and their expected values |
| 32 | +```php |
| 33 | +/** |
| 34 | + * @key1 |
| 35 | + * @key2 |
| 36 | + * @key3.subKey1 |
| 37 | + * @key3.subKey2.subkey21 success |
| 38 | + * @key4 v1 |
| 39 | + * @key5 (v2) |
| 40 | + * @key6 v3 v4 |
| 41 | + * @key7 "v5\"With Space and Quotes\"" |
| 42 | + * @key8 ("v6\"With Space and Quotes\"", v7) |
| 43 | + * @key9 ("v8\"With Space and Quotes\"", v9) description1 |
| 44 | + * @key10 ("v10 With \\", v11) description2 |
| 45 | + * @key11 ("123", v12) description3 |
| 46 | + * @key12 ("true", "false") |
| 47 | + * @key13 v13 |
| 48 | + * @key13 1234 |
| 49 | + * @key14 (v14) |
| 50 | + * @key14 v15 |
| 51 | + * @ notKey |
| 52 | + * @wrongKey(v16) desc |
| 53 | + * |
| 54 | + */ |
| 55 | +public $testDifferrentFormatsOfAnnoptations; |
| 56 | +``` |
| 57 | +The array of annotations returned from |
| 58 | +```PHP |
| 59 | +PhpPlatform\Annotations\Annotation::getAnnotations($className, 'testDifferrentFormatsOfAnnoptations'); |
| 60 | +``` |
| 61 | +Will be |
| 62 | +```php |
| 63 | +[ |
| 64 | + "testDifferrentFormatsOfAnnoptations" => [ |
| 65 | + "key1" => true, |
| 66 | + "key2" => true, |
| 67 | + "key3" => [ |
| 68 | + "subKey1" => true, |
| 69 | + "subKey2" => [ |
| 70 | + "subkey21" => "success" |
| 71 | + ] |
| 72 | + ], |
| 73 | + "key4" => "v1", |
| 74 | + "key5" => ["v2"], |
| 75 | + "key6" => ["v3", "v4"], |
| 76 | + "key7" => 'v5"With Space and Quotes"', |
| 77 | + "key8" => ['v6"With Space and Quotes"', "v7"], |
| 78 | + "key9" => ['v8"With Space and Quotes"', "v9"], |
| 79 | + "key10" => ["v10 With \\", "v11"], |
| 80 | + "key11" => [123, "v12"], |
| 81 | + "key12" => [true, false], |
| 82 | + "key13" => ['v13', 1234], |
| 83 | + "key14" => ["v14", "v15"] |
| 84 | + ] |
| 85 | +] |
| 86 | +``` |
0 commit comments