Skip to content

Commit dd3912d

Browse files
committed
Fix deprecations in symfony/validator, including the fix in #2417
Fixes #2416
1 parent d247368 commit dd3912d

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

Controller/Annotations/AbstractScalarParam.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ public function getConstraints()
4141
if ($this->requirements instanceof Constraint) {
4242
$constraints[] = $this->requirements;
4343
} elseif (is_scalar($this->requirements)) {
44-
$constraints[] = new Regex([
45-
'pattern' => '#^(?:'.$this->requirements.')$#xsu',
46-
'message' => sprintf(
44+
$constraints[] = new Regex(
45+
'#^(?:'.$this->requirements.')$#xsu',
46+
sprintf(
4747
'Parameter \'%s\' value, does not match requirements \'%s\'',
4848
$this->getName(),
4949
$this->requirements
5050
),
51-
]);
51+
);
5252
} elseif (is_array($this->requirements) && isset($this->requirements['rule']) && $this->requirements['error_message']) {
53-
$constraints[] = new Regex([
54-
'pattern' => '#^(?:'.$this->requirements['rule'].')$#xsu',
55-
'message' => $this->requirements['error_message'],
56-
]);
53+
$constraints[] = new Regex(
54+
'#^(?:'.$this->requirements['rule'].')$#xsu',
55+
$this->requirements['error_message'],
56+
);
5757
} elseif (is_array($this->requirements)) {
5858
foreach ($this->requirements as $index => $requirement) {
5959
if ($requirement instanceof Constraint) {
@@ -76,7 +76,7 @@ public function getConstraints()
7676
// value of the map
7777
if ($this->map) {
7878
$constraints = [
79-
new All(['constraints' => $constraints]),
79+
new All($constraints),
8080
];
8181
if (false === $this->nullable) {
8282
$constraints[] = new NotNull();

Controller/Annotations/FileParam.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,18 @@ public function getConstraints()
7979

8080
$options = is_array($this->requirements) ? $this->requirements : [];
8181
if ($this->image) {
82-
$constraints[] = new Image($options);
82+
$constraint = new Image();
8383
} else {
84-
$constraints[] = new File($options);
84+
$constraint = new File();
85+
}
86+
foreach ($options as $name => $value) {
87+
$constraint->$name = $value;
8588
}
8689

8790
// If the user wants to map the value
8891
if ($this->map) {
8992
$constraints = [
90-
new All(['constraints' => $constraints]),
93+
new All($constraints),
9194
];
9295
}
9396

Tests/Controller/Annotations/AbstractScalarParamTest.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ public function testScalarRequirements()
8080
$this->param->requirements = 'foo %bar% %%';
8181
$this->assertEquals([
8282
new NotNull(),
83-
new Regex([
84-
'pattern' => '#^(?:foo %bar% %%)$#xsu',
85-
'message' => "Parameter 'bar' value, does not match requirements 'foo %bar% %%'",
86-
]),
83+
new Regex(
84+
'#^(?:foo %bar% %%)$#xsu',
85+
"Parameter 'bar' value, does not match requirements 'foo %bar% %%'",
86+
),
8787
], $this->param->getConstraints());
8888
}
8989

@@ -95,10 +95,10 @@ public function testArrayRequirements()
9595
];
9696
$this->assertEquals([
9797
new NotNull(),
98-
new Regex([
99-
'pattern' => '#^(?:foo)$#xsu',
100-
'message' => 'bar',
101-
]),
98+
new Regex(
99+
'#^(?:foo)$#xsu',
100+
'bar',
101+
),
102102
], $this->param->getConstraints());
103103
}
104104

@@ -133,8 +133,6 @@ public function testArrayWithNoConstraintsDoesNotCreateInvalidConstraint()
133133
{
134134
$this->param->nullable = true;
135135
$this->param->map = true;
136-
$this->assertEquals([new All([
137-
'constraints' => [],
138-
])], $this->param->getConstraints());
136+
$this->assertEquals([new All([])], $this->param->getConstraints());
139137
}
140138
}

Tests/Controller/Annotations/FileParamTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,40 +75,40 @@ public function testComplexRequirements()
7575
public function testFileRequirements()
7676
{
7777
$this->param->nullable = true;
78-
$this->param->requirements = $requirements = ['mimeTypes' => 'application/json'];
78+
$this->param->requirements = ['mimeTypes' => 'application/json'];
7979
$this->assertEquals([
80-
new File($requirements),
80+
new File(null, null, null, 'application/json'),
8181
], $this->param->getConstraints());
8282
}
8383

8484
public function testImageRequirements()
8585
{
8686
$this->param->image = true;
87-
$this->param->requirements = $requirements = ['mimeTypes' => 'image/gif'];
87+
$this->param->requirements = ['mimeTypes' => 'image/gif'];
8888
$this->assertEquals([
8989
new NotNull(),
90-
new Image($requirements),
90+
new Image(null, null, null, 'image/gif'),
9191
], $this->param->getConstraints());
9292
}
9393

9494
public function testImageConstraintsTransformWhenParamIsAnArray()
9595
{
9696
$this->param->image = true;
9797
$this->param->map = true;
98-
$this->param->requirements = $requirements = ['mimeTypes' => 'image/gif'];
98+
$this->param->requirements = ['mimeTypes' => 'image/gif'];
9999
$this->assertEquals([new All([
100100
new NotNull(),
101-
new Image($requirements),
101+
new Image(null, null, null, 'image/gif'),
102102
])], $this->param->getConstraints());
103103
}
104104

105105
public function testFileConstraintsWhenParamIsAnArray()
106106
{
107107
$this->param->map = true;
108-
$this->param->requirements = $requirements = ['mimeTypes' => 'application/pdf'];
108+
$this->param->requirements = ['mimeTypes' => 'application/pdf'];
109109
$this->assertEquals([new All([
110110
new NotNull(),
111-
new File($requirements),
111+
new File(null, null, null, 'application/pdf'),
112112
])], $this->param->getConstraints());
113113
}
114114
}

0 commit comments

Comments
 (0)