| Newsgroups |
php.pear.bugs |
| Message-ID |
<[email protected]> |
Edit report at http://pear.php.net/bugs/bug.php?id=13783&edit=1
ID: 13783
Comment by: [email protected]
Reported By: webmaster at dasourcerer dot net
Summary: Add factory pattern for filters
Status: Open
Type: Feature/Change Request
Package: Date_Holidays
Package Version: CVS
PHP Version: Irrelevant
Roadmap Versions:
New Comment:
I would like to discuss and probably implement this as I have need for
it.
Who to contact for design discussion?
Previous Comments:
------------------------------------------------------------------------
[2008-06-23 14:41:56] dasourcerer
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?
------------------------------------------------------------------------
[2008-06-12 04:11:06] kguest
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-11 04:08:05] dasourcerer
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-04-27 09:47:24] dasourcerer
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-04-27 09:09:01] doconnor
Can you show us with a bit of psuedocode what you mean by 'pure pain'?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://pear.php.net/bugs/bug.php?id=13783
--
Edit this bug report at http://pear.php.net/bugs/bug.php?id=13783&edit=1