|
@@ -6,6 +6,7 @@ namespace Symfony\Component\DependencyInjection\Configuration\Builder;
|
|
|
* This class builds an if expression.
|
|
|
*
|
|
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
|
+ * @author Christophe Coevoet <stof@notk.org>
|
|
|
*/
|
|
|
class ExprBuilder
|
|
|
{
|
|
@@ -23,6 +24,18 @@ class ExprBuilder
|
|
|
$this->parent = $parent;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Mark the expression as being always used.
|
|
|
+ *
|
|
|
+ * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
|
|
|
+ */
|
|
|
+ public function always()
|
|
|
+ {
|
|
|
+ $this->ifPart = function($v) { return true; };
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Sets a closure to use as tests.
|
|
|
*
|
|
@@ -78,6 +91,20 @@ class ExprBuilder
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Tests if the value is in an array.
|
|
|
+ *
|
|
|
+ * @param array $array
|
|
|
+ *
|
|
|
+ * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
|
|
|
+ */
|
|
|
+ public function ifInArray(array $array)
|
|
|
+ {
|
|
|
+ $this->ifPart = function($v) use ($array) { return in_array($v, $array, true); };
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Sets the closure to run if the test pass.
|
|
|
*
|
|
@@ -104,6 +131,32 @@ class ExprBuilder
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets a closure marking the value as invalid at validation time.
|
|
|
+ *
|
|
|
+ * @param string $message
|
|
|
+ *
|
|
|
+ * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
|
|
|
+ */
|
|
|
+ public function thenInvalid($message)
|
|
|
+ {
|
|
|
+ $this->thenPart = function ($v) use ($message) {throw new \InvalidArgumentException($message); };
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Sets a closure unsetting this key of the array at validation time.
|
|
|
+ *
|
|
|
+ * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
|
|
|
+ */
|
|
|
+ public function thenUnset()
|
|
|
+ {
|
|
|
+ $this->thenPart = function ($v) { throw new UnsetKeyException('Unsetting key'); };
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns the parent node
|
|
|
*
|