Giter Club home page Giter Club logo

Comments (10)

larsnystrom avatar larsnystrom commented on August 16, 2024

A fallback_if_invalid setting would fix this. If it defaulted to true there would be no BC break. It would also be pretty easy to implement.

from zend-inputfilter.

weierophinney avatar weierophinney commented on August 16, 2024

It would also be pretty easy to implement.

Considering the dozens of hours spent with the most recent releases to build a test matrix for the current combination of options, I beg to differ. Any new options introduced at this point need to be very carefully evaluated, as they add more permutations to the test matrix: we already are testing something like 32 combinations of options; adding another would double that to 64.

from zend-inputfilter.

larsnystrom avatar larsnystrom commented on August 16, 2024

Considering the dozens of hours spent with the most recent releases to build a test matrix for the current combination of options, I beg to differ. Any new options introduced at this point need to be very carefully evaluated, as they add more permutations to the test matrix: we already are testing something like 32 combinations of options; adding another would double that to 64.

In that case, maybe we could remove the "fallback if invalid" behaviour in 3.0?

from zend-inputfilter.

svycka avatar svycka commented on August 16, 2024

I think the name is not correct for this behavior I am thinking about default_value or something this should be used only if value not set, otherwise should be used fallback if set. this also would solve BC problem but also have big test matrix problem. But well if this is good feature and we want it in 3.0 we can do it now and remove whole test matrix in 3.0 when other options will be removed.

from zend-inputfilter.

Maks3w avatar Maks3w commented on August 16, 2024

The behavior can be do with very little effort by extending Input with your custom class.

Personally I prefer don't add implementations are not required by the Input interface and just provide stable and tested implementations.

Anyway, feel free to send a PR with the desired implementation and I'll reconsider my opinion if the implementation is simple and bugfree

Hint:

return [
// Description => [$inputIsRequired, $fallbackValue, $originalValue, $isValid, $expectedValue]
'Required: T, Input: Invalid. getValue: fallback' => [ $required, $fallbackValue, $originalValue, !$isValid, $fallbackValue],
'Required: T, Input: Valid. getValue: original' => [ $required, $fallbackValue, $originalValue, $isValid, $originalValue],
'Required: F, Input: Invalid. getValue: fallback' => [!$required, $fallbackValue, $originalValue, !$isValid, $fallbackValue],
'Required: F, Input: Valid. getValue: original' => [!$required, $fallbackValue, $originalValue, $isValid, $originalValue],
];

public function testValidationSkipsFieldsMarkedNotRequiredWhenNoDataPresent()
{
$filter = $this->inputFilter;
$optionalInputName = 'fooOptionalInput';
/** @var InputInterface|MockObject $optionalInput */
$optionalInput = $this->getMock(InputInterface::class);
$optionalInput->method('getName')
->willReturn($optionalInputName)
;
$optionalInput->expects($this->never())
->method('isValid')
;
$data = [];
$filter->add($optionalInput);
$filter->setData($data);
$this->assertTrue(
$filter->isValid(),
'isValid() value not match. Detail . ' . json_encode($filter->getMessages())
);
$this->assertArrayNotHasKey(
$optionalInputName,
$filter->getValidInput(),
'Missing optional fields must not appear as valid input neither invalid input'
);
$this->assertArrayNotHasKey(
$optionalInputName,
$filter->getInvalidInput(),
'Missing optional fields must not appear as valid input neither invalid input'
);
}

from zend-inputfilter.

svycka avatar svycka commented on August 16, 2024

@Maks3w what do you think if we make this default behavior in ZF3?
I think it is more logical to add fallback(default value) if value isn't set, but not when value is invalid(I would want error here). Or support both, but maybe that would be to complicated.

This would be BC but for 3.0 this is acceptable.

from zend-inputfilter.

vaclavvanik avatar vaclavvanik commented on August 16, 2024

@svycka +1 I use same behavior especially in grid controllers

from zend-inputfilter.

Maks3w avatar Maks3w commented on August 16, 2024

@svycka I don't consider replace a behavior an option. Instead I suggest send a PR where two behaviors could be used (one at time) probably setting a second parameter to setFallbackValue with an optional second argument where the default value is the current behavior.

from zend-inputfilter.

Maks3w avatar Maks3w commented on August 16, 2024

Closed due inactivity

from zend-inputfilter.

Erikvv avatar Erikvv commented on August 16, 2024

Ran into this limitation today made me pull my hair out. Fallback values which just work in the empty case would be very much appreciated.

W.r.t. complexity in the combination of flags: I think the solution is to split the Input class to multiple classes. Some combinations of options don't make sense or are very niche and you avoid that entirely that way.

from zend-inputfilter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.