diff --git a/lib/Minify.php b/lib/Minify.php index 1fe79a9..ba5ac4d 100644 --- a/lib/Minify.php +++ b/lib/Minify.php @@ -56,6 +56,11 @@ class Minify { */ protected $controller = null; + /** + * @var Minify_Env + */ + protected $env; + /** * @var Minify_SourceInterface[] */ @@ -218,6 +223,8 @@ class Minify { */ public function serve(Minify_ControllerInterface $controller, $options = array()) { + $this->env = $controller->getEnv(); + $options = array_merge($this->getDefaultOptions(), $options); $config = $controller->createConfiguration($options); @@ -499,7 +506,7 @@ class Minify { protected function setupUriRewrites() { foreach($this->sources as $key => $source) { - $file = $source->getFilePath(); + $file = $this->env->normalizePath($source->getFilePath()); $minifyOptions = $source->getMinifierOptions(); if ($file diff --git a/lib/Minify/App.php b/lib/Minify/App.php index 014f149..d39a639 100644 --- a/lib/Minify/App.php +++ b/lib/Minify/App.php @@ -104,7 +104,7 @@ class App extends Container { if (empty($config->documentRoot)) { return $app->env->getDocRoot(); } - return rtrim($config->documentRoot, '/\\'); + return $app->env->normalizePath($config->documentRoot); }; $this->env = function (App $app) { diff --git a/lib/Minify/Controller/Base.php b/lib/Minify/Controller/Base.php index aa83e36..e95e6e9 100644 --- a/lib/Minify/Controller/Base.php +++ b/lib/Minify/Controller/Base.php @@ -69,4 +69,12 @@ abstract class Minify_Controller_Base implements Minify_ControllerInterface { trigger_error(__METHOD__ . ' is deprecated in Minify 3.0.', E_USER_DEPRECATED); $this->logger->info($msg); } + + /** + * {@inheritdoc} + */ + public function getEnv() + { + return $this->env; + } } diff --git a/lib/Minify/ControllerInterface.php b/lib/Minify/ControllerInterface.php index 3828875..ebd71a4 100644 --- a/lib/Minify/ControllerInterface.php +++ b/lib/Minify/ControllerInterface.php @@ -12,4 +12,11 @@ interface Minify_ControllerInterface { * @return Minify_ServeConfiguration */ public function createConfiguration(array $options); + + /** + * Get the Env component + * + * @return Minify_Env + */ + public function getEnv(); } \ No newline at end of file diff --git a/lib/Minify/Env.php b/lib/Minify/Env.php index e6718f6..12e132d 100644 --- a/lib/Minify/Env.php +++ b/lib/Minify/Env.php @@ -33,6 +33,7 @@ class Minify_Env { } else { $this->server['DOCUMENT_ROOT'] = rtrim($this->server['DOCUMENT_ROOT'], '/\\'); } + $this->server['DOCUMENT_ROOT'] = $this->normalizePath($this->server['DOCUMENT_ROOT']); $this->get = $options['get']; $this->post = $options['post']; $this->cookie = $options['cookie']; @@ -76,6 +77,29 @@ class Minify_Env { return isset($this->post[$key]) ? $this->post[$key] : $default; } + /** + * turn windows-style slashes into unix-style, + * remove trailing slash + * and lowercase drive letter + * + * @param string $path absolute path + * + * @return string + */ + public function normalizePath($path) + { + $realpath = realpath($path); + if ($realpath) { + $path = $realpath; + } + $path = str_replace('\\', '/', $path); + $path = rtrim($path, '/'); + if (substr($path, 1, 1) === ':') { + $path = lcfirst($path); + } + return $path; + } + protected $server = null; protected $get = null; protected $post = null; diff --git a/lib/Minify/Source/Factory.php b/lib/Minify/Source/Factory.php index 476e798..7033179 100644 --- a/lib/Minify/Source/Factory.php +++ b/lib/Minify/Source/Factory.php @@ -110,20 +110,6 @@ class Minify_Source_Factory { return $realpath; } - /** - * turn windows-style slashes into unix-style, - * remove trailing slash - * and lowercase drive letter - * - * @param string $path absolute path - * - * @return string - */ - public function getNormalizedPath($path) - { - return lcfirst(rtrim(str_replace('\\', '/', $path), '/')); - } - /** * @param mixed $spec * @@ -159,8 +145,9 @@ class Minify_Source_Factory { if ($this->options['checkAllowDirs']) { $allowDirs = (array)$this->options['allowDirs']; $inAllowedDir = false; + $filePath = $this->env->normalizePath($spec['filepath']); foreach ($allowDirs as $allowDir) { - if (strpos($this->getNormalizedPath($spec['filepath']), $this->getNormalizedPath($allowDir)) === 0) { + if (strpos($filePath, $this->env->normalizePath($allowDir)) === 0) { $inAllowedDir = true; } }