@ 2014-11-05T03:35:20Z <?php
<?php
class Route {
const RESOURCE_PATTERN = '/'.'\[:(.*)\]'.'/';
const TOKEN_PARA_PATTERN = '/'.'\{:(.*)\}'.'/';
private $methodList;
private $url;
private $urlTokenList = array();
private $urlTokenCount;
private $controller;
private $action;
private $tokenParameterList = array();
private $tokenParameterDetailList = array();
private $resourceList = array();
private $resourceDetailList = array('music_recording' => array('jazz', 'pop'));
private $requestURL;
private $requestURLTokenList;
private $requestURLTokenCount;
public function __construct($httpMethod, $httpUrl, $controller, $action) {
$this->methodList = explode('|', $httpMethod);
$this->url = $httpUrl;
$this->controller = $controller;
$this->action = $action;
$this->parseURL($httpUrl);
}
public function parseURL($url) {
$tmpUrl = $url;
if (substr($tmpUrl, 0, 1) == '/') {
$tmpUrl = substr($tmpUrl, 1);
}
if (substr($tmpUrl, -1) == '/') {
$tmpUrl = substr($tmpUrl, 0, -1);
}
$tmpURLTokenList = explode('/', $tmpUrl);
$this->urlTokenCount = count($tmpURLTokenList);
foreach($tmpURLTokenList as $token) {
$tokenInfo = array();
$tokenInfo['name'] = $token;
$isMatchedForResourcePattern = preg_match(self::RESOURCE_PATTERN, $token, $resourceMatches, PREG_OFFSET_CAPTURE);
if ($isMatchedForResourcePattern === 1) {
array_push($this->resourceList, $resourceMatches[1][0]);
$tokenInfo['isResource'] = 1;
$tokenInfo['resourceName'] = $resourceMatches[1][0];
} else {
$tokenInfo['isResource'] = 0;
}
$isMatchedForParaPattern = preg_match(self::TOKEN_PARA_PATTERN, $token, $paramMatches, PREG_OFFSET_CAPTURE);
if ($isMatchedForParaPattern === 1) {
array_push($this->tokenParameterList, $paramMatches[1][0]);
$tokenInfo['isParam'] = 1;
$tokenInfo['paramName'] = $paramMatches[1][0];
} else {
$tokenInfo['isParam'] = 0;
}
array_push($this->urlTokenList, $tokenInfo);
}
}
public function parseRequestURL($url) {
$tmpUrl = $url;
if (substr($tmpUrl, 0, 1) == '/') {
$tmpUrl = substr($tmpUrl, 1);
}
if (substr($tmpUrl, -1) == '/') {
$tmpUrl = substr($tmpUrl, 0, -1);
}
$this->requestURLTokenList = explode('/', $tmpUrl);
$this->requestURLTokenCount = count($this->requestURLTokenList);
}
public function getMethodList() {
return $this->methodList;
}
public function getUrl() {
return $this->url;
}
public function getUrlTokenList() {
return $this->urlTokenList;
}
public function getUrlTokenCount() {
return $this->urlTokenCount;
}
public function getController() {
return $this->controller;
}
public function getAction() {
return $this->action;
}
public function getTokenParameterList() {
return $this->tokenParameterList;
}
public function getResourceList() {
return $this->resourceList;
}
public function getResourceDetailList() {
return $this->resourceDetailList;
}
public function isMatched($url) {
$this->requestURL = $url;
$this->parseRequestURL($url);
// echo "count not the same[".$this->requestURLTokenCount." - ".$this->urlTokenCount."]";
if ($this->requestURLTokenCount !== $this->urlTokenCount) {
// echo "count not the same[".$this->requestURLTokenCount." - ".$this->urlTokenCount."]";
return 0;
}
$isMatched = 1;
for($i=0;$i<($this->urlTokenCount);$i++) {
$urlToken = $this->urlTokenList[$i];
$requestURLToken = $this->requestURLTokenList[$i];
if ($urlToken['isResource'] !== 1 && $urlToken['isParam'] !== 1) {
if (strcmp($urlToken['name'], $requestURLToken)) {
$isMatched = 0;
break;
}
} else if ($urlToken['isResource'] === 1) {
if (array_key_exists($requestURLToken, $this->resourceDetailList) && in_array($requestURLToken, $this->resourceDetailList[$urlToken['resourceName']])) {
$isMatched = 1;
} else {
$isMatched = 0;
break;
}
} else if ($urlToken['isParam'] === 1) {
$this->tokenParameterDetailList[$urlToken['paramName']] = $requestURLToken;
}
}
return $isMatched;
}
public function getControllerInstance() {
}
}
$ROUTES =
array(
array('httpMethod' => 'GET', 'url' => '[:music_category]/xml', 'controller' => 'CategoryController', 'action' => 'xml'),
array('httpMethod' => 'GET', 'url' => '[:music_category]/json', 'controller' => 'CategoryController', 'action' => 'json'),
array('httpMethod' => 'GET|POST', 'url' => 'xml', 'controller' => 'temp_controller', 'action' => 'xml'),
array('httpMethod' => 'GET|POST', 'url' => 'json', 'controller' => 'temp_controller', 'action' => 'json'),
array('httpMethod' => 'GET|POST', 'url' => 'post/[:music_category]/{:data}/xml', 'controller' => 'CategoryController', 'action' => 'post')
);
$routeObjArray = array();
foreach ($ROUTES as $route) {
array_push($GLOBALS['routeObjArray'], new Route($route['httpMethod'], $route['url'], $route['controller'], $route['action']));
}
$testURl = "music/xml";
foreach ($routeObjArray as $abc) {
print_r ($abc->isMatched($testURl) == 1 ? 'true' : 'false');
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.34 0.012 0.032 12.00 5.4.32 0.004 0.037 12.50 5.4.31 0.006 0.044 12.49 5.4.30 0.006 0.038 12.50 5.4.29 0.004 0.039 12.49 5.4.28 0.004 0.037 12.39 5.4.27 0.007 0.034 12.39 5.4.26 0.007 0.036 12.39 5.4.25 0.010 0.034 12.39 5.4.24 0.006 0.035 12.39 5.4.23 0.006 0.036 12.38 5.4.22 0.004 0.038 12.38 5.4.21 0.005 0.035 12.38 5.4.20 0.006 0.036 12.38 5.4.19 0.005 0.037 12.38 5.4.18 0.006 0.035 12.38 5.4.17 0.007 0.033 12.38 5.4.16 0.008 0.033 12.39 5.4.15 0.005 0.035 12.38 5.4.14 0.006 0.035 12.07 5.4.13 0.007 0.033 12.05 5.4.12 0.008 0.032 12.02 5.4.11 0.005 0.034 12.01 5.4.10 0.002 0.038 12.01 5.4.9 0.005 0.036 12.01 5.4.8 0.007 0.035 12.01 5.4.7 0.006 0.034 12.01 5.4.6 0.007 0.033 12.01 5.4.5 0.008 0.032 12.01 5.4.4 0.005 0.041 12.00 5.4.3 0.007 0.040 11.99 5.4.2 0.005 0.035 11.98 5.4.1 0.006 0.033 11.99 5.4.0 0.006 0.035 11.48 5.3.29 0.007 0.045 12.80 5.3.28 0.009 0.045 12.71 5.3.27 0.008 0.036 12.72 5.3.26 0.008 0.036 12.72 5.3.25 0.002 0.040 12.72 5.3.24 0.006 0.036 12.72 5.3.23 0.004 0.038 12.71 5.3.22 0.006 0.041 12.68 5.3.21 0.008 0.036 12.68 5.3.20 0.005 0.036 12.68 5.3.19 0.006 0.037 12.68 5.3.18 0.005 0.037 12.67 5.3.17 0.009 0.032 12.67 5.3.16 0.002 0.039 12.67 5.3.15 0.007 0.034 12.67 5.3.14 0.004 0.038 12.66 5.3.13 0.008 0.036 12.66 5.3.12 0.008 0.035 12.66 5.3.11 0.012 0.032 12.66 5.3.10 0.007 0.034 12.12 5.3.9 0.007 0.040 12.09 5.3.8 0.007 0.045 12.07 5.3.7 0.005 0.043 12.07 5.3.6 0.013 0.034 12.06 5.3.5 0.007 0.039 12.00 5.3.4 0.008 0.034 12.00 5.3.3 0.007 0.039 11.95 5.3.2 0.006 0.034 11.73 5.3.1 0.007 0.032 11.70 5.3.0 0.004 0.036 11.68 5.2.17 0.004 0.031 9.18 5.2.16 0.004 0.030 9.18 5.2.15 0.007 0.028 9.19 5.2.14 0.007 0.027 9.18 5.2.13 0.002 0.030 9.14 5.2.12 0.010 0.022 9.14 5.2.11 0.004 0.036 9.15 5.2.10 0.006 0.027 9.14 5.2.9 0.005 0.027 9.15 5.2.8 0.004 0.031 9.14 5.2.7 0.003 0.033 9.14 5.2.6 0.005 0.030 9.09 5.2.5 0.004 0.030 9.06 5.2.4 0.005 0.028 9.04 5.2.3 0.006 0.028 9.02 5.2.2 0.006 0.027 9.01 5.2.1 0.004 0.031 8.93 5.2.0 0.005 0.032 8.79 5.1.6 0.003 0.026 8.07 5.1.5 0.005 0.023 8.07 5.1.4 0.001 0.028 8.05 5.1.3 0.004 0.027 8.40 5.1.2 0.003 0.027 8.42 5.1.1 0.005 0.031 8.15 5.1.0 0.003 0.027 8.15 5.0.5 0.004 0.019 6.63 5.0.4 0.005 0.022 6.48 5.0.3 0.005 0.029 6.30 5.0.2 0.005 0.018 6.27 5.0.1 0.005 0.018 6.25 5.0.0 0.005 0.028 6.23 4.4.9 0.004 0.013 4.78 4.4.8 0.002 0.015 4.76 4.4.7 0.003 0.014 4.76 4.4.6 0.002 0.015 4.76 4.4.5 0.001 0.016 4.77 4.4.4 0.000 0.027 4.71 4.4.3 0.001 0.017 4.76 4.4.2 0.003 0.015 4.84 4.4.1 0.004 0.014 4.85 4.4.0 0.002 0.025 4.75 4.3.11 0.002 0.017 4.67 4.3.10 0.002 0.015 4.66 4.3.9 0.002 0.014 4.63 4.3.8 0.006 0.031 4.58 4.3.7 0.002 0.015 4.63 4.3.6 0.004 0.013 4.63 4.3.5 0.003 0.015 4.63 4.3.4 0.004 0.022 4.54 4.3.3 0.003 0.014 3.29 4.3.2 0.004 0.017 3.26 4.3.1 0.002 0.019 3.22 4.3.0 0.000 0.027 7.42
preferences:dark mode live preview
146.46 ms | 1394 KiB | 7 Q