7

I know that frameworks like Synfony2, Doctrine2, PHPUnit, etc... have support for annonations but I want to add in annotation support for my library but don't want to write the parser/caching myself. Does anyone know if there is a library I can include/hook into my code and be able to start using annonations or at least provide a large set of functionality that does parsing/caching of the annonations for me?

3
  • Reflection? Commented Dec 1, 2011 at 19:34
  • my biggest issue is how to handle cached of the annination Commented Dec 2, 2011 at 0:00
  • You need cache the result? You can use a session or a memory cache, like memcached, maybe store in a file, but for better performance, use memcached. Then you make a md5 of annotation, parse it like a DocComment, store and use. :) Commented Dec 2, 2011 at 2:02

3 Answers 3

4

Reflections are definitely the right path, yet you surely don't want to do all the parsing. Nette Framework has a class you might want to try: https://github.com/nette/nette/blob/master/Nette/Reflection/AnnotationsParser.php

Sign up to request clarification or add additional context in comments.

1 Comment

Actually you can choose between New BDS and GNU GPL, that should not be likely to be an issue.
4

Don't reinvent the wheel. I suggest you to try the doctrine2 parser. It is simple to use and to install.

Comments

3

Take a look: test

Code:

<?php

    /**
     * This is what you want.
     */
    function test() {
    }

    $ref = new ReflectionFunction('test');
    echo $ref->getDocComment();

?>

This works on PHP 5.2+.

1 Comment

This is the core of an annotation framework, but has nothing to do with annotations specifically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.