|
<?php |
|
${"GLOBALS"}["crehucyu"] = "key"; |
|
${"GLOBALS"}["dqzqldait"] = "regex"; |
|
${"GLOBALS"}["gvhqawh"] = "position"; |
|
${"GLOBALS"}["difhktogm"] = "pattern"; |
|
${"GLOBALS"}["hrbpetmqjq"] = "method_match"; |
|
${"GLOBALS"}["wfjudmkesp"] = "requestMethod"; |
|
${"GLOBALS"}["smolar"] = "handler"; |
|
${"GLOBALS"}["ielvkwx"] = "lastRequestUrlChar"; |
|
${"GLOBALS"}["kdewwhmr"] = "requestUrl"; |
|
${"GLOBALS"}["cxzyviss"] = "optional"; |
|
${"GLOBALS"}["mnrldqdp"] = "params"; |
|
${"GLOBALS"}["aybmsnriksi"] = "pre"; |
|
${"GLOBALS"}["pkbiifdlr"] = "param"; |
|
${"GLOBALS"}["gmfcfiphuit"] = "type"; |
|
${"GLOBALS"}["rkbovssyxj"] = "block"; |
|
${"GLOBALS"}["svhvtvmtlwn"] = "match"; |
|
${"GLOBALS"}["urjujynpsf"] = "index"; |
|
${"GLOBALS"}["yjeejonjt"] = "matches"; |
|
${"GLOBALS"}["gthrhlcx"] = "url"; |
|
${"GLOBALS"}["nojrmhwb"] = "name"; |
|
${"GLOBALS"}["zhftdvy"] = "target"; |
|
${"GLOBALS"}["rpldswqcvqbr"] = "method"; |
|
${"GLOBALS"}["wpxzqrc"] = "route"; |
|
${"GLOBALS"}["szvaitvyze"] = "routes"; |
|
${"GLOBALS"}["gfwbzwp"] = "matchTypes"; |
|
class AltoRouter |
|
{ |
|
protected $routes = []; |
|
protected $namedRoutes = []; |
|
protected $basePath = ""; |
|
protected $matchTypes = [ |
|
"i" => "[0-9]++", |
|
"a" => "[0-9A-Za-z_-]++", |
|
"h" => "[0-9A-Fa-f]++", |
|
"*" => ".+?", |
|
"**" => ".++", |
|
"" => "[^/\.]++", |
|
]; |
|
public function __construct( |
|
array $routes = [], |
|
$basePath = "", |
|
array $matchTypes = [] |
|
) { |
|
$aeshsxk = "routes"; |
|
$this->addRoutes(${$aeshsxk}); |
|
$ixnkzbpy = "basePath"; |
|
$this->setBasePath(${$ixnkzbpy}); |
|
$this->addMatchTypes(${${"GLOBALS"}["gfwbzwp"]}); |
|
} |
|
public function getRoutes() |
|
{ |
|
return $this->routes; |
|
} |
|
public function addRoutes($routes) |
|
{ |
|
${"GLOBALS"}["yocetiv"] = "routes"; |
|
if ( |
|
!is_array(${${"GLOBALS"}["yocetiv"]}) && |
|
!${${"GLOBALS"}["szvaitvyze"]} instanceof Traversable |
|
) { |
|
throw new RuntimeException( |
|
"Routes should be an array or an instance of Traversable" |
|
); |
|
} |
|
foreach (${${"GLOBALS"}["szvaitvyze"]} as ${${"GLOBALS"}["wpxzqrc"]}) { |
|
${"GLOBALS"}["tattinqtd"] = "route"; |
|
call_user_func_array([$this, "map"], ${${"GLOBALS"}["tattinqtd"]}); |
|
} |
|
} |
|
public function setBasePath($basePath) |
|
{ |
|
${"GLOBALS"}["pgjoeyqybad"] = "basePath"; |
|
$this->basePath = preg_replace( |
|
"/:[0-9]+/", |
|
"", |
|
${${"GLOBALS"}["pgjoeyqybad"]} |
|
); |
|
} |
|
public function addMatchTypes(array $matchTypes) |
|
{ |
|
$this->matchTypes = array_merge( |
|
$this->matchTypes, |
|
${${"GLOBALS"}["gfwbzwp"]} |
|
); |
|
} |
|
public function map($method, $route, $target, $name = null) |
|
{ |
|
${"GLOBALS"}["qvhdvojiy"] = "route"; |
|
$this->routes[] = [ |
|
${${"GLOBALS"}["rpldswqcvqbr"]}, |
|
${${"GLOBALS"}["qvhdvojiy"]}, |
|
${${"GLOBALS"}["zhftdvy"]}, |
|
${${"GLOBALS"}["nojrmhwb"]}, |
|
]; |
|
if (${${"GLOBALS"}["nojrmhwb"]}) { |
|
$qbumnnkueyk = "route"; |
|
$jzreyhq = "name"; |
|
if (isset($this->namedRoutes[${$jzreyhq}])) { |
|
throw new RuntimeException("Can not redeclare route '{$name}'"); |
|
} |
|
$this->namedRoutes[${${"GLOBALS"}["nojrmhwb"]}] = ${$qbumnnkueyk}; |
|
} |
|
return; |
|
} |
|
public function generate($routeName, array $params = []) |
|
{ |
|
$fnscdnduwk = "routeName"; |
|
${"GLOBALS"}["bujzpeco"] = "url"; |
|
${"GLOBALS"}["tcjruuybso"] = "routeName"; |
|
$eqfkcrtv = "route"; |
|
${"GLOBALS"}["jnhjaicvngc"] = "matches"; |
|
if (!isset($this->namedRoutes[${${"GLOBALS"}["tcjruuybso"]}])) { |
|
throw new RuntimeException("Route '{$routeName}' does not exist."); |
|
} |
|
${$eqfkcrtv} = $this->namedRoutes[${$fnscdnduwk}]; |
|
${${"GLOBALS"}["gthrhlcx"]} = |
|
$this->basePath . ${${"GLOBALS"}["wpxzqrc"]}; |
|
if ( |
|
preg_match_all( |
|
"`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`", |
|
${${"GLOBALS"}["wpxzqrc"]}, |
|
${${"GLOBALS"}["jnhjaicvngc"]}, |
|
PREG_SET_ORDER |
|
) |
|
) { |
|
foreach ( |
|
${${"GLOBALS"}["yjeejonjt"]} |
|
as ${${"GLOBALS"}["urjujynpsf"]} => |
|
${${"GLOBALS"}["svhvtvmtlwn"]} |
|
) { |
|
$yyauppok = "match"; |
|
$ktxybex = "optional"; |
|
${"GLOBALS"}["ctkwof"] = "index"; |
|
${"GLOBALS"}["tqsajzxwkg"] = "pre"; |
|
list( |
|
${${"GLOBALS"}["rkbovssyxj"]}, |
|
${${"GLOBALS"}["tqsajzxwkg"]}, |
|
${${"GLOBALS"}["gmfcfiphuit"]}, |
|
${${"GLOBALS"}["pkbiifdlr"]}, |
|
${$ktxybex}, |
|
) = ${$yyauppok}; |
|
if (${${"GLOBALS"}["aybmsnriksi"]}) { |
|
${"GLOBALS"}["otbxhuyrjv"] = "block"; |
|
${${"GLOBALS"}["otbxhuyrjv"]} = substr( |
|
${${"GLOBALS"}["rkbovssyxj"]}, |
|
1 |
|
); |
|
} |
|
if ( |
|
isset( |
|
${${"GLOBALS"}["mnrldqdp"]}[ |
|
${${"GLOBALS"}["pkbiifdlr"]} |
|
] |
|
) |
|
) { |
|
${"GLOBALS"}["qckmbbjh"] = "url"; |
|
${${"GLOBALS"}["qckmbbjh"]} = str_replace( |
|
${${"GLOBALS"}["rkbovssyxj"]}, |
|
${${"GLOBALS"}["mnrldqdp"]}[ |
|
${${"GLOBALS"}["pkbiifdlr"]} |
|
], |
|
${${"GLOBALS"}["gthrhlcx"]} |
|
); |
|
} elseif ( |
|
${${"GLOBALS"}["cxzyviss"]} && |
|
${${"GLOBALS"}["ctkwof"]} !== 0 |
|
) { |
|
${"GLOBALS"}["okcitn"] = "url"; |
|
${"GLOBALS"}["szuexkygie"] = "url"; |
|
$wnopkjz = "pre"; |
|
${${"GLOBALS"}["okcitn"]} = str_replace( |
|
${$wnopkjz} . ${${"GLOBALS"}["rkbovssyxj"]}, |
|
"", |
|
${${"GLOBALS"}["szuexkygie"]} |
|
); |
|
} else { |
|
${"GLOBALS"}["rdkgmflvrbgf"] = "block"; |
|
$ihbpnuzxl = "url"; |
|
${$ihbpnuzxl} = str_replace( |
|
${${"GLOBALS"}["rdkgmflvrbgf"]}, |
|
"", |
|
${${"GLOBALS"}["gthrhlcx"]} |
|
); |
|
} |
|
} |
|
} |
|
return ${${"GLOBALS"}["bujzpeco"]}; |
|
} |
|
public function match($requestUrl = null, $requestMethod = null) |
|
{ |
|
${${"GLOBALS"}["mnrldqdp"]} = []; |
|
$dvwchaiajiu = "strpos"; |
|
${"GLOBALS"}["wuqotbcwwx"] = "requestUrl"; |
|
$mopjvqt = "requestUrl"; |
|
${"GLOBALS"}["ceoscck"] = "requestMethod"; |
|
$daglprejfc = "requestUrl"; |
|
if (${${"GLOBALS"}["kdewwhmr"]} === null) { |
|
${${"GLOBALS"}["kdewwhmr"]} = isset($_SERVER["REQUEST_URI"]) |
|
? $_SERVER["REQUEST_URI"] |
|
: "/"; |
|
} |
|
${${"GLOBALS"}["kdewwhmr"]} = substr( |
|
${$mopjvqt}, |
|
strlen($this->basePath) |
|
); |
|
if ((${$dvwchaiajiu} = strpos(${$daglprejfc}, "?")) !== false) { |
|
${"GLOBALS"}["hrwhhbpsyg"] = "requestUrl"; |
|
${"GLOBALS"}["bncftdc"] = "strpos"; |
|
$fowihbtbsdu = "requestUrl"; |
|
${$fowihbtbsdu} = substr( |
|
${${"GLOBALS"}["hrwhhbpsyg"]}, |
|
0, |
|
${${"GLOBALS"}["bncftdc"]} |
|
); |
|
} |
|
${${"GLOBALS"}["ielvkwx"]} = ${${"GLOBALS"}["kdewwhmr"]} |
|
? ${${"GLOBALS"}["wuqotbcwwx"]}[ |
|
strlen(${${"GLOBALS"}["kdewwhmr"]}) - 1 |
|
] |
|
: ""; |
|
if (${${"GLOBALS"}["ceoscck"]} === null) { |
|
${"GLOBALS"}["kvsmocjyog"] = "requestMethod"; |
|
${${"GLOBALS"}["kvsmocjyog"]} = isset($_SERVER["REQUEST_METHOD"]) |
|
? $_SERVER["REQUEST_METHOD"] |
|
: "GET"; |
|
} |
|
foreach ($this->routes as ${${"GLOBALS"}["smolar"]}) { |
|
${"GLOBALS"}["adylcufqxy"] = "position"; |
|
$ghwoweq = "route"; |
|
${"GLOBALS"}["hgqjhnkqn"] = "route"; |
|
$lmexojqte = "target"; |
|
$nmbontwdpq = "match"; |
|
$wkzdthecr = "handler"; |
|
${"GLOBALS"}["hvbjnfyb"] = "methods"; |
|
$wdzqpgcdjh = "methods"; |
|
${"GLOBALS"}["pbmcylfrqnz"] = "method_match"; |
|
list( |
|
${$wdzqpgcdjh}, |
|
${$ghwoweq}, |
|
${$lmexojqte}, |
|
${${"GLOBALS"}["nojrmhwb"]}, |
|
) = ${$wkzdthecr}; |
|
${${"GLOBALS"}["pbmcylfrqnz"]} = |
|
stripos( |
|
${${"GLOBALS"}["hvbjnfyb"]}, |
|
${${"GLOBALS"}["wfjudmkesp"]} |
|
) !== false; |
|
if (!${${"GLOBALS"}["hrbpetmqjq"]}) { |
|
continue; |
|
} |
|
if (${${"GLOBALS"}["hgqjhnkqn"]} === "*") { |
|
${${"GLOBALS"}["svhvtvmtlwn"]} = true; |
|
} elseif ( |
|
isset(${${"GLOBALS"}["wpxzqrc"]}[0]) && |
|
${${"GLOBALS"}["wpxzqrc"]}[0] === "@" |
|
) { |
|
${"GLOBALS"}["iqylen"] = "route"; |
|
$dbcjfunkf = "params"; |
|
${${"GLOBALS"}["difhktogm"]} = |
|
"`" . substr(${${"GLOBALS"}["iqylen"]}, 1) . "`u"; |
|
${${"GLOBALS"}["svhvtvmtlwn"]} = |
|
preg_match( |
|
${${"GLOBALS"}["difhktogm"]}, |
|
${${"GLOBALS"}["kdewwhmr"]}, |
|
${$dbcjfunkf} |
|
) === 1; |
|
} elseif ( |
|
(${${"GLOBALS"}["adylcufqxy"]} = @strpos( |
|
${${"GLOBALS"}["wpxzqrc"]}, |
|
"[" |
|
)) === false |
|
) { |
|
${"GLOBALS"}["iizkedbhtb"] = "requestUrl"; |
|
${"GLOBALS"}["gqkjsw"] = "match"; |
|
${${"GLOBALS"}["gqkjsw"]} = |
|
strcmp( |
|
${${"GLOBALS"}["iizkedbhtb"]}, |
|
${${"GLOBALS"}["wpxzqrc"]} |
|
) === 0; |
|
} else { |
|
${"GLOBALS"}["neqtxj"] = "requestUrl"; |
|
${"GLOBALS"}["rxlbdscf"] = "lastRequestUrlChar"; |
|
$wckebd = "route"; |
|
${"GLOBALS"}["qxcefpdpijjx"] = "position"; |
|
if ( |
|
@strncmp( |
|
${${"GLOBALS"}["kdewwhmr"]}, |
|
${${"GLOBALS"}["wpxzqrc"]}, |
|
${${"GLOBALS"}["gvhqawh"]} |
|
) !== 0 && |
|
(${${"GLOBALS"}["rxlbdscf"]} === "/" || |
|
@${$wckebd}[${${"GLOBALS"}["qxcefpdpijjx"]} - 1] !== |
|
"/") |
|
) { |
|
continue; |
|
} |
|
${${"GLOBALS"}["dqzqldait"]} = $this->compileRoute( |
|
${${"GLOBALS"}["wpxzqrc"]} |
|
); |
|
${${"GLOBALS"}["svhvtvmtlwn"]} = |
|
preg_match( |
|
${${"GLOBALS"}["dqzqldait"]}, |
|
${${"GLOBALS"}["neqtxj"]}, |
|
${${"GLOBALS"}["mnrldqdp"]} |
|
) === 1; |
|
} |
|
if (${$nmbontwdpq}) { |
|
${"GLOBALS"}["nwvkrila"] = "name"; |
|
$yjkgrqrf = "target"; |
|
if (${${"GLOBALS"}["mnrldqdp"]}) { |
|
${"GLOBALS"}["csddcsp"] = "key"; |
|
$ywzdfolgr = "value"; |
|
$dedltzeg = "params"; |
|
foreach ( |
|
${$dedltzeg} |
|
as ${${"GLOBALS"}["csddcsp"]} => ${$ywzdfolgr} |
|
) { |
|
if (is_numeric(${${"GLOBALS"}["crehucyu"]})) { |
|
${"GLOBALS"}["ijtffihp"] = "params"; |
|
unset( |
|
${${"GLOBALS"}["ijtffihp"]}[ |
|
${${"GLOBALS"}["crehucyu"]} |
|
] |
|
); |
|
} |
|
} |
|
} |
|
return [ |
|
"target" => ${$yjkgrqrf}, |
|
"params" => ${${"GLOBALS"}["mnrldqdp"]}, |
|
"name" => ${${"GLOBALS"}["nwvkrila"]}, |
|
]; |
|
} |
|
} |
|
return false; |
|
} |
|
protected function compileRoute($route) |
|
{ |
|
${"GLOBALS"}["mebnbtxs"] = "route"; |
|
$bmfvto = "matches"; |
|
if ( |
|
preg_match_all( |
|
"`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`", |
|
${${"GLOBALS"}["mebnbtxs"]}, |
|
${$bmfvto}, |
|
PREG_SET_ORDER |
|
) |
|
) { |
|
${${"GLOBALS"}["gfwbzwp"]} = $this->matchTypes; |
|
foreach ( |
|
${${"GLOBALS"}["yjeejonjt"]} |
|
as ${${"GLOBALS"}["svhvtvmtlwn"]} |
|
) { |
|
${"GLOBALS"}["wphenucf"] = "type"; |
|
$wmwhbmowij = "pattern"; |
|
${"GLOBALS"}["qhrqgyxqgb"] = "pattern"; |
|
${"GLOBALS"}["fubrgxc"] = "match"; |
|
${"GLOBALS"}["dsmirhxuwmby"] = "optional"; |
|
$mlkrryxqab = "type"; |
|
${"GLOBALS"}["shwlyubciyn"] = "type"; |
|
$ryvzujghqwae = "pre"; |
|
${"GLOBALS"}["hnccmn"] = "param"; |
|
$piloxlse = "param"; |
|
$cpwtsxohxdxa = "route"; |
|
${"GLOBALS"}["syquobqdgkjd"] = "pre"; |
|
list( |
|
${${"GLOBALS"}["rkbovssyxj"]}, |
|
${${"GLOBALS"}["aybmsnriksi"]}, |
|
${${"GLOBALS"}["wphenucf"]}, |
|
${${"GLOBALS"}["hnccmn"]}, |
|
${${"GLOBALS"}["cxzyviss"]}, |
|
) = ${${"GLOBALS"}["fubrgxc"]}; |
|
if ( |
|
isset( |
|
${${"GLOBALS"}["gfwbzwp"]}[ |
|
${${"GLOBALS"}["shwlyubciyn"]} |
|
] |
|
) |
|
) { |
|
$gxuzxclrvhm = "type"; |
|
${$gxuzxclrvhm} = |
|
${${"GLOBALS"}["gfwbzwp"]}[ |
|
${${"GLOBALS"}["gmfcfiphuit"]} |
|
]; |
|
} |
|
if (${${"GLOBALS"}["aybmsnriksi"]} === ".") { |
|
$cjktgnt = "pre"; |
|
${$cjktgnt} = "\."; |
|
} |
|
$jwmomffq = "route"; |
|
${${"GLOBALS"}["cxzyviss"]} = |
|
${${"GLOBALS"}["cxzyviss"]} !== "" ? "?" : null; |
|
${$wmwhbmowij} = |
|
"(?:" . |
|
(${${"GLOBALS"}["syquobqdgkjd"]} !== "" |
|
? ${$ryvzujghqwae} |
|
: null) . |
|
"(" . |
|
(${$piloxlse} !== "" ? "?P<$param>" : null) . |
|
${$mlkrryxqab} . |
|
")" . |
|
${${"GLOBALS"}["dsmirhxuwmby"]} . |
|
")" . |
|
${${"GLOBALS"}["cxzyviss"]}; |
|
${$jwmomffq} = str_replace( |
|
${${"GLOBALS"}["rkbovssyxj"]}, |
|
${${"GLOBALS"}["qhrqgyxqgb"]}, |
|
${$cpwtsxohxdxa} |
|
); |
|
} |
|
} |
|
return "`^$route$`u"; |
|
} |
|
} |
|
?> |