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
This commit is contained in:
parent
fc7632b0ac
commit
cdef7a6324
2 changed files with 23 additions and 7 deletions
|
@ -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();
|
||||
|
|
24
lib/Pico.php
24
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}
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue