Example #1
0
 public function __construct()
 {
     if (!php_Boot::$skip_constructor) {
         $this->method = eval("if(isset(\$this)) \$»this =& \$this;switch(strtoupper(php_Web::getMethod())) {\n\t\t\tcase \"GET\":{\n\t\t\t\t\$»r = sinatra_HTTPMethod::\$GET;\n\t\t\t}break;\n\t\t\tcase \"POST\":{\n\t\t\t\t\$»r = sinatra_HTTPMethod::\$POST;\n\t\t\t}break;\n\t\t\tcase \"PUT\":{\n\t\t\t\t\$»r = sinatra_HTTPMethod::\$PUT;\n\t\t\t}break;\n\t\t\tcase \"DELETE\":{\n\t\t\t\t\$»r = sinatra_HTTPMethod::\$DELETE;\n\t\t\t}break;\n\t\t\tdefault:{\n\t\t\t\t\$»r = eval(\"if(isset(\\\$this)) \\\$»this =& \\\$this;throw new HException(\\\"Invalid HTTP Method\\\");\n\t\t\t\t\treturn \\\$»r2;\n\t\t\t\t\");\n\t\t\t}break;\n\t\t\t}\n\t\t\treturn \$»r;\n\t\t");
         $this->params = php_Web::getParams();
         $this->uri = sinatra_utils_URI::parse(php_Web::getURI());
         $this->path = $this->uri->path;
         $this->headers = new Hash();
         $»it = php_Web::getClientHeaders()->iterator();
         while ($»it->hasNext()) {
             $h = $»it->next();
             $this->headers->set($h->header, $h->value);
         }
     }
 }
Example #2
0
            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 $SCHEME_DEFAULT_PORT;
    static $PATTERN_ABS_URI = "\n\t        ([a-zA-Z][-+.a-zA-Z\\d]*):\n\t        (?:\n\t           ((?:[-_.!~*'()a-zA-Z\\d;?:@&=+\$,]|%[a-fA-F\\d]{2})(?:[-_.!~*'()a-zA-Z\\d;/?:@&=+\$,\\[\\]]|%[a-fA-F\\d]{2})*)\n\t        |\n\t           (?:(?:\n\t             //(?:\n\t                 (?:(?:((?:[-_.!~*'()a-zA-Z\\d;:&=+\$,]|%[a-fA-F\\d]{2})*)@)?\n\t                   (?:((?:(?:(?:[a-zA-Z\\d](?:[-a-zA-Z\\d]*[a-zA-Z\\d])?)\\.)*(?:[a-zA-Z](?:[-a-zA-Z\\d]*[a-zA-Z\\d])?)\\.?|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\[(?:(?:[a-fA-F\\d]{1,4}:)*(?:[a-fA-F\\d]{1,4}|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})|(?:(?:[a-fA-F\\d]{1,4}:)*[a-fA-F\\d]{1,4})?::(?:(?:[a-fA-F\\d]{1,4}:)*(?:[a-fA-F\\d]{1,4}|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}))?)\\]))(?::(\\d*))?))?\n\t               |\n\t                 ((?:[-_.!~*'()a-zA-Z\\d\$,;:@&=+]|%[a-fA-F\\d]{2})+)\n\t               )\n\t             |\n\t             (?!//))\n\t             (/(?:[-_.!~*'()a-zA-Z\\d:@&=+\$,]|%[a-fA-F\\d]{2})*(?:;(?:[-_.!~*'()a-zA-Z\\d:@&=+\$,]|%[a-fA-F\\d]{2})*)*(?:/(?:[-_.!~*'()a-zA-Z\\d:@&=+\$,]|%[a-fA-F\\d]{2})*(?:;(?:[-_.!~*'()a-zA-Z\\d:@&=+\$,]|%[a-fA-F\\d]{2})*)*)*)?\n\t           )(?:\\?((?:[-_.!~*'()a-zA-Z\\d;/?:@&=+\$,\\[\\]]|%[a-fA-F\\d]{2})*))?\n\t        )\n\t        (?:\\#((?:[-_.!~*'()a-zA-Z\\d;/?:@&=+\$,\\[\\]]|%[a-fA-F\\d]{2})*))?\n\t      ";
    static $PATTERN_REL_URI = "\n\t        (?:\n\t          (?:\n\t            //\n\t            (?:\n\t              (?:((?:[-_.!~*'()a-zA-Z\\d;:&=+\$,]|%[a-fA-F\\d]{2})*)@)?\n\t                ((?:(?:(?:[a-zA-Z\\d](?:[-a-zA-Z\\d]*[a-zA-Z\\d])?)\\.)*(?:[a-zA-Z](?:[-a-zA-Z\\d]*[a-zA-Z\\d])?)\\.?|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\[(?:(?:[a-fA-F\\d]{1,4}:)*(?:[a-fA-F\\d]{1,4}|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})|(?:(?:[a-fA-F\\d]{1,4}:)*[a-fA-F\\d]{1,4})?::(?:(?:[a-fA-F\\d]{1,4}:)*(?:[a-fA-F\\d]{1,4}|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}))?)\\]))?(?::(\\d*))?\n\t            |\n\t              ((?:[-_.!~*'()a-zA-Z\\d\$,;:@&=+]|%[a-fA-F\\d]{2})+)\n\t            )\n\t          )\n\t        |\n\t          ((?:[-_.!~*'()a-zA-Z\\d;@&=+\$,]|%[a-fA-F\\d]{2})+)\n\t        )?\n\t        (/(?:[-_.!~*'()a-zA-Z\\d:@&=+\$,]|%[a-fA-F\\d]{2})*(?:;(?:[-_.!~*'()a-zA-Z\\d:@&=+\$,]|%[a-fA-F\\d]{2})*)*(?:/(?:[-_.!~*'()a-zA-Z\\d:@&=+\$,]|%[a-fA-F\\d]{2})*(?:;(?:[-_.!~*'()a-zA-Z\\d:@&=+\$,]|%[a-fA-F\\d]{2})*)*)*)?\n\t        (?:\\?((?:[-_.!~*'()a-zA-Z\\d;/?:@&=+\$,\\[\\]]|%[a-fA-F\\d]{2})*))?\n\t        (?:\\#((?:[-_.!~*'()a-zA-Z\\d;/?:@&=+\$,\\[\\]]|%[a-fA-F\\d]{2})*))?\n\t      ";
    static $PATTERN_REMOVE_WHITESPACE;
    static function parse($str)
    {
        $abs = new EReg("^" . sinatra_utils_URI::$PATTERN_REMOVE_WHITESPACE->replace(sinatra_utils_URI::$PATTERN_ABS_URI, "") . "\$", "");
        if ($abs->match($str)) {
            return new sinatra_utils_URI($abs, true);
        }
        $rel = new EReg("^" . sinatra_utils_URI::$PATTERN_REMOVE_WHITESPACE->replace(sinatra_utils_URI::$PATTERN_REL_URI, "") . "\$", "");
        if ($rel->match($str)) {
            return new sinatra_utils_URI($rel, false);
        }
        throw new HException("Invalid URI");
    }
    function __toString()
    {
        return $this->toString();
    }
}
sinatra_utils_URI::$SCHEME_DEFAULT_PORT = _hx_anonymous(array("http" => 80, "https" => 443, "ftp" => 21, "ssh" => 22));
sinatra_utils_URI::$PATTERN_REMOVE_WHITESPACE = new EReg("\\s*|\\n", "g");