From f52e3dc89004ccf6415ead97cfa3cca830f85b03 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Mon, 1 May 2017 22:27:57 +0200 Subject: [PATCH] Add Pico::getVendorDir() The vendor directory is the installation path of the `picocms/Pico` package. If `picocms/Pico` is the composer root package (as in pre-bundled releases), it should be identical to `Pico::getRootDir()`. However, if `picocms/Pico` was installed as composer dependency (e.g. by `picocms/pico-composer`), the vendor directory usually corresponds to something like `Pico::getRootDir() . "vendor/picocms/pico"`. The vendor directory is currently only used as a last resort to load Pico's sample contents. --- lib/Pico.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/Pico.php b/lib/Pico.php index 0aed209..2deeb80 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -74,6 +74,14 @@ class Pico */ protected $rootDir; + /** + * Vendor directory of this Pico instance + * + * @see Pico::getVendorDir() + * @var string + */ + protected $vendorDir; + /** * Config directory of this Pico instance * @@ -262,6 +270,7 @@ class Pico public function __construct($rootDir, $configDir, $pluginsDir, $themesDir) { $this->rootDir = rtrim($rootDir, '/\\') . '/'; + $this->vendorDir = dirname(__DIR__) . '/'; $this->configDir = $this->getAbsolutePath($configDir); $this->pluginsDir = $this->getAbsolutePath($pluginsDir); $this->themesDir = $this->getAbsolutePath($themesDir); @@ -277,6 +286,16 @@ class Pico return $this->rootDir; } + /** + * Returns the vendor directory of this Pico instance + * + * @return string vendor directory path + */ + public function getVendorDir() + { + return $this->vendorDir; + } + /** * Returns the config directory of this Pico instance * @@ -744,8 +763,10 @@ class Pico // try to guess the content directory if (is_dir($this->getRootDir() . 'content')) { $this->config['content_dir'] = $this->getRootDir() . 'content/'; - } else { + } elseif (is_dir($this->getRootDir() . 'content-sample')) { $this->config['content_dir'] = $this->getRootDir() . 'content-sample/'; + } else { + $this->config['content_dir'] = $this->getVendorDir() . 'content-sample/'; } } else { $this->config['content_dir'] = $this->getAbsolutePath($this->config['content_dir']);