New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFR] Improve Filter Service #13060

Closed
emiliodeg opened this Issue Sep 5, 2017 · 1 comment

Comments

Projects
3 participants
@emiliodeg
Copy link
Member

emiliodeg commented Sep 5, 2017

Hi I think the actual filter service is very rigid and not very customizable. Although we can add functions can not be encapsulated in objects which is a great loss of usability and maintenance.

New Filter Service

  1. Be able to define each of the available filters and their params
  2. Filters, even pre-defined filters, that have configuration parameters
  3. A magic method to easily access them from the service
  4. All filters must be objects and implement a FilterInterface interface

Example Proposal One

New filter service

$di = new Phalcon\Di();
$di->set('filter', function() {
    $filter = new Phalcon\Filter(true); // true/false => to load or not default filters (string, email, absint, etc)
    $filter->loadDefaultFilters();
    $filter->removeDefaultFilters();
    $filter->set('someFilter', new Phalcon\Filter\SomeFilter()); //add new filter
    $filter->remove('email'); //remove filter
    $filter->set('absint', new My\Filter\AbsInt()); //rewrite filter
});

Example Proposal Two

Configurations params

class Striptags implements FilterInterface {
    public function __construct($whitelist = null) {}
}

Example Proposal Three

A magical method for rapid access to sanitize()

$this->getDI()->filter->absint(-1555);
$this->getDI()->filter->trim(' hello world!!      '); 

Example Proposal Four

Filter are objects and implement an interface

interface FilterInterface {
     public function sanitize($value);
}

Well what do you think?

@emiliodeg emiliodeg closed this Sep 5, 2017

@emiliodeg emiliodeg changed the title [NFR] Improve filter service [NFR] Improve Filter Service Sep 5, 2017

@emiliodeg emiliodeg reopened this Sep 5, 2017

@sergeyklay sergeyklay added this to the 4.0.0 milestone Oct 2, 2017

@stale stale bot added the stale label Apr 16, 2018

@sergeyklay sergeyklay closed this Apr 16, 2018

@sergeyklay sergeyklay reopened this May 2, 2018

@stale stale bot removed the stale label May 2, 2018

@niden niden added this to In progress in 4.0 Release Nov 28, 2018

@niden niden moved this from In progress to To do in 4.0 Release Nov 28, 2018

@phalcon phalcon deleted a comment from stale bot Dec 17, 2018

@niden niden moved this from To do to In progress in 4.0 Release Jan 19, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 20, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 20, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 20, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 20, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 20, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 20, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 25, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 25, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 25, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 25, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 25, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 25, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 25, 2019

[phalcon#13060] - Merge branch '4.0.x' into T13060-filter-service
* 4.0.x:
  _httpOnly has a default value of false
  Updated Tests
  Update tests/unit/Http/Cookie/CookieCest.php
  Created test for Issue phalcon#13464
  Fixes phalcon#13464: httpOnly is no longer initialised with a value
  Regenerated build
  Use latest Zephir
  phalcon#13749: Removed Phalcon\Mvc\User\* (phalcon#13775)
  phalcon#13717: Cleaned up the `Phalcon\Mvc\Model\Metadata\Redis` constructor (phalcon#13774)
  phalcon#13758: `Phalcon\Exception` implements `\Throwable` (phalcon#13776)

niden added a commit to niden/cphalcon that referenced this issue Jan 25, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 26, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 26, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 27, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 27, 2019

@niden niden referenced this issue Jan 27, 2019

Merged

T13060 filter service #13787

3 of 3 tasks complete

niden added a commit to niden/cphalcon that referenced this issue Jan 27, 2019

[phalcon#13060] - Merge branch '4.0.x' into T13060-filter-service
* 4.0.x:
  phalcon#13352: Select elements can now render without any options

niden added a commit to niden/cphalcon that referenced this issue Jan 27, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 27, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 27, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 27, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 27, 2019

niden added a commit that referenced this issue Jan 27, 2019

Merge branch 'niden-T13060-filter-service' into 4.0.x
* niden-T13060-filter-service: (22 commits)
  [#13060] - Correction to the method calls/parameters
  [#13060] - Removed unecessary for now interface
  [#13060] - Corrected types of the methods
  [#13060] - Corrected the name of the file
  [#13060] - Changes to the absint to remove all non numeric characters
  [#13060] - Corrected tests
  [#13060] - Test corrections
  [#13060] - More work on the filters; Anonymous functions resolution and tests
  [#13060] - Corrections to the sanitizers; Adjusted tests
  [#13060] - Updates to the changelog
  [#13060] - Refactored the html tag locator
  [#13060] - Adjustments to the service locator
  [#13060] - Sorted out filter tests
  [#13060] - Removed files from removed classes
  [#13060] - Adjustments to the service locator
  [#13060] - Work on the sanitizers; Wrote tests
  [#13060] - More tests!! yey
  [#13060] - Replaced references to the filter service with filter service locator
  [#13060] - Corrections to the filter tests
  [#13060] - Adjusted and wrote more tests
  ...
@niden

This comment has been minimized.

Copy link
Member

niden commented Jan 27, 2019

This has been implemented. Thank you @emiliodeg for the idea

https://docs.phalconphp.com/4.0/en/filter

@niden niden closed this Jan 27, 2019

4.0 Release automation moved this from In progress to Done Jan 27, 2019

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