Parsing the source
Phase 1 of the Documentation Generation Process is for DocBlox to analyze your existing source code and create a summary of its structure.
You can invoke DocBlox to generate this structure summary using two different ways executables:
- docblox.php
- parse.php
Both of these executables are located in the bin directory of your DocBlox installation path, and when you install using PEAR you can invoke the docblox command from any location on your operating system.
DocBlox.php
The docblox command (which actually executes the docblox.php file in the aforementioned bin folder) is a forefront which can be used to indirectly invoke the parse.php executable. This was done to simplify things for use in Continuous Integration environments like Jenkins as they commonly require a single global executable file.
So. what does all that mean?
Every time you invoke the docblox(.php) command with the term parse as its first argument; it will actually invoke parse.php. As such we will only describe parse.php and its arguments.
Note: docblox.php is planned for an overhaul; the intention in the end is that this executable will invoke both the parsing and transformation in one go; currently you need to invoke this script twice separately to achieve a complete generation of your API documentation.
Parse.php
The CLI interface of the parser was originally designed to match the CLI interface of phpDocumentor. This was done to make the migration from phpDocumentor to DocBlox easier.
As such the parser always requires that you provide it with files and directories to parse using either the command line parameters or the configuration file.
Command line parameters
Currently the parser supports the following command line parameters:
| Flag | Expected content type | Description |
|---|---|---|
| -h -help |
<none> | Displays the help text which shows a list and details of all parameters |
| -c -config |
<filename> | the location of a docblox configuration file; when used the settings from this file are loaded before the other parameters are interpreted (thus you can overwrite configuration directives on the command line). By default only the settings from the docblox.config.xml in the DocBlox project folder are used. |
| -f -filename |
<filename> | With this directive you can tell DocBlox which files to parse. You can provide a comma-separated list where the ? (any single character) and * (any sequence of characters of any length) wildcards are supported. This directive is required if the -d directive is not passed. |
| -d -directory |
<directory> | With this directive you can tell DocBlox which directories to parse. You can provide a comma-separated list where the ? (any single character) and * (any sequence of characters of any length) wildcards are supported. This directive is required if the -f directive is not passed. |
| -e -extensions |
<file extensions> | Here you can optionally provide a comma-separated list of extensions which DocBlox must parse; by default it will only check files ending with:
|
| -t -target |
<directory> | When provided, DocBlox will store the generated structure.xml on this location. Defaults to a folder named ‘output’ in the current working directory. |
| -v -verbose |
<none> | When provided, extra information will be shown which is useful in, for example, debugging.
Note: this directive comes with a price; when in effect the performance of DocBlox will be lower then when not given as more I/O and STDOUT actions are required. |
| -i -ignore |
<patterns> | A comma-separated list of patterns used to mark which folders and/or files need not parsed. As with the filename and directory directiev you can use the ? and * wildcards here. Defaults to <none>. |
| -m -markers |
<patterns> | An example of a marker is a TODO or FIXME statement; whenever DocBlox finds a marker as given with this parameter in the source, it will ocpy that source code line into a special marker log. By default this parameter is TODO and FIXME, no wildcards are possible here. |
| -force | <none> | The default behavior of DocBlox is that when a structure.xml file exists at the source location that every to-be-parsed file is first checked whether it has modified since the last run. If not; then it will not be re-parsed. When the force parameter is given this check is ignored and every file is parsed as usual. |
| -validate | <none> | DocBlox supports PHP Lint checking but disables this by default for performance reasons; when you really want to do a PHP Lint check before you try to run the documentor then you can provide this parameter.
Warning: this flag seriously affects performance. Only enable this when you are really sure that you want to do this. |
Configuration file
If you have read the command line paragraph well you have discovered that DocBlox also supports configuration files which define what settings are used. This is especially useful when you have a large project with specific settings that you do not want to type by hand every time; additionally it is possible to provide more options to the parsing process then the command line can offer.
DocBlox has 3 layers of configuration:
- Global configuration; this is defined in the docblox.config.xml file in the root of the DocBlox application folder. This file contains the defaults for the entire application and thus contains every configuration setting that DocBlox supports. Please remember that this file is distributed with DocBlox and can change during an upgrade.
- Per-project configuration; this is an XML file which is supplied using the -c command line directive. This file is merged with the global configuration (with the settings here taking precedence) and the combined settings are used. The per-project configuration does not need to contain all elements that are in the global configuration. Only the elements where an actual change is appropriate.
- Command line directives; each directive on the command line overwrites a setting in the global and per project configuration and is thus final.
This mechanism provides a strong basis for flexible configuration as each layer refines and builds on the previous.
The global configuration file (version 0.8.7):
<?xml version="1.0" encoding="UTF-8" ?>
<docblox>
<target>output</target>
<extensions>
<extension>php</extension>
<extension>php3</extension>
<extension>phtml</extension>
</extensions>
<logging>
<level>warn</level>
<paths>
<default>{APP_ROOT}/log/{DATE}.log</default>
<errors>{APP_ROOT}/log/{DATE}.errors.log</errors>
</paths>
</logging>
<markers>
<item>TODO</item>
<item>FIXME</item>
</markers>
<transformations>
<template name="default" />
</transformations>
</docblox>
Except for the logging element and the transformations element everything should be reasonably self-explanatory (if not; hop on the Freenode IRC server, join #docblox and ask).
Logging
There is no command line argument which is equivalent to the settings in this element; so I will explain the elements contained here:
- level; this is the minimum level that will be logged. Everything below this level will be ignored and not recorded.
I would like to point out here that it is currently not possible to actually disable logging; if you want to log as little as possible I can advice to set the setting to emerg as that is only rarely used.
The applicable levels are (in order):- debug
- info
- notice
- warn
- err
- crit
- alert
- emerg
- paths->default; this is the location of the normal logging file; it may contain 2 parameters: {APP_ROOT} and {DATE}, the first is the location of the DocBlox installation folder and the second is the current time formatted as: YmdHis
- paths->errors; this is the location where everything concerning debugging is stored when verbose mode is on.
Transformations
Here you can add individual transformations and / or templates. This subject not entirely into scope for this part of the documentation and will be discussed in the transformation section.
Examples
The minimal command line argument is where you tell DocBlox to parse the current directory and create a structure.xml in the subfolder output of the current working directory (we will also show the docblox command as extra example):
$ php bin/parse.php -d .
$ docblox parse -d .
When you want to tell docblox to store the structure.xml file in your home directory you can do the following:
$ php bin/parse -d . -t ~
$ docblox parse -d . -t ~
Ignoring any file in the tests sub-folder goes like this:
$ php bin/parse -d . -t ~ -i tests/*
$ docblox parse -d . -t ~ -i tests/*