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 Answers
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
1 Comment
Mikulas Dite
Actually you can choose between New BDS and GNU GPL, that should not be likely to be an issue.
Don't reinvent the wheel. I suggest you to try the doctrine2 parser. It is simple to use and to install.
Comments
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
LadyCailin
This is the core of an annotation framework, but has nothing to do with annotations specifically.
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. :)