예제 #1
0
 public function buildWithDict(RenderDict $dict)
 {
     $base = $this->_builder->buildWithDict($dict);
     $res = $this->_transformation->apply(V::val($dict))->apply(V::val($base))->get();
     C::guardIsHTML($res);
     return $res;
 }
예제 #2
0
 public function __construct(Formlet $formlet, FunctionValue $transform_builder, FunctionValue $transform_collector)
 {
     C::guardHasArity($transform_builder, 1);
     C::guardHasArity($transform_collector, 1);
     $this->_formlet = $formlet;
     $this->_transform_builder = $transform_builder;
     $this->_transform_collector = $transform_collector;
 }
예제 #3
0
 public function __construct($tag_name, TagBuilderCallbacks $callback_object, $name = null)
 {
     C::guardIsString($tag_name);
     C::guardIfNotNull($name, "guardIsString");
     $this->_tag_name = $tag_name;
     $this->_callback_object = $callback_object;
     $this->_name = $name;
 }
예제 #4
0
 public function content($content = 0)
 {
     if ($content === 0) {
         return $this->_content;
     }
     C::guardIfNotNull($content, "guardIsHTML");
     $this->_content = $content;
     return $this;
 }
예제 #5
0
 public function __construct(Collector $collector, FunctionValue $wrapper)
 {
     C::guardHasArity($wrapper, 2);
     if ($collector->isNullaryCollector()) {
         throw new Exception("It makes no sense to wrap around a nullary collector.");
     }
     $this->_collector = $collector;
     $this->_wrapper = $wrapper;
 }
예제 #6
0
 public function __construct($reason, $origin, $others = array())
 {
     C::guardIsString($reason);
     C::guardEach($others, "guardIsErrorValue");
     $this->_reason = $reason;
     $this->_others = $others;
     $this->_dict = null;
     parent::__construct($origin);
 }
예제 #7
0
 public final function satisfies(FunctionValue $predicate, $error)
 {
     C::guardIsString($error);
     C::guardHasArity($predicate, 1);
     return $this->map(V::fn_w(function ($value) use($predicate, $error) {
         if (!$predicate->apply($value)->get()) {
             return V::error($error, $value->origin());
         }
         return $value;
     }));
 }
예제 #8
0
 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;
 }
예제 #9
0
 public static function keysAndValuesToHTMLAttributes($attributes)
 {
     $str = "";
     foreach ($attributes as $key => $value) {
         C::guardIsString($key);
         if ($value !== null) {
             C::guardIsString($value);
         }
         $value = str_replace('"', '"', $value);
         $str .= " " . $key . ($value !== null ? "=\"{$value}\"" : "");
     }
     return $str;
 }
예제 #10
0
 public function __construct($id, $action, $attrs, IFormlet $formlet)
 {
     if (!preg_match("#[a-zA-Z][a-zA-Z0-9_]+#", $id)) {
         throw new Exception("Form::__construct: '{$id}' can not be used as " . "id. Only use numbers and digits.");
     }
     C::guardIsFormlet($formlet);
     C::guardIsString($id);
     C::guardIsString($action);
     $attrs = Value::defaultTo($attrs, array());
     C::guardEachAndKeys($attrs, "C::guardIsString", "C::guardIsString");
     $this->_id = $id;
     $this->_input = null;
     $this->_result = null;
     $attrs["method"] = "post";
     $attrs["action"] = $action;
     $formlet = $formlet->mapHTML(V::fn(function ($dict, $html) use($attrs) {
         return H::tag("form", $attrs, $html);
     }));
     $name_source = NameSource::instantiate($this->_id);
     $repr = $formlet->instantiate($name_source);
     $this->_builder = $repr["builder"];
     $this->_collector = $repr["collector"];
 }
예제 #11
0
 public function __construct($content)
 {
     C::guardEach($content, "guardIsHTML");
     $this->_content = $content;
 }
예제 #12
0
 public function __construct($name)
 {
     C::guardIsString($name);
     $this->_name = $name;
 }
예제 #13
0
 public function catchAndReify($exc_class)
 {
     C::guardIsString($exc_class);
     $re = $this->_reify_exceptions;
     $re[] = $exc_class;
     return new FunctionValue($this->_function, $this->_unwrap_args, $this->_args, $this->_arity + count($this->_args), $re, $this->origin());
 }
예제 #14
0
 public function __construct($text)
 {
     C::guardIsString($text);
     $this->_text = $text;
 }
예제 #15
0
 public function __construct($content)
 {
     C::guardIsString($content);
     $this->_content = $content;
 }
예제 #16
0
 public function __construct($attributes)
 {
     C::guardEachAndKeys($attributes, "guardIsString", "guardIsString");
     $this->_attributes = $attributes;
 }
예제 #17
0
 public static function select($options, $default = null, $attributes = array())
 {
     C::guardEach($options, "guardIsString");
     return self::input("select", $attributes)->mapHTML(V::fn(function ($dict, $html) use($options, $attributes, $default) {
         $name = $html->attribute("name");
         $value = $dict->value($name);
         if ($value === null) {
             $value == $default;
         }
         $attributes["name"] = $name;
         $options_html = array_map(function ($option) use($value) {
             if ($option !== $value) {
                 return H::tag("option", array(), H::text($option));
             } else {
                 return H::tag("option", array("selected" => "selected"), H::text($option));
             }
         }, $options);
         return H::tag("select", $attributes, H::harray($options_html));
     }))->satisfies(V::fn(function ($value) use($options) {
         return in_array($value, $options);
     }), "Option not available.");
 }
예제 #18
0
 public function __construct($origin)
 {
     C::guardIfNotNull($origin, "guardIsString");
     $this->_origin = $origin;
 }