schneidoa/php-easy-annotation

Simple PHP Annotation Library

v1.0.1 2016-07-08 22:32 UTC

This package is auto-updated.

Last update: 2024-09-27 07:44:29 UTC


README

Created by Daniel Schneider

Introduction

PHPEasyAnnotation is a simple PHP Annotation Library. It is designed to be very simple and easy to extend.

Requirements

DEV

  • phpunit/phpunit: "5.4.*"

Installation

Main Setup

With composer

  1. Add this project in your composer.json:

    "require": {
        "schneidoa/php-easy-annotation": "dev-master"
    }
    
  2. Now tell composer to download PHPEasyAnnotation:

    $ php composer.phar update

Usage

class Example 
{
    /**
     *
     * @Column(user_id)
     * @Json({"data": 1})
     */
    public $userId;
    
    /**
     *
     * @Column(username)
     * @NotNull()
     * @Json({"data": "dummy"})
     */
     public $username;
 }

Example 1

 
    use Schneidoa\EasyAnnotation\EasyAnnotationClass;
    use Schneidoa\EasyAnnotation\EasyAnnotationProperty;


    $p = new EasyAnnotationClass(get_class($this));
    $p = $p->getAnnotationProperty('userId');
    var_dump( $p->getAnnotations());

PHP Output

array (size=2)
  0 => 
    array (size=3)
      'annotation' => string '@Column(user_id)' (length=16)
      'name' => string 'Column' (length=6)
      'value' => string 'user_id' (length=7)
  1 => 
    array (size=3)
      'annotation' => string '@Json({"data": 1})' (length=18)
      'name' => string 'Json' (length=4)
      'value' => 
        array (size=1)
          'data' => int 1

Example 2

    $p = new EasyAnnotationClass(get_class($this));
    $properties = $p->getAnnotationProperties();
    
    foreach($properties as $property){
        var_dump($property->getAnnotations());
    }

PHP Output

array (size=2)
  0 => 
    array (size=3)
      'annotation' => string '@Column(user_id)' (length=16)
      'name' => string 'Column' (length=6)
      'value' => string 'user_id' (length=7)
  1 => 
    array (size=3)
      'annotation' => string '@Json({"data": 1})' (length=18)
      'name' => string 'Json' (length=4)
      'value' => 
        array (size=1)
          'data' => int 1

array (size=3)
  0 => 
    array (size=3)
      'annotation' => string '@Column(username)' (length=17)
      'name' => string 'Column' (length=6)
      'value' => string 'username' (length=8)
  1 => 
    array (size=3)
      'annotation' => string '@NotNull()' (length=10)
      'name' => string 'NotNull' (length=7)
      'value' => string '' (length=0)
  2 => 
    array (size=3)
      'annotation' => string '@Json({"data": "dummy"})' (length=24)
      'name' => string 'Json' (length=4)
      'value' => 
        array (size=1)
          'data' => string 'dummy' (length=5)