GithubHelp home page GithubHelp logo

annotations-1's Introduction

Minime \ Annotations

Build Status Coverage Status Scrutinizer Quality Score Latest Stable Version Total Downloads

Minime\Annotations is a very simple PHP library that lets you create APIs that react to metadata with great flexibility and no headache.

Features & Roadmap

  • [DONE] Class, property and method annotations
  • [DONE] Namespaced annotations
  • [DONE] API to filter and traverse annotations
  • [DONE] Traits (for convenient integration)
  • Parser
    • [DONE] Optional strong typed annotations: float, integer, string, json
    • [DONE] Dynamic annotations (eval type)
    • [DONE] Implicit boolean annotations
    • [DONE] Multiple value annotations
    • [DONE] Inline Docblock support (see #15)
    • [TODO] Multiline annotations value (see #16)
    • [TODO] Parser improvements and optimizations (see #17)

Installation

Manually update composer.json with:

{
  "require": {
    "minime/annotations": "~1.1"
  }
}

Or just use your terminal: composer require minime/annotations:~1.1 🎱

Basic Usage

Using as a trait

The trait approach is useful for self / internal reflection:

/**
 * @get @post @delete
 * @entity bar
 * @has-many Baz
 * @accept json ["json", "xml", "csv"]
 * @max integer 45
 * @delta float .45
 * @cache-duration eval 1000 * 24 * 60 * 60
 */
class FooController
{
    use Minime\Annotations\Traits\Reader;
}

$foo = new Foo();
$annotations = $foo->getClassAnnotations();

$annotations->get('get')      // > bool(true)
$annotations->get('post')     // > bool(true)
$annotations->get('delete')   // > bool(true)

$annotations->get('entity')   // > string(3) "bar"
$annotations->get('has-many') // > string(3) "Baz"

$annotations->get('accept')   // > array(3){ [0] => "json" [1] => "xml" [2] => "csv" }
$annotations->get('max')      // > int(45)
$annotations->get('delta')    // > double(0.45)
$annotations->get('cache-duration')    // > int(86400000)

$annotations->get('undefined')  // > null

Getting annotations from property and methods is easy too:

$foo->getPropertyAnnotations('property_name');
$foo->getMethodAnnotations('method_name');

Using the facade

The facade is useful when you want to inspect classes out of your logic domain:

use Minime\Annotations\Facade;

Facade::getClassAnnotations('Full\Class\Name');
Facade::getPropertyAnnotations('Full\Class\Name', 'property_name');
Facade::getMethodAnnotations('Full\Class\Name', 'method_name');

Grepping and traversing

Let's suppose you want to pick just a group of annotations:

/**
 * @response.xml
 * @response.xls
 * @response.json
 * @response.csv
 * @method.get
 * @method.post
 */
class WebService
{
    use Minime\Annotations\Traits\Reader;
}

$annotations = (new WebService())->getClassAnnotations();

Retrieving all annotations within 'response' namespace

$annotations->useNamespace('response')->export();
// > array(3){
// >    ["xml"]  => (bool) TRUE,
// >    ["xls"]  => (bool) TRUE,
// >    ["json"] => (bool) TRUE,
// >    ["csv"]  => (bool) TRUE
// > }

Chainning with grep to get all annotations beginning with 'x' within 'response' namespace:

$annotations->useNamespace('response')->grep('^x')->export();
// > array(3){
// >    ["xml"]  => (bool) TRUE,
// >    ["xls"]  => (bool) TRUE
// > }

Traversing results

foreach($annotations->useNamespace('method') as $annotation => $value)
{
    // some behavior
}

Want to contribute?

Found a bug? Have an improvement? Take a look at the issues, there is always something to be done. Please, send pull requests to develop branch only.

Steps

  1. Fork minime\annotations
  2. Clone forked repository
  3. Install composer dependencies $ composer install --prefer-dist
  4. Run unit tests $ phpunit
  5. Modify code: correct bug, implement features
  6. Back to step 4

PLEASE, be objective with pull requests. Avoid combos of improvements + doc + solve bugs + features within the same pull request.

Copyright

Copyright (c) 2013 Márcio Almada. Distributed under the terms of an MIT-style license. See LICENSE for details.

Bitdeli Badge

annotations-1's People

Contributors

carloscapela avatar ignace-dev avatar marcioalmada avatar nyamsprod avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.