During project development, I found that my php documents were missing Management. others wrote one and there were not many functions? Php *** class name: doc * Description: document generation class * others: you can filter directories. after setting the source directory, specify the directory to be generated using the absolute path. the mode is adjustable, mode * 1 is a regular type, that is, it starts with a slash ** and ends with a slash * 2 as the extension type. any slash * found in the project development that lacks management of php documents, one written by others, with few functions
/**
* Class name: doc
* Description: document generation class.
* Others: you can filter directories. after setting the source directory, use the absolute path to specify the directory to be generated. the mode is adjustable.
* 1 is a regular type, that is, it starts with a slash ** and ends with a slash.
* 2 is an extension type. all sections starting with a slash * will become part of the document.
*/
Class doc
{
Var $ docdirname;
Var $ docdir;
/**
* Function name: doc ()
* Function: construct
* Input parameter: none
* Function return value: return value description
* Other instructions: 2004-10-13
*/
Function doc ()
{
$ This-> docdirname = "doc /";
}
/**
* Function name: createDoc ($ root, $ newdir, $ mode = "1", $ filter = null)
* Function: create a document
* Input parameter: $ root ------------ source directory
$ Newdir ----------- target Directory
$ Mode ------------- mode, where 1 is normal and 2 is extended
$ Filter ------------ filter directories
* Function return value: return value description
* Other instructions: 2004-10-13
*/
Function createDoc ($ root, $ newdir, $ mode = "1", $ filter = null)
{
$ Getarr = $ this-> loopDir ($ root, $ filter );
$ I = 0;
$ This-> createFrame ($ newdir );
Foreach ($ getarr as $ key => $ val)
{
If ($ this-> getPhpFiles ($ val ))
{
$ Content = $ this-> getContent ($ val );
$ Content = $ this-> getDoc ($ content, $ mode );
$ Filepath = $ this-> setFilepath ($ val, $ root, $ newdir );
$ Filedir = $ this-> getFileDir ($ filepath );
$ This-> mkdirs ($ filedir );
$ This-> setDoc ($ filepath, $ content );
$ Data [$ I] ['URL'] = "$ filepath ";
$ Data [$ I] ['name'] = "$ val ";
$ I ++;
}
}
If (! Empty ($ data ))
{
$ This-> createMenu ($ newdir, $ data );
$ This-> redirect ($ this-> docdir );
}
}
/**
* Function name: redirect ($ path)
* Function: redirection
* Input parameter: $ path -------------- steering path
* Function return value: return value description
* Other instructions: 2004-10-13
*/
Function redirect ($ path)
{
Echo "the document is generated successfully. Click here to view details ";
}
/**
* Function name: loopDir ($ root, $ filter = null)
* Function: traverses directories.
* Input parameter: $ root ----------------- source directory
$ Filter ----------------- filter
* Function return value: array
* Other instructions: 2004-10-13
*/
Function loopDir ($ root, $ filter = null)
{
Static $ getarr = array ();
$ D = dir ($ root );
While (false! ==( $ Entry = $ d-> read ()))
{
If ($ entry = "." | $ entry = "..")
{
Continue;
}
If ($ this-> filter ($ entry, $ filter ))
{
If (is_dir ($ root. $ entry ))
{
$ This-> loopDir ($ d-> path. $ entry ."/");
}
Else
{
$ Getarr [] = $ d-> path. $ entry;
}
}
}
$ D-> close ();
Return $ getarr;
}
/**
* Function name: getPhpFiles ($ path)
* Function: extract the php document
* Input parameter: $ path -------------- document path
* Function return value: bool
* Other instructions: 2004-10-13
*/
Function getPhpFiles ($ path)
{
$ Type = preg_replace ('/. * \. (. * [^ \.]. *)/I', '\ 1', $ path );
$ Type = strtolower ($ type );
If ($ type = "php ")
{
Return true;
}
Else
{
Return false;
}
}
/**
* Function name: getContent ($ path)
* Function: Read file content
* Input parameter: $ path ------------------- file path
* Function return value: string
* Other instructions: 2004-10-13
*/
Function getContent ($ path)
{
$ Fp = file ($ path );
$ Content = implode (', $ fp );
Return $ content;
}
/**
* Function name: getDoc ($ content, $ mode = "1 ")
* Function: extracts comments from the PHP file.
* Input parameter: $ content ------------ document content
$ Mode --------------- mode. the value 1 indicates normal, and the value 2 indicates extension.
* Function return value: string
* Other instructions: 2004-10-13
*/
Function getDoc ($ content, $ mode = "1 ")
{
Switch ($ mode)
{
Case '1 ':
$ Pattern = '// (\ *) [\ r \ n]. * \ // isu ';
Break;
Case '2 ':
$ Pattern = '// \/\ *. * \ // isu ';
Break;
}
Preg_match_all ($ pattern, $ content, $ carr );
$ Getarr = array ();
Foreach ($ carr [0] as $ key => $ val)
{
$ Getarr [] = trim ($ val );
}
$ Str = implode ("
", $ Getarr );
$ Str = preg_replace ('/[\ r]/I ','
', $ Str );
$ Style = $ this-> getStyle ();
$ Str = $ this-> getTable ($ str );
$ Str = $ style. $ str;
Return $ str;
}
/**
* Function name: etFilepath ($ filepath, $ oldroot, $ newroot)
* Function: set the path of the generated file.
* Input parameter: $ filepath ------------ source file path
$ Oldroot -------------- source directory path
$ Newroot ------------ target directory path
* Function return value: string
* Other instructions: 2004-10-13
*/
Function setFilepath ($ filepath, $ oldroot, $ newroot)
{
$ Oldroot = str_replace ('/', "\/", $ oldroot );
$ Pattern = "/". $ oldroot. "(. *)/iU ";
$ Filepath = preg_replace ($ pattern, '\ 1', $ filepath );
$ Newpath = $ newroot. $ this-> docdirname. $ filepath; // echo "$ newpath
";
$ Newpath = preg_replace ('/(. * \.) (. * [^ \.]. *)/I', '\ 1htm', $ newpath );
Return $ newpath;
}
/**
* Function name: getFileDir ($ path)
* Function: obtain the document directory.
* Input parameter: $ path ----------- document path
* Function return value: string
* Other instructions: 2004-10-13
*/
Function getFileDir ($ path)
{
$ Getpath = preg_replace ('/(. *) (\/. * [^ \.]. *)/I', '\ 1', $ path );
Return $ getpath;
}
/**
* Function name: setDoc
* Function: write comments to a specified directory and generate a page.
* Input parameter: $ filepath ------------- directory path
$ Content ---------------- written content
* Function return value: return value description
* Other instructions: Description
*/
Function setDoc ($ filepath, $ content)
{
$ Fp = fopen ($ filepath, "w + ");
Flock ($ fp, LOCK_EX );
Fwrite ($ fp, $ content );
Flock ($ fp, LOCK_UN );
}
/**
* Function name: mkdirs ($ path)
* Function: create a directory
* Input parameter: $ path ----------------- path
* Function return value: none
* Other instructions: 2004-10-13
*/
Function mkdirs ($ path)
{
$ Adir = explode ('/', $ path );
$ Dirlist = ';
$ Rootdir = $ adir [0];
Array_shift ($ adir );
Foreach ($ adir as $ key => $ val)
{
If ($ val! = '.' & $ Val! = '..')
{
$ Dirlist. = "/". $ val;
$ Dirpath = $ rootdir. $ dirlist;
If (! File_exists ($ dirpath )&&! Is_file ($ dirpath ))
{
Mkdir ($ dirpath );
Chmod ($ dirpath, 0777 );
}
}
}
}
/**
* Function name: filter ($ item, $ arr = null)
* Function: filter
* Input parameter: $ item ------------ content
$ Arr ------------- filter item
* Function return value: bool
* Other instructions: 2004-10-13
*/
Function filter ($ item, $ arr = null)
{
$ Item = strtolower ($ item );
$ Filter = explode (',', $ arr );
If ($ arr = null |! In_array ($ item, $ filter ))
{
Return true;
}
Else
{
Return false;
}
}
/**
* Function name: createFrame ($ root)
* Function: generate a framework page
* Input parameter: $ root --------------- storage directory of the home page
* Function return value: str
* Other instructions: 2004-10-13
*/
Function createFrame ($ root)
{
$ Str ='
Untitled Document
<Body> <br> </body>
';
$ This-> docdir = $ root. "index.htm ";
$ This-> setDoc ($ this-> docdir, $ str );
}
/**
* Function name: createMenu ($ root, $ data)
* Function: generate a menu
* Input parameter: $ root ------------------- save the page to the Directory
$ Data ------------------- content
* Function return value: string
* Other instructions: 2004-10-13
*/
Function createMenu ($ root, $ data)
{
$ Path = $ root. "menu.htm ";
$ Str = $ this-> getStyle ();
$ Str. ="
";Foreach ($ data as $ key => $ val){$ Str. ="
". $ Val ['name']." |
";}$ Str. ="
";
$ This-> setDoc ($ path, $ str );
}
/**
* Function name: getStyle ()
* Function: Style
* Input parameter: none
* Function return value: string
* Other instructions: 2004-10-13
*/
Function getStyle ()
{
$ Str ='
';
Return $ str;
}
/**
* Function name: getTable ($ content)
* Function: puts the content in a table.
* Input parameter: $ content ------------ content
* Function return value: string
* Other instructions: 2004-10-13
*/
Function getTable ($ content)
{
$ Str ="
";
Return $ str;
}
}
// Use
$ D = new doc;
$ Filter = "adodb, smarty, cvs, templates, templates_c ";
$ D-> createDoc ("e:/www/kpub20/class/", "e:/www/test/aaa/", 1, $ filter );
?>