00001 <?php
00021 error_reporting(E_ALL);
00027 class rewriteMapParser extends zCore{
00028 function parse($filePath){
00029 if(!file_exists($filePath)){
00030 perror('<code>zigmoyd.mvc.rewrite.parser</code><br />Failed to Parse '.$filePath.' as it doesn\t exist');
00031 return false;
00032 }
00033 if(!is_readable($filePath)){
00034 perror('<code>zigmoyd.mvc.rewrite.parser</code><br />Failed to Parse '.$filePath.' as its not readable');
00035 return false;
00036 }
00037 $content=file($filePath);
00038 foreach($content as $i => $line){
00039 if(!preg_match('~(.+)\s*\->\s*(.+)~', $line, $m)){
00040 perror('<code>zigmoyd.mvc.rewrite.parser</code><br />Failed to Parse '.$filePath.' unexpected format near line '.($i+1));
00041 return false;
00042 }else{
00043 $content[$i] = array('fake' => trim($m[1]), 'original' => trim($m[2]));
00044 }
00045 }
00046 return $content;
00047 }
00048 function match($filePath, $fakePath){
00049 foreach(rewriteMapParser::parse($filePath) as $rule){
00050 if(preg_match('$'.trim(trim($rule['fake']), '/').'$',trim(trim($fakePath), '/'))){
00051 return trim(preg_replace('$'.trim(trim($rule['fake']), '/').'$', $rule['original'], trim(trim($fakePath), '/')), '/');
00052 }
00053 }
00054 return false;
00055 }
00056 function currentUrlPath(){
00057 return implode('/', url_segment(ZIG_URL_SEGMENT_PATH));
00058 }
00059 function matchCurrentUrlPath($filePath){
00060 return rewriteMapParser::match($filePath, rewriteMapParser::currentUrlPath());
00061 }
00062 function explode($realPathStr){
00063 $explodedRealPath = explode('/', trim($realPathStr, '/'));
00064 if(!isset($explodedRealPath[0]))perror("<code>zigmoyd.mvc.rewrite.parser</code><br />Unexpected format of real path (Controller not Found)");
00065 if(!isset($explodedRealPath[1]))perror("<code>zigmoyd.mvc.rewrite.parser</code><br />Unexpected format of real path (Method Name not Found)");
00066 $ret = array($explodedRealPath[0], $explodedRealPath[1]);
00067 unset($explodedRealPath[0]);
00068 unset($explodedRealPath[1]);
00069 $args = array_values($explodedRealPath);
00070 return array($ret, $args);
00071 }
00072 }
00073 ?>
00074 <?php
00075
00076
00077 ?>