Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
Moderator: General Moderators
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Nov 01, 2007 10:09 pm
I'm working on some validation / filtering classes. So far we have these classes:
Data
Data_Validate
Data_Filter
I want to write a class that ties Data to Data_Validate and Date_Filter. So some example code would look like:
Code: Select all
$process = new Fp_Data_Process($_POST); // converts $_POST to a Data object
$process->addFilter('FormatCurrency', 'sallary');
$process->addValidator('StringTrim', 'username');
if ($process->filterThenValidate())
{
echo 'We\'re good,', $process->get('username');
}
else
{
$errors = $process->getErrorMessages();
foreach ($errors as $error)
{
echo $error;
}
}
I don't like Data_Process and I don't like filterThenValidate(). What should I name these?
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Fri Nov 02, 2007 10:23 am
Data_Purify?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Nov 02, 2007 11:47 am
Seems like a Chain/Guantlet-type class.
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Fri Nov 02, 2007 12:28 pm
I think Chain, Processor or Manager would all be fine. It seems like it should be more like:
Code: Select all
if ($filterchain->isValid())
// or
if ($chain->process())
(#10850)