Skip to content

[Validator] Improve TypeValidator to handle array of types #31351

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

Merged

Conversation

jschaedl
Copy link
Contributor

@jschaedl jschaedl commented May 1, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #31330
License MIT
Doc PR tbd.

The @Type constraint is now able to handle multiple types:

/**
 * @var string|array
 * @Assert\Type(type={"string", "array"})
 */
 private $name;

and will pass when $name is either of type string or array.

@jschaedl jschaedl force-pushed the validator-type_constraint_with_multiple_types branch from 7a71b3e to 0e78ee5 Compare May 1, 2019 18:53
@xabbuh xabbuh added this to the next milestone May 4, 2019
Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

The change should also be documented in the changelog file of the Validator component.

@jschaedl
Copy link
Contributor Author

jschaedl commented May 4, 2019

The change should also be documented in the changelog file of the Validator component.

done

@jschaedl jschaedl force-pushed the validator-type_constraint_with_multiple_types branch 2 times, most recently from 925c45d to 6f949d8 Compare May 9, 2019 21:16
@Simperfit
Copy link
Contributor

Travis failure is not related.

@jschaedl jschaedl force-pushed the validator-type_constraint_with_multiple_types branch from 6f949d8 to c8b4aac Compare May 12, 2019 09:08
@jschaedl jschaedl force-pushed the validator-type_constraint_with_multiple_types branch from 628acfd to b5b61d3 Compare June 1, 2019 08:39
@jschaedl jschaedl changed the base branch from master to 4.4 June 1, 2019 08:40
@jschaedl jschaedl changed the base branch from 4.4 to master June 1, 2019 08:40
@jschaedl jschaedl force-pushed the validator-type_constraint_with_multiple_types branch from b5b61d3 to 3fb7b32 Compare June 1, 2019 08:44
@jschaedl jschaedl changed the base branch from master to 4.4 June 1, 2019 08:44
@jschaedl jschaedl force-pushed the validator-type_constraint_with_multiple_types branch from 3fb7b32 to c8100f3 Compare June 1, 2019 08:45
@fabpot
Copy link
Member

fabpot commented Jun 4, 2019

Thank you @jschaedl.

@fabpot fabpot merged commit c8100f3 into symfony:4.4 Jun 4, 2019
fabpot added a commit that referenced this pull request Jun 4, 2019
…ypes (jschaedl)

This PR was merged into the 4.4 branch.

Discussion
----------

[Validator] Improve TypeValidator to handle array of types

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31330
| License       | MIT
| Doc PR        | tbd.

The `@Type` constraint is now able to handle multiple types:

```php
/**
 * @var string|array
 * @Assert\Type(type={"string", "array"})
 */
 private $name;
```

and will pass when `$name` is either of type `string` or `array`.

Commits
-------

c8100f3 [Validator] Improve TypeValidator to handle array of types
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
This was referenced Nov 12, 2019
@jschaedl jschaedl deleted the validator-type_constraint_with_multiple_types branch February 23, 2020 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants