private function do_routing(context $ctx) { $path = $ctx->in->uri->path->_to_string(); $routes = $this->configuration['routes']; $ctrl = null; $matches = array(); $segments = h\collection(); foreach ($routes as $route_pattern => $route_ctrl) { $results = h\regex_execute("^{$route_pattern}\$", $path); if ($results->is_match()) { $ctrl = $route_ctrl; $route = $route_pattern; $match = $results->iterate_records()[0]; foreach ($match as $key => $pair) { if (is_string($key)) { $segments[$key] = \rawurldecode($path->slice($pair->begin, $pair->end)); } } break; } } $ctx->segments = $segments; $http_method = $ctx->in->method; if (is_null($ctrl)) { $ctx->out->status = 'HTTP/1.1 405 Method Not Allowed'; $tpl = 'Non-supported method \'%s\' on \'%s\''; $msg = h\string::format($tpl, $http_method, $path); $ctx->error_handling['status'] = false; $ctx->error_handling['messages'][] = $msg; return false; } $ctx->route = $route; return true; }
public static function create_native() { $u = new self(); $u->ip = h\string($_SERVER['REMOTE_ADDR']); $u->cookie = h\collection($_COOKIE); return $u; }
public function __construct(h\collection $fields = null) { $this->_fields = h\collection(); $this->_criteria = h\collection(); parent::__construct(); $this->fields = $fields; }
public function _to_string() { $collection = h\collection(); foreach ($this as $name => $value) { $collection[] = rawurlencode($name) . '=' . rawurlencode($value); } return $collection->implode('&'); }
protected function _test_select_from_where() { $select = $this->_test_select_from(); $this->_assert_equals('select * from pictures', (string) $select); $where = $select->where('id'); $this->_assert_equals('select * from pictures where id', (string) $where); $where_equals = $where->equals(10); $this->_assert_equals('select * from pictures where id=10', (string) $where_equals); $where_in = $select->where('id')->in(h\collection(1, 2)); $this->_assert_equals('select * from pictures where id in (1, 2)', (string) $where_in); }
private function render_extract_section(h\collection $parser_stack, h\string $section_name) { $depth = 1; $sub_parser_stack = h\collection(); do { $element = $parser_stack->shift(); $sub_parser_stack[] = $element; if ($element instanceof tag\section || $element instanceof tag\inverted) { $element->name->is_equal($section_name) and ++$depth; } elseif ($element instanceof tag\close) { $element->name->is_equal($section_name) and --$depth; if (0 === $depth) { break; } } } while (!is_null($element)); return $sub_parser_stack; }
protected function do_before(context $ctx) { $ctx->results = h\collection(); $interfaces = array('GET' => '\\horn\\lib\\http_get', 'POST' => '\\horn\\lib\\http_post', 'PUT' => '\\horn\\lib\\http_put', 'DELETE' => '\\horn\\lib\\http_delete'); $http_method = $ctx->in->method; if (!isset($interfaces[$http_method])) { h\http\response_methods::method_not_allowed($ctx->out); $msg = sprintf('Non-supported method \'%s\' on \'%s\'', $http_method, $ctx->in->uri); $ctx->error_handling['status'] = false; $ctx->error_handling['messages'][] = $msg; return false; } $controller_class = $this->configuration['routes'][$ctx->route]; if (!class_exists($controller_class)) { $msg = sprintf('Undefined controller class \'%s\'', $controller_class); $ctx->error_handling['status'] = false; $ctx->error_handling['messages'][] = $msg; return false; } $ctrl = new $controller_class($ctx); if (!$ctrl instanceof $interfaces[$http_method]) { h\http\response_methods::method_not_allowed($ctx->out); $msg = sprintf('Non-supported method \'%s\' on \'%s\'', $http_method, $ctx->in->uri); $ctx->error_handling['status'] = false; $ctx->error_handling['messages'][] = $msg; return false; } try { $result = $ctrl->{"do_{$http_method}"}(); } catch (h\http\error $e) { $error = get_class($e); $error = substr($error, 1 + strrpos($error, '\\')); h\http\response_methods::$error($ctx->out); $result = array(false, null, array($e->getMessage())); } $ctx->error_handling['status'] = $result[0]; isset($result[1]) and $ctx->results->join($result[1]); isset($result[2]) and $ctx->error_handling['messages']->join($result[2]); return true; }
protected function do_before(context $ctx) { $ctx->error_handling = h\c(array('status' => true, 'messages' => h\collection())); ob_start(); }
public function __construct() { $this->_segments = h\collection(); parent::__construct(); }
public function select() { $fields = func_get_args(); $fields = !func_num_args() ? h\collection() : h\collection($fields); return new select($fields); }
public function query(h\string $sql) { $result = $this->_con->query($sql); if ($result === false) { throw $this->_exception_query_error(); } if (is_array($result)) { $return = h\collection(); while ($row = $result->fetch_assoc()) { $return->push($row); } } else { $return = $result; } return $return; }
public function __construct(h\string $charset) { $this->_map = h\collection(); parent::__construct($charset); }
public function __construct($operand) { $this->_stack = h\collection(); parent::__construct(); $this->stack[] = $operand; }
public function do_parse(h\string $template) { $begin = 0; $end = 0; $opening_delimiter = self::OPENING_DELIMITER; $closing_delimiter = self::CLOSING_DELIMITER; $parser_stack = h\collection(); $parser_stack[] = new tag\begin(); do { // Open tag //////////////////////////////////////////////////////////////////// $end = $template->search($opening_delimiter, $begin); if (-1 === $end) { $end = $template->length(); } $element = new tag\raw(); $element->content = $template->slice($begin, $end); $parser_stack[] = $element; $begin = $end; if ($template->length() === $begin) { break; } // Close tag /////////////////////////////////////////////////////////////////// $begin += strlen($opening_delimiter); $end = $template->search($closing_delimiter, $begin); $first = $template[$begin]; ++$begin; if ($first->is_equal(h\string('#'))) { $element = new tag\section(); $element->name = $template->slice($begin, $end); $parser_stack[] = $element; } elseif ($first->is_equal(h\string('^'))) { $element = new tag\inverted(); $element->name = $template->slice($begin, $end); $parser_stack[] = $element; } elseif ($first->is_equal(h\string('/'))) { $element = new tag\close(); $element->name = $template->slice($begin, $end); $parser_stack[] = $element; } elseif ($first->is_equal(h\string('!'))) { $element = new tag\comment(); $element->content = $template->slice($begin, $end); $parser_stack[] = $element; } elseif ($first->is_equal(h\string('{'))) { if ('}' !== $template[++$end]) { throw 'Ill-formed'; } $element = new tag\unescaped(); $element->name = $template->slice($begin, $end - 1)->trimmed(); $parser_stack[] = $element; } elseif ($first->is_equal(h\string('&'))) { $element = new tag\unescaped(); $element->name = $template->slice($begin, $end - 1)->trimmed(); $parser_stack[] = $element; } elseif ($first->is_equal(h\string('>'))) { throw 'TODO'; } elseif ($first->is_equal(h\string('='))) { throw 'TODO'; } else { $element = new tag\variable(); $element->name = $template->slice($begin - 1, $end)->trimmed(); $parser_stack[] = $element; } $begin = $end = $end + strlen($closing_delimiter); } while (true); $parser_stack[] = new tag\end(); return $parser_stack; }
private function load_results() { $this->records = h\collection(); foreach ($this->results as $record) { $row = h\collection(); foreach ($record as $index_name => $match) { $pair = new h\pair(); $pair->begin = $match[1]; $pair->end = $pair->begin + strlen($match[0]); $row[$index_name] = $pair; } $this->records[] = $row; } }
public function __construct(h\db\database $db) { $this->_source = $db; $this->cache = h\collection(); parent::__construct(); }
public function cut($offset) { if ($offset === strlen($this->_scalar)) { $tail = new static('', $this->charset); $head = clone $this; } else { $head = new static($this->php_substr(0, $offset), $this->charset); $tail = new static($this->php_substr($offset), $this->charset); } return h\collection($head, $tail); }
public function __construct() { $this->_name = h\string(''); $this->_sources = h\collection(); parent::__construct(); }
protected function do_before(context $ctx) { $ctx->logger = h\collection(); }