Data Filtering - Filter Functions #115

Closed
nickl- opened this Issue Feb 14, 2013 · 3 comments

Projects

None yet

4 participants

@nickl-
Member
nickl- commented Feb 14, 2013

There is a whole world of untapped goodness still in Data Filtering

If we want to sugar and spice it with panda goodness while still staying true to the PHP way I am not too sure that we can make this fit into v-double-colon without raping it, ides?

What I am thinking, to also flatten the learning curve both ways, is a new Respect\Validation\Filter along the familiar lines of:


filter::boolean(FILTER_NULL_ON_FAILURE)->var($value);

/** several variations can be supported **/
filter::validate_url(array(
   'options' => array('default'=>'http://example.com'), 
   'flags'=> FILTER_FLAG_PATH_REQUIRED 
       & FILTER_FLAG_HOST_REQUIRED 
        | FILTER_FLAG_QUERY_REQUIRED)
)->var($url);

filter::validate_url(
    FILTER_FLAG_PATH_REQUIRED 
    & FILTER_FLAG_HOST_REQUIRED 
    | FILTER_FLAG_QUERY_REQUIRED)
->options(array('default' => 'http://example.com'))
->input_cookie('domain');

filter::validate_url()->flags(
    FILTER_FLAG_PATH_REQUIRED 
    & FILTER_FLAG_HOST_REQUIRED 
    | FILTER_FLAG_QUERY_REQUIRED)
->options('default', 'http://example.com')
->input_server('host');

/** flag is default and **/
filter::validate_url()->flag(FILTER_FLAG_PATH_REQUIRED)
    ->and_flag(FILTER_FLAG_HOST_REQUIRED)
    ->or_flag(FILTER_FLAG_QUERY_REQUIRED)
->default('http://example.com')
->input_server('host');

filter::validate_url()->flag(FILTER_FLAG_PATH_REQUIRED)
    ->flag('and', FILTER_FLAG_HOST_REQUIRED)
    ->flag('or', FILTER_FLAG_QUERY_REQUIRED)
->default('http://example.com')
->input_server('host');

filter::validate_url()->flag(FILTER_FLAG_PATH_REQUIRED)
    ->flag(0&FILTER_FLAG_HOST_REQUIRED)
    ->flag(0|FILTER_FLAG_QUERY_REQUIRED)
->default('http://example.com')
->input_server('host');

filter::validate_url(FILTER_FLAG_PATH_REQUIRED)
    ->and(FILTER_FLAG_HOST_REQUIRED)
    ->or(FILTER_FLAG_QUERY_REQUIRED)
->default('http://example.com')
->input_env('HOSTNAME');

filter::validate_url('flag_path_required')
    ->and('flag_host_required')
    ->or('flag_query_required')
->default('http://example.com')
->var($url)

filter::validate_url()
    ->flag_path_required()
    ->flag_host_required()
    ->or_flag_query_required()
->default('http://example.com')
->var($url);

filter::validate_url()
    ->flag_path_required()
    ->flag_host_required('flag_query_required')
->default('http://example.com')
->var($url);

/** we can even fix some broken things **/
filter::callback(function ($v) { 
    return strtoupper($a ); 
})->var();

/** or the "valid", read broken, way **/ 
filter::callback(array( 'options' => function ($v) { 
    return strtoupper($a ); 
}))->input_get();

@Respect What are you thinking?

@alganet
Member
alganet commented Feb 14, 2013

Once upon a time we had filters: https://github.com/Respect/Validation/blob/41286de8b53041b87852fb9c35e8fd5c0da59f9f/library/Respect/Validation/Rules/AbstractComposite.php

I'm thinking about it! We could abstract out much of the 'flag' and 'required' in API calls. Perhaps follow the old filter structure (sampled in the file above) which needs some sort of final touches.

@augustohp augustohp added this to the Backlog milestone Feb 20, 2014
@henriquemoody
Member

Already implemented

@henriquemoody
Member

Sorry, it was not implemented, but I don't think it should be implemented.

Any way, I created this project past year: https://github.com/PHPFluent/Filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment