예제 #1
0
 public function &_set_map(h\collection $pairs)
 {
     if ($pairs->keys()->unique()->count() !== $pairs->values->count()) {
         throw $this->_exception_invalid_map();
     }
     $this->_map = $pairs;
 }
예제 #2
0
function create_native()
{
    //
    $native = new request();
    $native->head['host'] = new h\uri\host();
    // XXX Assume we have a hostname
    $native->head['host']->set_impl(new h\inet\host());
    $native->head['host']->segments = h\string($_SERVER['HTTP_HOST'])->explode(h\string('.'));
    $native->head['cookie'] = h\collection::merge($_COOKIE);
    $native->method = validate_http_method($_SERVER['REQUEST_METHOD']);
    $native->uri = new h\http\request_uri();
    $request_uri = h\string($_SERVER['REQUEST_URI']);
    if (false !== $request_uri->search('?')) {
        list($path, ) = $request_uri->explode(h\string('?'));
    }
    $native->uri->path = new h\uri\absolute_path();
    $native->uri->path->segments = $path->explode(h\string('/'));
    $native->uri->search = new h\uri\query();
    foreach ($_GET as $name => $value) {
        $native->uri->search[$name] = $value;
    }
    $native->version = h\string($_SERVER['SERVER_PROTOCOL']);
    $native->body = new body();
    if (PUT === $native->method) {
        $put_data = file_get_contents('php://input');
        $put_data = urldecode($put_data);
        parse_str($put_data, $put_data);
        $put_data = h\collection::merge($put_data);
        $native->body->content = $put_data;
    } elseif (POST === $native->method) {
        $native->body->content = h\collection::merge($_POST, $_FILES);
    }
    return $native;
}
예제 #3
0
 private function render_template_recursive(h\collection $parser_stack, $context = array())
 {
     $output = array();
     while (0 < $parser_stack->count()) {
         $sub_parser_stack = null;
         $element = $parser_stack->shift();
         if ($element instanceof tag\raw) {
             $output[] = $element->content;
         } elseif ($element instanceof tag\variable) {
             $variable_name = $element->name;
             if (isset($context->{$variable_name})) {
                 $variable = $context->{$variable_name};
                 $output[] = $this->escaper->do_escape($variable);
             }
         } elseif ($element instanceof tag\section) {
             $variable_name = $element->name;
             $sub_parser_stack = $this->render_extract_section($parser_stack, $variable_name);
             if (isset($context->{$variable_name}) && $context->{$variable_name}) {
                 $variable = $context->{$variable_name};
                 if (is_object($variable)) {
                     $output[] = $this->render_template_recursive($sub_parser_stack, $variable);
                 } elseif (is_array($variable)) {
                     foreach ($variable as $var) {
                         $output[] = $this->render_template($sub_parser_stack, $var);
                     }
                 } else {
                     $output[] = $this->render_template_recursive($sub_parser_stack, $variable);
                 }
             }
         } elseif ($element instanceof tag\inverted) {
             $variable_name = $element->name;
             $sub_parser_stack = $this->render_extract_section($parser_stack, $variable_name);
             if (!isset($context->{$variable_name}) || !$context->{$variable_name}) {
                 $output[] = $this->render_template_recursive($sub_parser_stack);
             }
         } elseif ($element instanceof tag\unescaped) {
             $variable_name = $element->name;
             if (isset($context->{$variable_name})) {
                 $variable = $context->{$variable_name};
                 $output[] = (string) $variable;
             }
         } elseif ($element instanceof tag\close) {
             //break;
         }
     }
     return implode('', $output);
 }
예제 #4
0
 public function __construct(composed_configuration $composed)
 {
     $this->_composed = $composed;
     $values = clone $composed->payload;
     while ($composed->has_next()) {
         $composed = $composed->next;
         $values->join($composed->payload);
     }
     parent::__construct();
     $this->join($values);
 }
예제 #5
0
 public function in(h\collection $list)
 {
     $this->stack[] = ' in ';
     $this->stack[] = '(' . $list->implode(', ') . ')';
     return $this;
 }