Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc99791a

Browse files
committed
Add ifFalse()
1 parentda15553 commitc99791a

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

‎src/Symfony/Component/Config/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add`ifFalse()`
8+
49
7.2
510
---
611

‎src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ public function ifTrue(?\Closure $closure = null): static
6767
return$this;
6868
}
6969

70+
/**
71+
* Sets a closure to use as tests.
72+
*
73+
* The default one tests if the value is false.
74+
*
75+
* @return $this
76+
*/
77+
publicfunctionifFalse(?\Closure$closure =null):static
78+
{
79+
$this->ifPart =$closure ??staticfn ($v) =>false ===$v;
80+
$this->allowedTypes =self::TYPE_ANY;
81+
82+
return$this;
83+
}
84+
7085
/**
7186
* Tests if the value is a string.
7287
*

‎src/Symfony/Component/Config/Tests/Definition/Builder/ExprBuilderTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ public function testIfTrueExpression()
4949
$this->assertFinalizedValueIs('value',$test);
5050
}
5151

52+
publicfunctiontestIfFalseExpression()
53+
{
54+
$test =$this->getTestBuilder()
55+
->ifFalse()
56+
->then($this->returnClosure('new_value'))
57+
->end();
58+
$this->assertFinalizedValueIs('new_value',$test, ['key' =>false]);
59+
60+
$test =$this->getTestBuilder()
61+
->ifFalse(fn () =>false)
62+
->then($this->returnClosure('new_value'))
63+
->end();
64+
$this->assertFinalizedValueIs('new_value',$test);
65+
66+
$test =$this->getTestBuilder()
67+
->ifFalse(fn () =>true)
68+
->then($this->returnClosure('new_value'))
69+
->end();
70+
$this->assertFinalizedValueIs('value',$test);
71+
}
72+
5273
publicfunctiontestIfStringExpression()
5374
{
5475
$test =$this->getTestBuilder()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp