Znarkus / postmark-php

Postmark PHP class
http://developer.postmarkapp.com/developer-libs.html#php-5
139 stars 49 forks source link

allow class to be extendable #4

Closed zdanozdan closed 13 years ago

zdanozdan commented 13 years ago

Hi, I am working on PostMark plugin for Symfony framework, and there is a need for class Mail_Postmark to be exteded, but some methods and members are private and IMHO should be protected. For example doing somethng like this is impossible as _apiKey is private and will not be set in parent class. Diff attached.

class sfPostMark extends Mail_Postmark { public function __construct() { $this->_apiKey = sfPostMarkAdapter::getApiKey();
sfPostMarkAdapter::setupDefaults($this); $this->messageHtml(null)->messagePlain(null); }

Tomasz

Znarkus commented 13 years ago

Is there any reason you can't use the adapter? Extending third party classes like that is not all that good, if I would change the internal calls your class would probably break.

zdanozdan commented 13 years ago

Ok the reason is pretty simple. I am using PHP framework which has autoloading turned on. So all php classes are loading automatically as php starts which also includes Mail_Postmark_Adapter from test directory. This is OK (I just forked this lib, I don't care about contents). Now:

  1. I have extended Mail_Postmark class with my specific functionality - so far so good.
  2. I want to write my own adapter (as I should) but I cant coz such class already exists (Mail_Postmark_Adapter) in autoloader - class name is fixed in the code. Following wont work: "myadapter extends Mail_Postmark_Adapter"
  3. I could just override __construct() in Mail_Postmark but there is no accessor methods for __apiKey member (get,set)

So basically all the evil comes from class autoloader.

So solutions are:

  1. Remove test directory in my fork which I don't like - I want to fork whole and do not worry about contents. Also I cant have this lib as git submodule, I need to remeber every time I fork to remove adapter class.
  2. Add getter/setter methods for __apiKey for keeping code maintanable. 3 other solution ?

Those are not like big issues, just things I run into while developing plugin.

Znarkus commented 13 years ago

I'm not sure I understand. Is there a Mail_Postmark_Adapter that you haven't written, that you don't want to use? Postmark should only include an interface.