/
URI.class.php
75 lines (74 loc) · 5.43 KB
/
URI.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
class sinatra_URI {
public function __construct($ereg, $absolute) {
if( !php_Boot::$skip_constructor ) {
$this->isAbsolute = $absolute;
if($this->isAbsolute) {
$this->schema = $ereg->matched(1);
$this->opaque = $ereg->matched(2);
$this->userinfo = $ereg->matched(3);
$this->host = $ereg->matched(4);
$this->port = $ereg->matched(5);
$this->registry = $ereg->matched(6);
$this->path = $ereg->matched(7);
$this->query = $ereg->matched(8);
$this->fragment = $ereg->matched(9);
}
else {
$this->userinfo = $ereg->matched(1);
$this->host = $ereg->matched(2);
$this->port = $ereg->matched(3);
$this->registry = $ereg->matched(4);
$this->segment = $ereg->matched(5);
$this->path = $ereg->matched(6);
$this->query = $ereg->matched(7);
$this->fragment = $ereg->matched(8);
}
if($this->port === null && $this->schema !== null) {
$this->port = Reflect::field(sinatra_URI::$SCHEMA_DEFAULT_PORT, $this->schema);
}
}}
public $schema;
public $opaque;
public $userinfo;
public $user;
public $pass;
public $host;
public $port;
public $registry;
public $segment;
public $path;
public $query;
public $fragment;
public $isAbsolute;
public function __call($m, $a) {
if(isset($this->$m) && is_callable($this->$m))
return call_user_func_array($this->$m, $a);
else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m]))
return call_user_func_array($this->»dynamics[$m], $a);
else
throw new HException('Unable to call «'.$m.'»');
}
static $SCHEMA_DEFAULT_PORT;
static $PATTERN_ABS_URI = "\x0A\x09 ([a-zA-Z][-+.a-zA-Z\\d]*):\x0A\x09 (?:\x0A\x09 ((?:[-_.!~*'()a-zA-Z\\d;?:@&=+\$,]|%[a-fA-F\\d]{2})(?:[-_.!~*'()a-zA-Z\\d;/?:@&=+\$,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))?\x0A\x09 ";
static $PATTERN_REMOVE_WHITESPACE;
static function parse($str) {
haxe_Log::trace("Parsing URI from: " . $str, _hx_anonymous(array("fileName" => "URI.hx", "lineNumber" => 131, "className" => "sinatra.URI", "methodName" => "parse")));
$abs = new EReg(sinatra_URI::$PATTERN_REMOVE_WHITESPACE->replace(sinatra_URI::$PATTERN_ABS_URI, ""), "");
if($abs->match($str)) {
haxe_Log::trace("IT'S AN ABSOLUTE URI!", _hx_anonymous(array("fileName" => "URI.hx", "lineNumber" => 135, "className" => "sinatra.URI", "methodName" => "parse")));
return new sinatra_URI($abs, true);
}
$rel = new EReg(sinatra_URI::$PATTERN_REMOVE_WHITESPACE->replace(sinatra_URI::$PATTERN_REL_URI, ""), "");
if($rel->match($str)) {
haxe_Log::trace("IT'S A RELATIVE URI!", _hx_anonymous(array("fileName" => "URI.hx", "lineNumber" => 141, "className" => "sinatra.URI", "methodName" => "parse")));
return new sinatra_URI($rel, false);
}
haxe_Log::trace("Invalid URI", _hx_anonymous(array("fileName" => "URI.hx", "lineNumber" => 145, "className" => "sinatra.URI", "methodName" => "parse")));
return null;
}
function __toString() { return 'sinatra.URI'; }
}
sinatra_URI::$SCHEMA_DEFAULT_PORT = _hx_anonymous(array("http" => 80, "https" => 443, "ftp" => 21, "ssh" => 22));
sinatra_URI::$PATTERN_REMOVE_WHITESPACE = new EReg("\\s*|\\n", "g");