10000 [Config] Add ExprBuilder::ifEmpty() · symfony/symfony@4e46f64 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e46f64

Browse files
committed
[Config] Add ExprBuilder::ifEmpty()
1 parent d923e35 commit 4e46f64

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ public function ifNull()
9797
return $this;
9898
}
9999

100+
/**
101+
* Tests if the value is empty.
102+
*
103+
* @return ExprBuilder
104+
*/
105+
public function ifEmpty()
106+
{
107+
$this->ifPart = function ($v) { return empty($v); };
108+
109+
return $this;
110+
}
111+
100112
/**
101113
* Tests if the value is an array.
102114
*

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ public function testIfNullExpression()
7575
$this->assertFinalizedValueIs('value', $test);
7676
}
7777

78+
public function testIfEmptyExpression()
79+
{
80+
$test = $this->getTestBuilder()
81+
->ifEmpty()
82+
->then($this->returnClosure('new_value'))
83+
->end();
84+
$this->assertFinalizedValueIs('new_value', $test, array('key' => array()));
85+
86+
$test = $this->getTestBuilder()
87+
->ifEmpty()
88+
->then($this->returnClosure('new_value'))
89+
->end();
90+
$this->assertFinalizedValueIs('value', $test);
91+
}
92+
7893
public function testIfArrayExpression()
7994
{
8095
$test = $this->getTestBuilder()

0 commit comments

Comments
 (0)
0