Ali
Ali

Reputation: 22337

PHP DocComment Annotation Structure and Parsing

I want to use DocComment to define some meta data for properties, class and functions like annotation in more advanced languages.

These data consist of some scalar and array variables like this example:

<?
/** type=set, options=[value1, value2, value3] **/
public $state;
?>

I can't think of any good structure to use here.

I thought of using parse_str after replacing ", " with & but it doesn't work with array part (options in my example).

This is an example of java annotation which includes optional list of key-value pairs. It's a good practice to use java annotation, but how to write an effective parser?

@Author(first = "Oompah", last = "Loompah")

Any good suggestion regarding the structure and parsing method which is fast, easy to implement and human readable would be appreciated.

Upvotes: 1

Views: 414

Answers (1)

lisachenko
lisachenko

Reputation: 6092

Do not try to invent the wheel :) Just integrate Doctrine Annotations library into your project. Doctrine2 and Symfony2 heavily use this library for meta definitions support.

Upvotes: 0

Related Questions