From cdef7a6324a7309fa03994237b6649545b09047c Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 1 Oct 2015 15:14:45 +0200 Subject: [PATCH] Explicitly treat relative paths to be relative to Picos root dir This tempers the BC break, we can now recommend to simply remove the ROOT_DIR part --- index.php | 6 +++--- lib/Pico.php | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index c459a00..02f9444 100644 --- a/index.php +++ b/index.php @@ -2,8 +2,8 @@ require_once(__DIR__ . '/vendor/autoload.php'); $pico = new Pico( __DIR__, - __DIR__ . '/config/', - __DIR__ . '/plugins/', - __DIR__ . '/themes/' + 'config/', + 'plugins/', + 'themes/' ); echo $pico->run(); diff --git a/lib/Pico.php b/lib/Pico.php index 544fb4e..e9aae70 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -166,9 +166,9 @@ class Pico public function __construct($rootDir, $configDir, $pluginsDir, $themesDir) { $this->rootDir = rtrim($rootDir, '/') . '/'; - $this->configDir = rtrim($configDir, '/') . '/'; - $this->pluginsDir = rtrim($pluginsDir, '/') . '/'; - $this->themesDir = rtrim($themesDir, '/') . '/'; + $this->configDir = $this->getAbsolutePath($configDir); + $this->pluginsDir = $this->getAbsolutePath($pluginsDir); + $this->themesDir = $this->getAbsolutePath($themesDir); } /** @@ -399,7 +399,7 @@ class Pico $this->config['base_url'] = $this->getBaseUrl(); } if (!empty($this->config['content_dir'])) { - $this->config['content_dir'] = rtrim($this->config['content_dir'], '/') . '/'; + $this->config['content_dir'] = $this->getAbsolutePath($this->config['content_dir']); } if (!empty($this->config['timezone'])) { date_default_timezone_set($this->config['timezone']); @@ -1006,6 +1006,22 @@ class Pico return $result; } + /** + * Makes a relative path absolute to Picos root dir + * + * This method also guarantees a trailing slash. + * + * @param string $path relative or absolute path + * @return string absolute path + */ + protected function getAbsolutePath($path) + { + if (substr($path, 0, 1) !== '/') { + $path = $this->getRootDir() . $path; + } + return rtrim($path, '/') . '/'; + } + /** * Triggers events on plugins which implement {@link PicoPluginInterface} *