public function __construct($inp, Value $value, $_empty = false) { C::guardIsBool($_empty); $this->_values = $inp; $value = $value->force(); if ($value instanceof ErrorValue) { $this->_errors = $value->toDict(); } else { $this->_errors = array(); } $this->_empty = $_empty; }
public function __construct($function, $unwrap_args = true, $args = null, $arity = null, $reify_exceptions = null, $origin = null) { if ($origin === null) { if (is_string($function)) { $origin = $function; } else { $origin = V::ANONYMUS_FUNCTION_ORIGIN; } } parent::__construct($origin); if (is_string($function)) { C::guardIsCallable($function); } else { C::guardIsClosure($function); } C::guardIsBool($unwrap_args); $args = self::defaultTo($args, array()); $reify_exceptions = self::defaultTo($reify_exceptions, array()); C::guardIsArray($args); C::guardIfNotNull($arity, "guardIsUInt"); C::guardIsArray($reify_exceptions); foreach ($args as $key => $value) { $args[$key] = $this->toValue($value, null); } if ($arity === null) { $refl = new ReflectionFunction($function); $this->_arity = $refl->getNumberOfParameters() - count($args); } else { $this->_arity = $arity - count($args); } if ($this->_arity < 0) { throw new Exception("FunctionValue::__construct: more args then parameters."); } $this->_function = $function; $this->_unwrap_args = $unwrap_args; $this->_args = $args; $this->_reify_exceptions = $reify_exceptions; }
public static function checkbox($default = false, $attributes = null) { C::guardIsBool($default); return self::input("checkbox", $attributes)->wrapCollector(V::fn(function ($collector, $inp) { // We don't really need the value, we just // have to check weather it is there. try { $collector->collect($inp); return true; } catch (MissingInputError $e) { return false; } }))->mapHTML(V::fn(function ($dict, $html) use($default) { $name = $html->attribute("name"); if ($dict->isEmpty()) { $value = $default; } else { $value = $dict->value($name) !== null; } if ($value) { return $html->attribute("checked", "checked"); } return $html; })); }