Doxygen - PHP properties

We love Doxygen, it undoubtedly produces the best documentation.

However, we are using PHP and the traits are simply ignored / missing in the generated documentation.

Is there a trick missing or just incompatible with traits?

+3


source to share


1 answer


Traits are simply not supported by doxygen.

Since PHP does not support inheriting from multiple classes, traits are a way of extending a class with functions from multiple "classes".

C ++ supports inheritance from multiple classes, so try this filter:

// make traits to classes
$regexp = '#trait([\s]+[\S]+[\s]*){#';
$replace = 'class$1{';
$source = preg_replace($regexp, $replace, $source);

// use traits by extending them (classes that not extending a class)
$regexp = '#class([\s]+[\S]+[\s]*)(implements[\s]+[\S]+[\s]*)?{[\s]+use([^;]+);#';
$replace = 'class$1 extends $3 $2 {';
$source = preg_replace($regexp, $replace, $source);

// use traits by extending them (classes that already extending a class)
$regexp = '#class([\s]+[\S]+[\s]+extends[\s]+[\S]+[\s]*)(implements[\s]+[\S]+[\s]*){[\s]+use([^;]+);#';
$replace = 'class$1, $3 $2{';
$source = preg_replace($regexp, $replace, $source);

      



This filter does:

  • Converts traits to classes

    trait MyTrait{ ... }
    
          

    becomes

    class MyTrait{ ... }
    
          

  • Converting "using" traits to "expanding" traits

    class MyClass{
        use MyTrait1, MyTrait2;
        ...
    }
    
          

    becomes

    class MyClass extends MyTrait, MyTrait2{
        ...
    }
    
          

Doxygen documents this as multiple inheritance. This might work for you.

You can find this and a few more doxygen filters for PHP in my GitHub repository .

+4


source







All Articles