Php annotation

I know that frameworks like Synfony2, Doctrine2, PHPUnit, etc., support annotations, but I want to add annotation support for my library, but I don't want to write parser / cache itself. Does anyone know if there is a library that I can include / connect to my code, and can start using annotations, or at least provide a large set of functions that perform annotation parsing / caching for me?

+6
source share
3 answers

Reflections are definitely the right way, but you certainly don't want to do all the parsing. The Nette Framework has a class that you can try: https://github.com/nette/nette/blob/master/Nette/Reflection/AnnotationsParser.php

+4
source

Do not reinvent the wheel. I suggest you try the doctrine2 parser. It is easy to use and install.

+4
source

Take a look: test

The code

<?php /** * This is what you want. */ function test() { } $ref = new ReflectionFunction('test'); echo $ref->getDocComment(); ?> 

This works on PHP 5.2+.

+3
source

Source: https://habr.com/ru/post/902861/


All Articles