@ 2014-11-05T03:35:32Z <?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.006 0.033 12.01 5.4.32 0.006 0.035 12.50 5.4.31 0.004 0.039 12.49 5.4.30 0.003 0.037 12.50 5.4.29 0.004 0.038 12.49 5.4.28 0.006 0.039 12.39 5.4.27 0.012 0.038 12.39 5.4.26 0.008 0.040 12.39 5.4.25 0.004 0.039 12.39 5.4.24 0.007 0.039 12.39 5.4.23 0.007 0.036 12.38 5.4.22 0.006 0.041 12.38 5.4.21 0.008 0.033 12.38 5.4.20 0.007 0.037 12.38 5.4.19 0.011 0.033 12.38 5.4.18 0.006 0.035 12.38 5.4.17 0.009 0.037 12.38 5.4.16 0.007 0.034 12.38 5.4.15 0.005 0.036 12.38 5.4.14 0.005 0.037 12.07 5.4.13 0.003 0.041 12.05 5.4.12 0.007 0.033 12.02 5.4.11 0.007 0.032 12.01 5.4.10 0.008 0.034 12.02 5.4.9 0.006 0.037 12.01 5.4.8 0.006 0.035 12.01 5.4.7 0.004 0.035 12.00 5.4.6 0.007 0.040 12.01 5.4.5 0.009 0.034 12.01 5.4.4 0.005 0.035 11.99 5.4.3 0.011 0.040 12.00 5.4.2 0.010 0.039 11.98 5.4.1 0.007 0.035 11.99 5.4.0 0.007 0.042 11.48 5.3.29 0.007 0.043 12.80 5.3.28 0.010 0.034 12.71 5.3.27 0.008 0.040 12.73 5.3.26 0.006 0.039 12.72 5.3.25 0.004 0.038 12.72 5.3.24 0.003 0.039 12.72 5.3.23 0.007 0.037 12.70 5.3.22 0.007 0.036 12.68 5.3.21 0.006 0.038 12.68 5.3.20 0.007 0.035 12.68 5.3.19 0.008 0.035 12.68 5.3.18 0.011 0.030 12.68 5.3.17 0.004 0.038 12.67 5.3.16 0.008 0.033 12.67 5.3.15 0.007 0.036 12.68 5.3.14 0.006 0.035 12.66 5.3.13 0.004 0.039 12.66 5.3.12 0.005 0.038 12.65 5.3.11 0.009 0.037 12.66 5.3.10 0.007 0.042 12.12 5.3.9 0.011 0.030 12.09 5.3.8 0.009 0.039 12.07 5.3.7 0.009 0.039 12.08 5.3.6 0.006 0.037 12.07 5.3.5 0.014 0.035 12.00 5.3.4 0.008 0.038 12.00 5.3.3 0.003 0.042 11.95 5.3.2 0.010 0.038 11.73 5.3.1 0.006 0.034 11.70 5.3.0 0.004 0.036 11.68 5.2.17 0.003 0.031 9.18 5.2.16 0.003 0.030 9.18 5.2.15 0.007 0.028 9.19 5.2.14 0.005 0.029 9.18 5.2.13 0.004 0.029 9.14 5.2.12 0.008 0.025 9.14 5.2.11 0.006 0.027 9.15 5.2.10 0.004 0.027 9.15 5.2.9 0.006 0.027 9.15 5.2.8 0.007 0.027 9.14 5.2.7 0.007 0.027 9.14 5.2.6 0.009 0.024 9.10 5.2.5 0.003 0.031 9.06 5.2.4 0.006 0.027 9.04 5.2.3 0.004 0.029 9.01 5.2.2 0.005 0.027 9.01 5.2.1 0.005 0.026 8.93 5.2.0 0.011 0.024 8.79 5.1.6 0.003 0.025 8.08 5.1.5 0.007 0.022 8.07 5.1.4 0.008 0.021 8.05 5.1.3 0.007 0.023 8.41 5.1.2 0.007 0.025 8.42 5.1.1 0.004 0.025 8.15 5.1.0 0.003 0.025 8.14 5.0.5 0.004 0.019 6.63 5.0.4 0.003 0.019 6.48 5.0.3 0.005 0.029 6.29 5.0.2 0.004 0.018 6.27 5.0.1 0.001 0.021 6.24 5.0.0 0.007 0.026 6.23 4.4.9 0.005 0.013 4.78 4.4.8 0.004 0.013 4.75 4.4.7 0.004 0.014 4.75 4.4.6 0.005 0.015 4.75 4.4.5 0.004 0.014 4.77 4.4.4 0.002 0.028 4.70 4.4.3 0.008 0.016 4.76 4.4.2 0.002 0.020 4.84 4.4.1 0.004 0.021 4.84 4.4.0 0.005 0.027 4.76 4.3.11 0.002 0.016 4.67 4.3.10 0.002 0.022 4.67 4.3.9 0.003 0.014 4.63 4.3.8 0.001 0.026 4.59 4.3.7 0.006 0.015 4.63 4.3.6 0.003 0.016 4.63 4.3.5 0.003 0.015 4.62 4.3.4 0.002 0.028 4.54 4.3.3 0.003 0.014 3.28 4.3.2 0.002 0.015 3.26 4.3.1 0.003 0.017 3.23 4.3.0 0.000 0.023 7.40
preferences:dark mode live preview
142.73 ms | 1394 KiB | 7 Q