add package comment to classes?

add package comment to classes?

Postby subaochen on Fri Oct 22, 2004 10:37 pm

I want to generate documentations for plog using phpdocumentor(http://www.phpdoc.org), but all calsses in plog lacks of package tag, so I write an ugly script to add package comment to every class in plog/class directory, hope helpful.

addpackage.php:

Code: Select all
#!/usr/bin/php4

<?php
    // print help screen
    if("help" == trim($argv[1])){
        echo "Usage:","\n";
        echo "php4 addpackage.php","\n";
        echo "\n";
        echo "Notice:","\n";
        echo "1 please run this script in class directory.","\n";
        echo "2 please move class/database/adodb,class/template/smarty,class/logger/log4php,class/mail/phpmailer to a bak directory first.","\n";
        echo "3 run only once.","\n";
        die;
    }

    function addPkgComment($file,$dir){

        // read all lines of the $file into array $lines
        $lines = file($file);

        $head = array_shift($lines);

        $pkgDeclare = array("\n",
                            "    /**\n",
                            "     * @package $dir\n",
                            "     */\n",
                            "\n");

        $result = array_merge($head,$pkgDeclare,$lines);

        $fp = fopen($file,'w');
        while($result){
            $line = array_shift($result);
            fwrite($fp,$line);
        }
        fclose($fp);

    }


    foreach(glob("*") as $dir){
        if(is_dir($dir)) {
            foreach(glob("$dir/*.php") as $file) {
                addPkgComment($file,$dir);
            }
        }
    }

    echo "done.","\n","add package comments successfully!","\n";

?>



please run:

addpackage.php help

to get help:-)

Su baochen
subaochen
 
Posts: 11
Joined: Wed Oct 13, 2004 10:30 pm

Postby phunkphorce on Sun Oct 24, 2004 7:29 am

already added in the current development version, thanks a lot! :)
phunkphorce
Lifetype Expert
 
Posts: 9028
Joined: Mon Aug 25, 2003 6:34 am
Location: Suomessa


Return to Documentation

cron