Patch Explanation
Factory:
The last implementation of the class Format_Factory had a lot of creational
methods, one for each output format.
ex:
public function createXhtmlFormat() {
trigger_error(This format is not supported by this package,
E_USER_ERROR);
}
public function createBigXhtmlFormat() {
trigger_error(This format is not supported by this package,
E_USER_ERROR);
}
public function createPHPFormat() {
trigger_error(This format is not supported by this package,
E_USER_ERROR);
}
...
Problem:
What if a package had a really new output format? Will be necessary modify
the abstract factory to add the new output format
Solution:
Now the abstract factory has only one creational method:
createFormat($format), and the concrete factories have an array with the
output formats and classes to return
class Package_PHP_Factory extends Format_Factory {
private $formats = array(
'xhtml' = 'Package_PHP_ChunkedXHTML',
'bigxhtml' = 'Package_PHP_BigXHTML',
'php'= 'Package_PHP_Web',
'howto' = 'Package_PHP_HowTo',
'manpage'= 'Package_PHP_Functions',
'pdf' = 'Package_PHP_PDF',
'bigpdf' = 'Package_PHP_BigPDF',
'kdevelop' = 'Package_PHP_KDevelop',
);
public function __construct() {
parent::registerOutputFormats($this-formats);
}
}
But we still have the new format problem, because the classes Config and
BuildOptionsParser have predefined output formats:
class Config
{
private static $optionArray = array(
'output_format' = array(
'xhtml',
'php',
'bigxhtml',
'howto',
'manpage',
'kdevelop',
'pdf',
'bigpdf',
),
The solution is load the output formats dynamically, and now we can do this
using the factory:
Config::set_output_format($factory-getOutputFormats());
examples:
php render.php -d phpdoc/.manual.xml --format xhtml --package PHP
If the package PHP have the xhtml format everything is ok.
php render.php -d phpdoc/.manual.xml --package PHP
If we don't pass the --format arg, all the formats in the PHP factory will
be loaded.
php render.php -d phpdoc/.manual.xml --package Pear
only the pear output formats will be loaded
php render.php -d phpdoc/.manual.xml --format newformat --package NewPackage
now we can run new formats \o/
--Moacir