Double Include Prevention Code in PHP Prevents Doxygen From Generating Documentation

后端 未结 1 1149
醉酒成梦
醉酒成梦 2021-01-23 10:22

I am writing relatively complex PHP applications and have several files for class definitions formatted as follows:



        
1条回答
  •  南方客
    南方客 (楼主)
    2021-01-23 11:10

    As mentioned by @Sverri in the comments, I also think that autoloading is a good way to solve your problem (what it already did, as it seems).

    But just for the case you (or someone else) is looking for a doxygen-only solution:

    You can use INPUT_FILTERS in doxygen to remove or change some parts of the source code before creating the documentation.

    You can use the following php code to remove all lines containing if(!class_exists and the braces { } that belong to this if-block, as long as it is not followed by another block.

    // input
    $source = file_get_contents($argv[1]);
    
    // removes the whole line
    list($head,$tail) = preg_split('/.*if\(!class_exists\(.+/', $source, 2);   
    
    $openingBracePos = strpos($tail,'{');
    $closingBracePos = strrpos($tail,'}');
    
    if($openingBracePos !== false && $closingBracePos !== false)
        $source = $head . substr($tail,$openingBracePos+1,
                                 $closingBracePos-$openingBracePos-1);
    
    echo $source;
    

    This filter truns

    into

    Note: On windows I have to call the filter like this: C:\xampp\php\php.exe php_var_filter.php

    You can find some more input filters to improve doxygen's php support on GitHub.

    0 讨论(0)
提交回复
热议问题