Skip to content
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

[WIP] Initial release #1

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

[WIP] Initial release #1

wants to merge 13 commits into from

Conversation

bakura10
Copy link
Member

No description provided.

@bakura10
Copy link
Member Author

ping @danizord

This is just a backport of my refactor but with the main classes for now. I'd like to clearly understand your point of view regarding the factory.

Right now, as you can see the problem is that I need to inject ValdiatorChain and FilterChain in all inputs. Actually, they are optional (like in ZF2), but the problem is that if you let the Input creates itself those two things, you will loose any custom valdiators/filters, which lead to a lot of problems, especially for beginners that do not understand why.

What do you think?

I'd like to quickly have a working version for those two classes.

protected $factory;

/**
* @var InputCollectionInterface[]|InputInterface[]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since InputCollectionInterface extends InputInterface it can be @var InputInterface[].

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I prefer to use that, so we can have proper hints from IDE when looping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's incorrect. You should not call any method from InputCollectionInterface inside a loop if it don't contains only instances of InputCollectionInterface (:

@fabiocarneiro
Copy link

Didn't like that runAgainst method. I would prefer ->filter() or something else.

@bakura10
Copy link
Member Author

@fabiocarneiro , no the runAgainst is definitely the big +1 of this refactor, because it allows completely stateless input / input collection.

class InputCollection extends Input implements InputCollectionInterface
{
/**
* @var InputCollectionInterface[]|InputInterface[]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@var InputInterface[]

@fabiocarneiro
Copy link

@bakura10 i was not talking about removing the method. I was talking about its name. runAgainst seems weird to me.

*/
public function getFilterChain()
{
return $this->filterChain ?: new FilterChain();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (null === $this->filterChain) {
    $this->filterChain = new FilterChain();
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I like oneLiner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha yeah, I get your point, sorry.

@bakura10
Copy link
Member Author

lol we had a debate about this and runAgainst was the best name we found :/. If you have a better idea, go on!


if (
$this->validatorChain->isValid($filteredValue, $context)
|| (null === $filteredValue && $this->allowEmpty)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably check it first than validator chain.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True.

{
$type = isset($specification['type']) ? $specification['type'] : Input::class;

if ($type instanceof InputInterface) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$type is a string.

@bakura10
Copy link
Member Author

I really have no idea about how to deal with the "required" parameter (adding the NotEmpty validator). In ZF2 the code seems strange: https://github.com/zendframework/zf2/blob/master/library/Zend/InputFilter/Input.php#L359

If for whatever reason you set required back to false, the validators is never removed.

* Uses a concept of "InputFilterResult"
* Renames to make it easier to understand (previous "InputFilter" has been renamed to "InputCollection")
* Behaviour is now much more predictable
* ... and a lot of things!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unaware of instantiation logic :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants