PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1
CHAPTER 16 ■ GENERATING DOCUMENTATION WITH PHPDOCUMENTOR

Generating Documentation


It might seem odd to generate documentation before we have even written any, but phpDocumentor
parses the code structures in our source code, so it can gather information about your project before you
even start.
I are going to document aspects of an imaginary project called “megaquiz.” It consists of two
directories, command and quiztools, which contain class files. These are also the names of packages in the
project. phpDocumentor can be run as a command line tool or through a slick web GUI. I will
concentrate on the command line, because it’s easy then to embed documentation updates into build
tools or shell scripts. The command to invoke phpDocumentor is phpdoc. You will need to run the
command with a number of arguments in order to generate documentation. Here’s an example:


phpdoc -d megaquiz/ \
-t docs/megaquiz/ \
-ti 'Mega Quiz' \
-dn 'megaquiz'


The -d flag denotes the directory whose contents you intend to document. -t denotes your target
directory (the directory to which you wish to write the documentation files). Use -ti to set a project title,
and -dn to define the default package name.
If we run this command on our undocumented project, we get a surprising amount of detail. You
can see the menu page of our output in Figure 16–1.


Figure 16–1. A basic phpDocumentor output menu

Free download pdf