protected function do_before(context $ctx) { $ctx->template = new $this->configuration['template']['engine']($this->configuration['template']); $ctx->template_name = h\string($this->configuration['template']['name']); $ctx->template_action = h\string($this->configuration['template']['action']); return true; }
public function a($text) { if (!$text instanceof h\string) { $text = h\string($text); } return $this->escapers['attribute']->do_escape($text); }
public static function create_native() { $u = new self(); $u->ip = h\string($_SERVER['REMOTE_ADDR']); $u->cookie = h\collection($_COOKIE); return $u; }
protected function _set_title(h\string $text) { $c = $this->create_element(h\string('channel'), h\c(array('rdf:about' => '/'))); $t = $this->create_element(h\string('title'), h\c(array($text))); $c->appendChild($t); return $this->root->appendChild($c); }
public function _to_string() { $s = $this->_path->_to_string(); if ($this->_query->count()) { $s->append(h\string('?'))->append($this->_query->_to_string()); } return $s; }
public function __construct(h\string $pattern, h\string $delimiter = null) { $this->_delimiter = is_null($delimiter) ? h\string(static::default_delemeter) : $delimiter; $this->_pattern = new h\string(); parent::__construct(); $this->_pattern = $pattern; $this->escaper = new escaper(h\string($pattern->charset)); }
public function __construct($name) { $this->_providers = new h\collection(); $this->_cases = new h\collection(); $this->_name = h\string($name); parent::__construct(); $this->run(); }
public function do_escape(h\string $subject) { $escaped = strtr($subject, $this->_map); if (false === $escaped) { throw $this->_exception_invalid_map(); } $escaped = h\string($escaped); return $escaped; }
public function _to_string() { $string = $this->path->_to_string(); if ($this->search->count()) { $string->append(h\string('?')); $string->append($this->search->_to_string()); } return $string; }
public function do_feed(h\string $meat) { $uri = new url(); $uri->scheme = h\string($this->secured ? 'https' : 'http'); $uri->hierarchical_part = $this->master->factories['hierarchical_part']->do_feed($meat); // XXX check authority is present and throw an error if not $uri->query = $this->master->factories['query']->do_feed($meat); $uri->fragment = $this->master->factories['fragment']->do_feed($meat); return $uri; }
protected function _test_create_uri() { $messages = array('URL'); $expected_exception = null; $u = $this->target; $callback = function () use($u) { return h\string('a')->is_equal(h\string($u->scheme)) && 'a:b' === (string) $u; }; $this->add_test($callback, $messages, $expected_exception); }
function process($template, $context) { if (!$template instanceof h\string) { $template = h\string($template); } $parser = new parser(); $escaper = new html_escaper(h\string('UTF-8')); $processor = new processor($parser, $escaper); return $processor->do_process($template, $context); }
function create_generic() { $factory = new h\uri\factory(); $factory->do_register_factory(h\string('scheme'), new h\uri\scheme_factory($factory)); $factory->do_register_factory(h\string('http'), new h\http\uri_factory($factory)); $factory->do_register_factory(h\string('host'), new h\uri\host_factory($factory)); $factory->do_register_factory(h\string('port'), new h\uri\port_factory($factory)); $factory->do_register_factory(h\string('relative_path'), new h\uri\path_factory($factory)); $factory->do_register_factory(h\string('absolute_path'), new h\uri\path_factory($factory)); return $factory; }
public function do_control() { $path = h\string($this->app->request->uri->path); $legacy = $this->model->get_by_legacy_path($path); if (!$legacy instanceof story) { header('HTTP/1.1 404 Document not found'); return array(false); } $this->context->router->redirect_to($this->uri_to($legacy)); return array(true); }
protected function _test_create_http_uri() { $messages = array('HTTP URL'); $expected_exception = null; $literal = h\string($this->target); $factory = $this->factory; $callback = function () use($literal, $factory) { $url = $factory->create($literal); return $url->scheme->is_equal(h\string('http')) && h\string($url)->is_equal($literal); }; $this->add_test($callback, $messages, $expected_exception); }
protected function _test_match_capture() { $messages = array('Regex capture'); $expected_exception = null; foreach (array(array('^(?:(\\w+)\\s?)*$', 'Bonjour le monde', true, 1, 'monde')) as $target) { $callback = function () use($target) { list($re, $subject, $expected_matching, $expected_capture_index, $expected_capture) = $target; $re = h\regex($re); $subject = h\string($subject); $result = $re->do_execute($subject); return $expected_matching === $result->is_match() && $result->has_captured(0) && $result->has_captured($expected_capture_index) && $subject == $subject->slice($result->iterate_matches()[0]->begin, $result->iterate_matches()[0]->end) && $expected_capture == $subject->slice($result->iterate_captures_by_index($expected_capture_index)[0]->begin, $result->iterate_captures_by_index($expected_capture_index)[0]->end); }; $this->add_test($callback, $messages, $expected_exception); } }
protected function _test_escape() { $messages = array('Tests escape character in a string'); $e = $this->target; $callback = function () use($e) { $s = h\string('\\$'); $es = $e->do_escape($s); return h\string('\\\\$')->is_equal($es); }; $this->add_test($callback, $messages); $messages = array('Tests unescape character in a string'); $e = $this->target; $callback = function () use($e) { $s = h\string('\\\\$'); $ues = $e->do_unescape($s); return h\string('\\$')->is_equal($ues); }; $this->add_test($callback, $messages); }
public function do_feed(h\string $meat) { if ($meat->length() < 1) { return null; } if (h\string(':')->is_equal($meat[0])) { $meat->behead(1); } else { return null; } for ($end_port = 0; \is_numeric((string) $meat[$end_port]); ++$end_port) { /* */ } $port = $meat->behead($end_port); $port = $port->as_integer(); if (1 > $port || $port > 65535) { throw $this->_exception_format('Specified port \'%d\' is incorrect', $port); } return $port; }
public function __construct() { $this->_name = h\string(''); $this->_sources = h\collection(); parent::__construct(); }
public static function create() { $template = h\string('<!DOCTYPE html><html><head><title><body>'); return self::new_from_string($template); }
public function uri_of_parent() { return h\string('/'); }
protected function _test_create_http_uri_example_com_here_params() { $messages = array('Path with //example.com/here?first=one'); $expected_exception = null; $callback = function () { $wrapper = new h\uri\path(); $wrapper->set_impl(new h\uri\hierarchical_part()); $wrapper->path->set_impl(new h\uri\net_path()); $wrapper->authority->host->set_impl(new h\inet\host()); $wrapper->authority->host->segments[] = 'example'; $wrapper->authority->host->segments[] = 'com'; $wrapper->path->path->set_impl(new h\uri\absolute_path()); $wrapper->path->path->segments[] = 'here'; $wrapper->query['first'] = 'one'; return h\string('//example.com/here?first=one')->is_equal($wrapper->_to_string()); }; $this->add_test($callback, $messages, $expected_exception); }
public static function create($name, $email, $created, $modified) { $new = new static(); $new->name = h\string($name); $new->email = h\string($email); $new->created = h\date::new_from_sql($created); // XXX or null $new->modified = h\date::new_from_sql($modified); // XXX or null return $new; }
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; }
public function escape_json(h\string $sql, $is_nullable = false) { if (h\string('null')->is_equal($sql)) { if (false === $is_nullable) { throw $this->_exception('Value is not nullable'); } else { $escaped = h\string('null'); } } else { $escaped = h\string::format('\'%s\'', $this->_con->real_escape_string(json_encode($sql->scalar))); } return $escaped; }
public function itemise(accounts $accounts, $mode) { if ($mode->is_equal(h\string('add'))) { $this->entry_add(new account()); } $canvas = $this->canvas; $od = $canvas->ownerDocument; $ul = $canvas->appendChild($od->createElement('ul')); $li = $ul->appendChild($od->createElement('li')); $a = $li->appendChild($od->createElement('a', 'Add')); $a->setAttribute('href', '?add'); $ul = $canvas->appendChild($od->createElement('ul')); foreach ($accounts as $account) { $li = $ul->appendChild($od->createElement('li')); $a = $li->appendChild($od->createElement('a', $account->name)); $a->setAttribute('href', $this->link($account)); $li->appendChild($od->createEntityReference('nbsp')); $a = $li->appendChild($this->action_node($account, 'edit')); $li->appendChild($od->createEntityReference('nbsp')); $a = $li->appendChild($this->action_node($account, 'delete')); } return $ul; }
public function create_nbsp() { return $this->create_entity_reference(h\string('nbsp')); }
public function r($resource, $action, $type, $context) { foreach (array('resource', 'action', 'type') as $var) { ${$var} instanceof h\string or ${$var} = h\string(${$var}); } $template_file = $this->template_for($resource, $action, $type); return $this->do_render($template_file, $context); }
public function do_create_net_path(h\string $meat) { $impl = new net_path(); $slashes = $meat->behead(2); if (!h\string('//')->is_equal($slashes)) { throw $this->_exception('Not a net path'); } $impl->authority->assign($this->master->factories['authority']->do_feed($meat)); if (0 === $meat->search(h\string('/'))) { $impl->path = $this->do_feed($meat); } else { $impl->path->set_impl(new empty_path()); } return $impl; }
function regex_find($pattern, $haystack) { $re = regex($pattern); $haystack = h\string($haystack); return $re->find($haystack); }