<?php
define('BIN_PATH', ROOT_PATH . 'bin' . DIRECTORY_SEPARATOR);
 class AppPublish {
 public static $layoutModules = null;
 public static $isReadEvent = false;
 }
 function __isHasRouteParam($url) {
 if(isset($url) == false || $url == '' || $url == '/') return false;
 $startIndex = strpos($url, '{');
 if($startIndex !== false) {
 $endIndex = strpos($url, "}");
 if($endIndex !== false && $endIndex > $startIndex) return true;
 }
 return false;
 }
 function __parseParamRouteUrl($route) {
 $paramRegex = [];
 $startIndex = 0;
 $endIndex = 0;
 $arrUrl = explode('/', $route['url']);
 foreach($arrUrl as $url) {
 $isRegex = false;
 $regexUrl = '';
 $paramArray = [];
 while (true) {
 $startIndex = strpos($url, '{');
 if ($startIndex === false) {
 $regexUrl .= $url;
 break;
 }
 $startIndex++;
 $endIndex = strpos($url, '}', $startIndex);
 if ($endIndex === false) {
 $regexUrl .= $url;
 break;
 }
 if($startIndex > 0) {
 $regexUrl .= "(" . substr($url, 0, $startIndex - 1) . ")";
 if($regexUrl == '()') {
 $regexUrl = '';
 }
 }
 $isRegex = true;
 $param = substr($url, $startIndex, $endIndex - $startIndex);
 $regex = ($route['regex'] && array_key_exists($param, $route['regex'])) ? $route['regex'][$param] : '[a-zA-Z0-9-]+';
 $paramArray[] = [ 'param' => $param, 'value' => '' ];
 if(strpos($regex, '(') !== 0) $regexUrl .= '(' . $regex . ')';
 else $regexUrl .= $regex;
 $url = substr($url, $endIndex + 1);
 }
 $paramRegex[] = [ 'url' => $regexUrl, 'isRegex' => $isRegex, 'paramArray' => $paramArray ];
 }
 return $paramRegex;
 }
 function _isMatcherRouteUrl($routeCfg) {
 $url = GlobalVars::$requestInfo['url'];
 $routeUrl = $routeCfg['url'];
 if($routeUrl == $url) {
 return true;
 }
 if (__isHasRouteParam($routeUrl)) {
 if (substr_count($routeUrl, "/") == substr_count($url, "/")) {
 $paramRegex = __parseParamRouteUrl($routeCfg);
 $arrUrl = explode('/', $url);
 $isMatcher = true;
 foreach ($paramRegex as $key => &$param) {
 if ($param['isRegex']) {
 if (preg_match("/" . $param['url'] . "/", $arrUrl[$key], $match)) {
 if (count($match) > 1) {
 $j = 0;
 for ($i = 1;
 $i < count($match);
 $i++) {
 if($match[$i] != '' && $match[$i] != '-' && $match[$i] != '_') {
 $param['paramArray'][$j++]['value'] = $match[$i];
 }
 }
 }
 }
 else {
 $isMatcher = false;
 break;
 }
 }
 else {
 if ($param['url'] != $arrUrl[$key]) {
 $isMatcher = false;
 break;
 }
 }
 }
 if ($isMatcher) {
 \GlobalVars::$requestInfo['params'] = [];
 $length = count($paramRegex);
 for ($i = 0;
 $i < $length;
 $i++) {
 if (count($paramRegex[$i]['paramArray']) > 0) {
 $l = count($paramRegex[$i]['paramArray']);
 for ($j = 0;
 $j < $l;
 $j++) {
 \GlobalVars::$requestInfo['params'][$paramRegex[$i]['paramArray'][$j]['param']] = $paramRegex[$i]['paramArray'][$j]['value'];
 }
 }
 }
 return true;
 }
 }
 }
 return false;
 }
