Re: File_DNS Changes

From: Date: Tue, 10 Jan 2012 22:04:44 +0000
Subject: Re: File_DNS Changes
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-54709@lists.php.net to get a copy of this message
> > > On Mon, Jan 9, 2012 at 7:58 PM, Jonathan Creasy <jc@box.com> wrote: > > > >> I'm working on some enhancements to File_DNS and this is the first PEAR > >> development I have done. I read through the style guides and best > >> practices > >> but I didn't see an answer to my question. > >> > >> The DNS classes we use internally are structured more like the Net_DNS > >> package, we have classes for the resource records (Net_DNS_RR_A for > >> example). The parser in File_DNS was superior to ours but was missing a > >> few > >> things we wanted and lacking a maintainer I decided to fork and work on > >> the > >> enhancements to contribute back. > >> > There's nothing official about this, but re-use tends to Just Make Sense - so long as the package you are using is modern enough, and allows you to deliver flexibility. So... if it does everything you want, use it. If it does most of what you want, demand feature requests/send pull requests. If nothing happens, extend the affected code in your local codebase if possible; and complain bitterly on the mailing list. ie: class File_DNS_RR_A extends Net_DNS_RR_A { /** @bug http://pear.php.net/bug?1245 - Net_DNS_RR_A does not have enough fun */ public function __toString() { return parent::__toString() . "\n" . "Wheeeeee"; } } If it does some of what you want, but you have to fight it, wrap it in an adapter/proxy. ie: class File_DNS_ResourceAdapter { public function __construct(Net_DNS2_RR_A $resource) { $this->resource = $resource; } public function doUsefulThing() { $this->resource->foo(); $this->resource->bar(); $this->resource->stupidThingYouHaveToDo(); $this->resource->foo(); $this->resource->bar(); $this->resource->stupidThingYouHaveToDo(); $this->resource->foo(); $this->resource->bar(); $this->resource->stupidThingYouHaveToDo(); } public function getHelpfulContent() { $this->resource->foo(); $this->resource->bar(); $output = $this->resource->stupidThingYouHaveToDo(); return explode("\n", $output); } } Often you want to use the above for when the code you are working with fights dependency injection, or otherwise makes life hard - at least that way the *rest* of your code can deal with your cleaner API, and the uglyness is hidden in a specific spot.

« previous php.pear.dev (#54709) next »