Skip to content

Commit c99791a

Browse files
committed
Add ifFalse()
1 parent da15553 commit c99791a

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+
public function ifFalse(?\Closure $closure = null): static
78+
{
79+
$this->ifPart = $closure ?? static fn ($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+
public function testIfFalseExpression()
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
public function testIfStringExpression()
5374
{
5475
$test = $this->getTestBuilder()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy