Пример #1
0
 public function get_by_email(h\string $email)
 {
     $sql = h\string::format('select * from accounts where email = %s', $this->source->escape($email));
     $rows = $this->source->query($sql);
     $accounts = $this->accounts_from_select($rows);
     return isset($accounts[0]) ? $accounts[0] : null;
 }
Пример #2
0
 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;
 }
Пример #3
0
 public function _to_string()
 {
     $authority = $this->_host->_to_string();
     is_null($this->port) or $authority->append(h\string::format(':%d', $this->port));
     if (0 < $this->password->length()) {
         if (0 < $this->user->length()) {
             $authority->prepend(h\string::format('%s:%s@', $this->user, $this->password));
         } else {
             throw $this->_exception('Malformed authority: password but no username');
         }
     } elseif (0 < $this->user->length()) {
         $authority->prepend(h\string::format('%s@', $this->user));
     }
     return $authority;
 }
Пример #4
0
 public function get_by_legacy_path(h\string $legacy_path)
 {
     $db = $this->model->services->get('db');
     $sql = h\string::format('select * from stories s right join legacy_stories ls' . '	on s.id = ls.story_id where path = %s', $db->escape($legacy_path));
     $rows = $db->query($sql);
     $stories = $this->create_stories_from_select($rows);
     return isset($stories[0]) ? $stories[0] : null;
 }
Пример #5
0
 protected function &_get_pattern()
 {
     $pattern = h\string::format("%1\$s%2\$s%1\$s", $this->delimiter, $this->_pattern);
     return $pattern;
 }
Пример #6
0
 public function _to_string()
 {
     $literal = h\string::format('%s:%s', $this->scheme, $this->scheme_specific_part);
     return $literal;
 }
Пример #7
0
 public function uri_of($story)
 {
     $uri = h\string::format('/stories/%s', rawurlencode($story->title));
     return $uri;
 }
Пример #8
0
function validate_http_method($candidate)
{
    static $methods = array('POST' => POST, 'GET' => GET, 'PUT' => PUT, 'DELETE' => DELETE, 'OPTIONS' => OPTIONS);
    if (isset($methods[strtoupper($candidate)])) {
        return $methods[strtoupper($candidate)];
    }
    throw new h\exception(h\string::format('Method verb \'%s\' is not supported', $candidate));
}
Пример #9
0
 public function uri_of($account)
 {
     $uri = h\string::format('/accounts/%s', rawurlencode($account->name));
     return $uri;
 }
Пример #10
0
 public function do_render(h\string $name, $c)
 {
     $e = $this->escaper;
     include h\string::format('%s/%s.php', $this->path, $name);
 }
Пример #11
0
 private function do_deduce_content_type(context $ctx)
 {
     $ctx->out->head['Content-type'] = h\string::format('%s; charset=%s', $this->configuration['content_type']['mime_type'], $this->configuration['content_type']['encoding']);
 }
Пример #12
0
 private function do_populate_head(context $ctx)
 {
     $cors_headers = h\c(array('Access-Control-Allow-Credentials' => 'true', 'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE', 'Access-Control-Allow-Headers' => 'Content-Type', 'Access-Control-Allow-Origin' => h\string::format('https://%s', $this->configuration['front_base_url'])));
     $ctx->out->head->join($cors_headers);
 }
Пример #13
0
 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;
 }
Пример #14
0
 private function location($uri)
 {
     $to = new h\http\url(h\string::format('%s://%s%s', 'http', 'blog.localhost', $uri));
     h\http\response_methods::location($this->context->out, $to);
 }