PHPackages                             jan-swiecki/simple-annotations - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. jan-swiecki/simple-annotations

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

jan-swiecki/simple-annotations
==============================

Simple annotation parser

0.3.1(10y ago)66615.0k↓35.4%25[3 PRs](https://github.com/jan-swiecki/php-simple-annotations/pulls)18MITPHPPHP &gt;=5.3.0

Since Apr 13Pushed 5y ago4 watchersCompare

[ Source](https://github.com/jan-swiecki/php-simple-annotations)[ Packagist](https://packagist.org/packages/jan-swiecki/simple-annotations)[ Docs](https://github.com/jan-swiecki/php-simple-annotations)[ RSS](/packages/jan-swiecki-simple-annotations/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (12)Used By (18)

PHP Simple Annotations
======================

[](#php-simple-annotations)

Installation
------------

[](#installation)

Get [composer](http://getcomposer.org/) and learn to use it.

Library is on [packagist](https://packagist.org/packages/jan-swiecki/simple-annotations).

If you refuse to use composer then instead of `include_once "vendor/autoload.php"` use `include_once "src/DocBlockReader/Reader.php"`.

Test
----

[](#test)

You need [PHPUnit](https://github.com/sebastianbergmann/phpunit/). After you get it run:

```
> git clone https://github.com/jan-swiecki/php-simple-annotations
> cd php-simple-annotations
> composer install
> phpunit

```

Introduction
------------

[](#introduction)

This library gives you the ability to extract and auto-parse DocBlock comment blocks.

Example:

```
class TestClass {
  /**
   * @x 1
   * @y yes!
   */
  private $myVar;
}

$reader = new \DocBlockReader\Reader('TestClass', 'myVar', 'property');
$x = $reader->getParameter("x"); // 1 (with number type)
$y = $reader->getParameter("y"); // "yes!" (with string type)

```

So as you can see to do this you need to construct `Reader` object and target it at something. Then you extract data.

You can point at classes, class methods and class properties.

- Targeting class: `$reader = new \DocBlockReader\Reader(String $className)`
- Targeting method or property: `$reader = new \DocBlockReader\Reader(String $className, String $name [, String $type = 'method'])`

This will initialize DocBlock Reader on method `$className::$name` or property `$className::$name`.

To choose method use only two arguments or provide third argument as `method` string value. To get property value put `property` string value in third argument.

To extract parsed properties you have two methods:

- `$reader->getParameter(String $key)`

Returns DocBlock value of parameter `$key`. E.g.

```
