Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.21.8

Request #13783 Add factory pattern for filters
Submitted: 2008-04-27 13:06 UTC
From: dasourcerer Assigned:
Status: Open Package: Date_Holidays (version CVS)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 35 - 23 = ?

 
 [2008-04-27 13:06 UTC] dasourcerer (Stephan Hohmann)
Description: ------------ While letting a user select a set of holiday drivers from a UI, the same is pure pain for filters. I think a factory method for filters would greatly improve this situation.

Comments

 [2008-04-27 13:09 UTC] doconnor (Daniel O'Connor)
Can you show us with a bit of psuedocode what you mean by 'pure pain'?
 [2008-04-27 13:47 UTC] dasourcerer (Stephan Hohmann)
Well, for holiday drivers I can simply go with: include('Date/Holidays.php'); $composite = Date_Holidays::factory('Composite'); /* $selectedDrivers is a subset of the result from Date_Holidays::getInstalledDrivers() */ foreach($selectedDrivers as $driver) { $composite->addDriver(Date_Holidays::factory($driver['id'])); } This is very convenient and relatively safe. Now the same for filters were about this: include('Date/Holidays/Filter/Composite.php'); $compositeFilter = new Date_Holidays_Filter_Composite(); /* $selectedFilters is a subset of the result from Date_Holidays::getInstalledFilters() */ foreach($selectedFilters as $filter) { @include_once('Date/Holidays/Filter/' . $filter['id]); if(class_exists('Date_Holidays_Filter_' . $filter['title'])) { $compositeFilter->addFilter(new 'Date_Holidays_Filter' . $filter['title']()); } ) Now this doesn't seem like a big deal at first. Yet I am feeling pretty uncomfortable with making assumptions on the package structure and other logic that were better off being handled by the package itself. Perhaps the Date_Holidays::factory() could be modified to create filters as well?
 [2008-06-11 08:08 UTC] dasourcerer (Stephan Hohmann)
So, are there any decissions on this? I'd provide a patch but I am not really sure where to place the factory method...
 [2008-06-12 08:11 UTC] kguest (Ken Guest)
I think it would be best to have a factory method for filters as a method of the [base] driver that the filters would relate to - i.e. the Ireland driver would have a factory method for returning a filter of [Un]Official holidays observed in Ireland; though this method should be inherited from the base Driver class. A use case could be something along the lines of: include('Date/Holidays.php'); $composite = Date_Holidays::factory('Composite'); $compositeFilter = new Date_Holidays_Filter_Composite(); /* $selectedDrivers is a subset of the result from Date_Holidays::getInstalledDrivers() */ foreach($selectedDrivers as $driver) { $fdriver = Date_Holidays::factory($driver['id']); $composite->addDriver($fdriver); $filters = $fdriver->getInstalledFilters(); /* $selectedFilters is a subset of $filters */ foreach($selectedFilters as $filter) { $compositeFilter->AddFilter($filter); $$filter = $fdriver->filterFactory($filter); } } We shouldn't have to search the filesystem for obtaining the actual data/filter names returned by the getInstalledFilters method - at the moment only Germany, Ireland and Netherlands subpackages have filters so there wouldn't be much impact involved in those drivers simply returning an array containing the names of the relevant/associated filters. so, similar to getISO3166Codes, we use something like the following rather than wasting resources searching the file system: Date_Holidays_Driver_Germany::getInstalledFilters() { return array('Official', 'Berlin', ....); } and the factory method simply creates and dispenses the appropriate filter.
 [2008-06-23 18:41 UTC] dasourcerer (Stephan Hohmann)
I've spent some time thinking about this. I think the last proposed solution is a good way for single instances of holiday drivers but exposes too much functionality in other cases. Maybe it were good to hide this within the composite filter and add a Date_holidays_Filter_Composite::addFilterById(...) method?
 [2011-08-24 21:28 UTC] ralf_lang_b1_systems (Ralf Lang (B1 Systems GmbH))
I would like to discuss and probably implement this as I have need for it. Who to contact for design discussion?
 [2011-08-24 21:42 UTC] kguest (Ken Guest)
That would be me, mainly. Patches welcome :)