particle-php / Filter

Flexible and highly usable filtering library with no dependencies.
http://filter.particle-php.com
BSD 3-Clause "New" or "Revised" License
82 stars 11 forks source link

Create the initial Particle\Filter #1

Closed rick-nu closed 9 years ago

rick-nu commented 9 years ago

With API:

$f = new Particle\Filter;

$f->value('first_name')
    ->trim($chars)
    ->lower()
    ->upper()
    ->stripHtml()
    ->replace($search, $replace)
    ->regexReplace($regex, $replacement, Callable $callback = null)
    ->int()
    ->bool()
    ->string()
    ->float()
    ->camelcase()
    ->ucfirst()
    ->underscore()
    ->append()
    ->prepend()
    ->callable()
;

$f->filter([
    'first_name' => 'Rick'
]);

This issue is currently picked up in #4

rick-nu commented 9 years ago

@berry-langerak: alternatives for the function names:

$f = new Particle\Filter;

$f->clean('first_name')->trim(); // Option 1
$f->refine('first_name')->trim(); // Option 2
$f->update('first_name')->trim(); // Option 3
$f->set('first_name')->trim(); // Option 4

$f->filter([ // I think this should be filter
    'first_name' => 'Rick'
]);
berry-langerak commented 9 years ago

Meh. I agree on the last one (that that should be filter), but none of the options really cover the load :(

berry-langerak commented 9 years ago

@RickvdStaaij Hm. So what do you think about this?

$f = new Particle\Filter;
$f->sanitize('first_name')->trim();

$f->filter($values);

Filtering is for sanitizing values, after all? :)

rick-nu commented 9 years ago

@berry-langerak Yes, but I think sanitize is not really a common word, something you would easily remember. If you look at it from that perspective, clean might be easier. Or maybe sift?

rick-nu commented 9 years ago

And if we can't find the proper replacement for filter, then what about $f->filterValue('first_name')->trim(); or just $f->value('first_name')->trim();.

berry-langerak commented 9 years ago

I whole-heartily disagree with your assertion that sanitize is not a common word. It's actually rather common, also in the context of filtering values. Then, you could argue that value might be better:

$f = new Filter;
$f->value('first_name')->trim();
$f->value('premium_sms')->bool();

$values = $f->filter($values);

I like it. Go! :)

rick-nu commented 9 years ago

value it is!

NickBelhomme commented 9 years ago

Also will this api be included?

$f->value('*')->trim();
$f->value('premium_sms')->bool();

altenative something as

$f->allValues()->trim();
$f->value('premium_sms')->bool();

Which will then apply the filters to all values in the context and on top of that a separately filter chain to a single value.

rick-nu commented 9 years ago

@NickBelhomme $f->all()->trim() is already included, we are also thinking of adding: $f->values(['first_name', 'last_name'])->trim() But that's a bit more complex. However, you can expect that for version 1. I will release v0.1.0 when I added all filters featured in the readme, after that I will look into that.

NickBelhomme commented 9 years ago

you guys are the best! Looking forward to using it.

berry-langerak commented 9 years ago

@RickvdStaaij I think I also miss a callback filter rule, which may come in handy if you have a weird filter rule you just want to do once (e.g. prepend a "0", if the value doesn't start with "0").

rick-nu commented 9 years ago

Might be nice to add a prepend and a append anyway too, I've added those and callable to the list in #4.

rick-nu commented 9 years ago

Default filter-rules have been implemented and have been released in version 0.1.0, closing.