So, I want to do the following, and I'm just looking for advice on how to create it.
- I have
Filterone that can be run on certain types of entities Filterhave Ruleto determine their behaviorFilter process entities using their rules and return logical- As a concrete example, I can filter out, which means that some regular expression in the given field is rejected, and I can define rules for it. I can also have different rules that use simple prefix matching in the same filter.
So, I came up with the following
interface FilterInterface
{
function loadRules();
function filter($entity, $context = array());
function supportsEntity($entity);
}
Then I plan to do:
class ImageFilter implements FilterInterface
Which will load the rules from the database and implement the filter.
So, initially I, although I had Entity, sort of
FilterRule:
- scope ( , , )
- type ( , , , )
- (, )
ImageFilter FilterRule, . ImageFilter . .
public function filter($entity)
{
foreach ($this->rules as $rule) {
switch($rule->getType()) {
case RULE_TYPE_REGEX:
$this->doRegex();
break;
case RULE_TYPE_PREFIX:
$this->doPrefix();
break;
}
}
}
, switch? , - :
public function filter($entity)
{
foreach ($this->rules as $rule) {
$rule->process($entity);
}
}
, Filter , , " " . , POPO, , ( 100% , ).
Inheritance Mapping, Rule , ( ). , , , Rule - , "" -, ...
, , :
Filter , Rule . Rule "" .Rule - . Rule "", Filter Filter , RuleRule , , switch statement- 2., 3.
Rule "" ( , , ) - 1 4. ,
Filter Rule ( , "" factory)
, , , . , , . ( , , , )