From 7c607ff932c05963ac465b9ec916e568f5002a7a Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Mon, 28 Sep 2015 21:50:32 -0400 Subject: [PATCH] Allow specifying files via $min_symlinks paths If you have an alias/symlink like "//~name" => "/full/path", then you can now serve with the more logical URL http://example.com/min/?f=~name/foo.css Fixes #137 --- index.php | 1 + lib/Minify/CSS/UriRewriter.php | 4 ++-- lib/Minify/Controller/MinApp.php | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index c3628ae..0d8e9e1 100644 --- a/index.php +++ b/index.php @@ -52,6 +52,7 @@ $server = new Minify($cache); // TODO probably should do this elsewhere... $min_serveOptions['minifierOptions']['text/css']['docRoot'] = $env->getDocRoot(); $min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks; +$min_serveOptions['minApp']['symlinks'] = $min_symlinks; // auto-add targets to allowDirs foreach ($min_symlinks as $uri => $target) { $min_serveOptions['minApp']['allowDirs'][] = $target; diff --git a/lib/Minify/CSS/UriRewriter.php b/lib/Minify/CSS/UriRewriter.php index 43cc254..52f1d43 100644 --- a/lib/Minify/CSS/UriRewriter.php +++ b/lib/Minify/CSS/UriRewriter.php @@ -48,8 +48,8 @@ class Minify_CSS_UriRewriter { ); self::$_currentDir = self::_realpath($currentDir); self::$_symlinks = array(); - - // normalize symlinks + + // normalize symlinks in order to map to link foreach ($symlinks as $link => $target) { $link = ($link === '//') ? self::$_docRoot diff --git a/lib/Minify/Controller/MinApp.php b/lib/Minify/Controller/MinApp.php index b79c9fa..6f58380 100644 --- a/lib/Minify/Controller/MinApp.php +++ b/lib/Minify/Controller/MinApp.php @@ -33,11 +33,22 @@ class Minify_Controller_MinApp extends Minify_Controller_Base { array( 'groupsOnly' => false, 'groups' => array(), + 'symlinks' => array(), ) ,(isset($options['minApp']) ? $options['minApp'] : array()) ); unset($options['minApp']); + // normalize $symlinks in order to map to target + $symlinks = array(); + foreach ($localOptions['symlinks'] as $link => $target) { + if (0 === strpos($link, '//')) { + $link = rtrim(substr($link, 1), '/') . '/'; + $target = rtrim($target, '/\\'); + $symlinks[$link] = $target; + } + } + $sources = array(); $selectionId = ''; $firstMissingResource = null; @@ -127,6 +138,14 @@ class Minify_Controller_MinApp extends Minify_Controller_Base { $uri = $base . $file; $path = $this->env->getDocRoot() . $uri; + // try to rewrite path + foreach ($symlinks as $link => $target) { + if (0 === strpos($uri, $link)) { + $path = $target . DIRECTORY_SEPARATOR . substr($uri, strlen($link)); + break; + } + } + try { $source = $this->sourceFactory->makeSource(array( 'filepath' => $path,