Re: [PHP-DOC] Patches

2009-07-16 Thread Hannes Magnusson
On Thu, Jul 16, 2009 at 05:37, Moacir de
Oliveiramoacirdeoliveira@gmail.com wrote:
 Hey guys,

 Some patches to improve the factory system and load the formats dynamically.

How does it improve the system?
Are there any performance differences? Readability changes? Extendability?

I know the answer (heck, I commented on this few weeks ago :)), but
you still need to be able to explain the patch.
Ideally the explanation should be so good that I wouldn't even have to
view the patch :)

-Hannes


Re: [PHP-DOC] Patches

2009-07-16 Thread Moacir de Oliveira
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


Re: [PHP-DOC] Patches

2009-07-16 Thread G. T. Stresen-Reuter
On Jul 16, 2009, at 2:04 PM, Moacir de Oliveira moacirdeoliveira@gmail.com 
 wrote:



Patch Explanation


Outstanding explanation. Gave me some ideas for how to improve my own  
code.


Ted Stresen-Reuter




Re: [PHP-DOC] Patches

2009-07-16 Thread Hannes Magnusson
On Thu, Jul 16, 2009 at 15:04, Moacir de
Oliveiramoacirdeoliveira@gmail.com wrote:
 Patch Explanation
[...]

Looks good to me :)

-Hannes