public $ifPart;
public $thenPart;
- /**
- * Constructor.
- *
- * @param NodeDefinition $node The related node
- */
public function __construct(NodeDefinition $node)
{
$this->node = $node;
/**
* Marks the expression as being always used.
*
- * @param \Closure $then
- *
* @return $this
*/
public function always(\Closure $then = null)
*
* The default one tests if the value is true.
*
- * @param \Closure $closure
- *
* @return $this
*/
public function ifTrue(\Closure $closure = null)
/**
* Tests if the value is in an array.
*
- * @param array $array
- *
* @return $this
*/
public function ifInArray(array $array)
/**
* Tests if the value is not in an array.
*
- * @param array $array
- *
* @return $this
*/
public function ifNotInArray(array $array)
}
/**
- * Sets the closure to run if the test pass.
+ * Transforms variables of any type into an array.
*
- * @param \Closure $closure
+ * @return $this
+ */
+ public function castToArray()
+ {
+ $this->ifPart = function ($v) { return !is_array($v); };
+ $this->thenPart = function ($v) { return array($v); };
+
+ return $this;
+ }
+
+ /**
+ * Sets the closure to run if the test pass.
*
* @return $this
*/
*/
public function thenInvalid($message)
{
- $this->thenPart = function ($v) use ($message) {throw new \InvalidArgumentException(sprintf($message, json_encode($v))); };
+ $this->thenPart = function ($v) use ($message) { throw new \InvalidArgumentException(sprintf($message, json_encode($v))); };
return $this;
}