Forum Feature requests

PHP class usage + Drupal module

siliconmeadow
Hi,

We've been using a Drupal module (https://drupal.org/node/1733320) on our production system and it is working fine for our day-to-day needs.

I'm currently doing some modifications to the module, so that I can not only provide a link for clients to click on a link to generate a PDF on the fly which then immediately starts downloading for them, but so we can, as administrators, save the PDF on the server for further processing (zipping it up with some other files, to be specific).

The creator of the Drupal module has designed it to use the Prince php class, as is. At this stage we don't seem to see that any of the convert* methods in the class return anything other than 'success'.

My modifications to the Drupal module extend the Prince class and will use the DrupalStreamWrapper interface to give other Drupal module developers/themers/site builders the ability to choose what they want to do with the PDF - save it to Drupal's 'private://' or 'public:' URIs, or a directory of choice for the module developer, as well as to send the file straight to the users browser.

To do so, I've changed all the 'private' properties and methods in the Prince class to 'protected'. I'd be interested to know the decisions about why 'private' was chosen. I hope you don't mind me asking? :-)

I can also see, from a Drupal point of view, that it would make sense for us to use the Libraries API module (https://drupal.org/project/libraries). It might be useful if the comments at the top of the Prince php class file had some version information in it.

I'm happy to supply my modified version if that helps?

Kind regards,

Richard
https://drupal.org/user/55284
mikeday
To do so, I've changed all the 'private' properties and methods in the Prince class to 'protected'. I'd be interested to know the decisions about why 'private' was chosen. I hope you don't mind me asking?

Just on the general principle that composition (have-a) is better than inheritance (is-a), and you can always make a new class that contains a Prince class, instead of inheriting from it. :)

I don't know much about Drupal, do you need version comments with a particular syntax, or does it just need to be human readable?
siliconmeadow
Thanks for explaining that one, Mike!

mikeday wrote:
I don't know much about Drupal, do you need version comments with a particular syntax, or does it just need to be human readable?


Human readable is fine and preferred. All of the library module implementations I've seen simply grep for it. It would be handy if you always put it on line X. :-)

Cheers,

Richard