1
votes

I'm using phalcon 3 and trying to override the default httprequest class and add a default custom filter, something like this:

public function getPut($name = null, $filters = null, $defaultValue = null, $notAllowEmpty = false, $noRecursive = false)
{
     return parent::getPut($name, [$filters, function($value){return str_replace(['null', 'undefined'], null, $value);}], $defaultValue, $notAllowEmpty, $noRecursive);
}

This way I don't have to add filters to every place (controller) where i use request->getPut('paramname'). But it doesn't work. Anyone knows how to do it?

1

1 Answers

0
votes

If $filters is supposed to be an array of functions, you'll need to set $filters to an empty array by default and add your custom filter to that parameter:

public function getPut($name = null, $filters = [], $defaultValue = null, $notAllowEmpty = false, $noRecursive = false)
{
     $filters[] = function($value){return str_replace(['null', 'undefined'], null, $value);};
     return parent::getPut($name, $filters, $defaultValue, $notAllowEmpty, $noRecursive);
}