This article provides a detailed analysis of how to use PhpDocumentor to generate a document. For more information, see
Command line method:
Enter phpdoc-h in the directory where phpDocumentor is located to obtain a detailed parameter table. several important parameters are as follows:
-F name of the file to be analyzed. multiple files are separated by commas.
-D directory to be analyzed. multiple directories are separated by commas.
-T: storage path of the generated document
-O output file format. The structure is output format: converter name: Template directory.
Example: phpdoc-o HTML: frames: earthli-f test. php-t docs
Web interface generation
In the new phpdoc, in addition to generating documents under the command line, you can also generate documents on the client browser, the specific method is to put the content of PhpDocumentor under the apache Directory so that it can be accessed through a browser. the following interface is displayed after access:
Click the files button and select the php file or folder to be processed. you can also specify Files to ignore on this interface to ignore the processing of some files.
Click the output button to select the path and format of the generated document.
Finally, click create. the phpdocumentor automatically starts generating the document. the progress and status of the generated document are displayed at the bottom.
Total Documentation Time: 1 seconds
Done
Operation Completed !!
Then, we can use the generated document. if it is in the simplified format, it is named documentation.pdf.
Add Standard comments to php code
PHPDocument is to generate a document from the comments of your source code. Therefore, the process of commenting your program is the process of compiling the document.
From this point on, PHPdoc prompts you to develop good programming habits, try to use specifications, clear text for your program to make comments, at the same time, it also avoids the problem of non-sync preparation of documents and updates later.
In phpdocumentor, annotations are classified into document comments and non-document comments.
Document comments are multi-line comments placed before specific keywords. specific keywords refer to keywords that can be analyzed by phpdoc, such as class and var. for details, refer to Appendix 1.
Comments that are not preceded by keywords or are not standardized are called non-document comments. these comments will not be analyzed by phpdoc or appear in your generated api text.
How to write document comments:
All document comments are a multi-line comments starting with/**. in phpDocumentor, DocBlock refers to the help information written by software developers about a keyword, this allows others to know the specific purpose of this keyword and how to use it. PhpDocumentor specifies that a DocBlock contains the following information:
1. function overview area
2. Detailed description area
3. tag
The first line of document comments is the function description area. The body is generally a concise description of the functions of this class, method, or function, the body of the function description is displayed in the index area in the generated document. The content in the function description area can end with a blank line or.
There is a blank line behind the function description area, followed by a detailed description area. this section mainly describes the functions and usage of your API. if possible, it can also be used as an example. In this section, you should focus on the common usage and usage of your API functions or methods, and specify whether it is cross-platform (if involved). For platform-related information, you need to treat it differently from general information. the common practice is to set up another line, and then write the precautions or special information on a specific platform. This information should be sufficient, this allows your readers to write test information, such as boundary conditions, parameter ranges, and breakpoints.
It is also a blank line, followed by the tag of the document, indicating some technical information, mainly the call parameter type, the return value is extremely type, inheritance relationship, related methods/functions.
For example For details about such a label, see Appendix 2.
Example of a document comment
/**
* Add the function to add two numbers.
*
* In a simple addition calculation, the function accepts two numbers a and B and returns their and c
*
* @ Param int addition
* @ Param int add count
* @ Return integer
*/
Function Add ($ a, $ B)
{
Return $ a + $ B;
}
The generated document is as follows:
Add
Integer Add (int $ a, int $ B)
[Line 45]
Function add to add two numbers
Constants is a simple addition calculation. the Function accepts two numbers a and B and returns their and c
Parameters
• Int $ a-addend
• Int $ B-number of added parts
Document tag:
The scope of use of a document tag is a keyword that can be used to modify a document tag, or other document tag.
All document tags start with @ after each line. If @ is marked in the middle of a passage, the mark will be ignored as common content.
@ Access
Usage scope: class, function, var, define, module
Indicates the access permission for a keyword: private, public, or proteced.
@ Author
Specify author
@ Copyright
Usage scope: class, function, var, define, module, use
Copyright information
@ Deprecated
Usage scope: class, function, var, define, module, constent, global, include
Specify unnecessary or obsolete keywords
@ Example
This tag is used to parse the content of a file and highlight it. Phpdoc will try to read the file content from the file path marked
@ Const
Scope of use: define
Used to specify the define constant in php
@ Final
Usage scope: class, function, var
Specifies that a keyword is a final class, method, or attribute, and cannot be derived or modified.
@ Filesource
Similar to example, however, this tag will directly read and display the content of the currently resolved php file.
@ Global
Specifies the global variables referenced in this function.
@ Ingore
Used to ignore specified keywords in the document
@ License
It is equivalent to the URL in the html tag, followed by the content to be displayed.
For example, Baidu
Can Write @ license http://www.baidu.com Baidu
@ Link
Similar to license
However, you can refer to any keyword in the document through link.
@ Name
Specify an alias for the keyword.
@ Package
Scope of use: page-> define, function, include
Class-> class, var, methods
It is used to logically group one or more keywords into one group.
@ Shortcut
Indicates that the current class is an abstract class.
@ Param
Specify the parameters of a function.
@ Return
Specifies the return value of a method or function.
@ Static
Indicates that the word is static.
@ Var
Variable type
@ Version
Specify version information
@ Todo
Specify the areas to be improved or not implemented
@ Throws
Indicates the error exception that this function may throw.
As mentioned above, the mark of common documents must start with @ at the beginning of each line. In addition, there is also a mark called inline tag, which is represented by {@}, including the following:
{@ Link}
Usage: @ link
{@ Source}
Display the content of a function or method
Some annotation specifications
A. The comment must be
/**
* XXXXXXX
*/
Format
B. The glboal mark must be used for functions that reference global variables.
C. for variables, you must use var to mark their types (int, string, bool ...)
D. the function must specify its parameters and return values through param and return tags.
E. for keywords that appear twice or more times, ignore unnecessary keywords through ingore and retain only one keyword.
F. when other functions or classes are called, link or other markup should be used to link to the corresponding part for easy reading of the document.
G. use non-document comments as necessary to improve ease of coding.
H. The descriptive content should be as concise as possible and use phrases instead of sentences as much as possible.
I. global variables, static variables and constants must be marked with corresponding descriptions
Summary
PhpDocumentor is a very powerful automatic document generation tool. it helps us write standard comments, generate easy-to-understand and well-structured documents, and upgrade and maintain our code, the handover and so on are of great help.
For more details about phpDocumentor, visit its official website.
Two examples:
Instance 1
Instance 2