コード例 #1
0
ファイル: Utility.php プロジェクト: falmar/Epsilon
 /**
  * @param $Path
  * @return string
  */
 public static function getRelativePath($Path)
 {
     $URI = Factory::getURI();
     $Filter = array_filter(explode("/", EPSILON_PATH));
     $nPath = array_pop($Filter);
     return $URI->getRelativePath() . substr($Path, strpos($Path, $nPath) + strlen($nPath) + 1, strlen($Path));
 }
コード例 #2
0
ファイル: Router.php プロジェクト: falmar/Epsilon
 /**
  * @param null  $Route
  * @param array $Parameters
  * @param null  $Fragment
  * @return string
  */
 public function getURL($Route = null, $Parameters = [], $Fragment = null)
 {
     $eURI = Factory::getURI();
     $Query = null;
     $arQuery = $Parameters;
     if (($Rules = $this->getRules()) && is_array($Parameters)) {
         $rRoute = $Route;
         $HighestMatch = 0;
         foreach ($Rules as $rKey => $rValue) {
             $Match = 0;
             if ($rValue == $rRoute) {
                 $replace = [];
                 foreach (explode('/', $rKey) as $item) {
                     if (strpos($item, ':')) {
                         $Key = substr($item, 1, strpos($item, ':') - 1);
                         if (isset($Parameters[$Key])) {
                             $replace[$item] = $Parameters[$Key];
                             unset($arQuery[$Key]);
                             $Match++;
                         }
                     }
                 }
                 $r = str_replace(array_keys($replace), array_values($replace), $rKey);
                 if (preg_match($this->getRuleRegex($rKey), $r)) {
                     if ($Match >= $HighestMatch) {
                         $HighestMatch = $Match;
                         $Route = $r;
                     }
                 }
             }
         }
     }
     if (!Config::PRETTY_URL && $Route) {
         $Route = "?r={$Route}";
     } elseif (strpos($Route, '/') !== 0 && $Route) {
         $Route = '/' . $Route;
     }
     foreach ($arQuery as $Key => $Value) {
         if (!$Query && Config::PRETTY_URL) {
             $Query = '?' . $Key . '=' . $Value;
         } else {
             $Query = '&' . $Key . '=' . $Value;
         }
     }
     if (is_string($Fragment)) {
         $Fragment = "#{$Fragment}";
     }
     return $eURI->getRelativePath() . (Config::SHOW_SCRIPT ? 'index.php' : null) . $Route . $Query . $Fragment;
 }