*/
public $cacheDirUrl;
+
+ /**
+ * List of config file paths that were tried to load
+ * @var array
+ */
+ public $cfgFiles = array();
+
+ /**
+ * If a configuration file could be found
+ * @var boolean
+ */
+ public $cfgFileExists;
+
/**
* Credentials for access
*
$this->timestampMaxAge = Options::validateAge($this->timestampMaxAge);
$this->screenshotMaxAge = Options::validateAge($this->screenshotMaxAge);
$this->screenshotMinAge = Options::validateAge($this->screenshotMinAge);
+
+ $this->loadConfigFilePaths();
}
public function load()
{
- $cfgFile = __DIR__ . '/../../data/phancap.config.php';
- if (file_exists($cfgFile)) {
- $this->loadFile($cfgFile);
+ $this->cfgFileExists = false;
+ foreach ($this->cfgFiles as $file) {
+ if (file_exists($file)) {
+ $this->cfgFileExists = true;
+ $this->loadFile($file);
+ break;
+ }
}
$this->setupCheck();
}
+ /**
+ * Load possible configuration file paths into $this->cfgFiles.
+ *
+ * @return void
+ */
+ protected function loadConfigFilePaths()
+ {
+ $pharFile = \Phar::running();
+ if ($pharFile == '') {
+ $this->cfgFiles[] = __DIR__ . '/../../data/phancap.config.php';
+ } else {
+ //remove phar:// from the path
+ $this->cfgFiles[] = substr($pharFile, 7) . '.config.php';
+ }
+
+ //TODO: add ~/.config/phancap.php
+
+ $this->cfgFiles[] = '/etc/phancap.php';
+ }
+
protected function loadFile($filename)
{
include $filename;
count($config->access) . ' users may access the API'
);
}
+
+ foreach ($config->cfgFiles as $cfgFile) {
+ $messages[][] = array(
+ 'info', 'Possible config file: ' . $cfgFile
+ );
+ }
+ if ($config->cfgFileExists) {
+ $messages[][] = array(
+ 'ok', 'Configuration file loaded'
+ );
+ } else {
+ $messages[][] = array(
+ 'info', 'No configuration file found'
+ );
+ }
} catch (\Exception $e) {
$messages[][] = array('err', $e->getMessage());
}
<head>
<title>phancap setup check</title>
<style type="text/css">
+ li:before {
+ text-align: center;
+ display: inline-block;
+ width: 1em;
+ padding: 0 0.5ex;
+ margin-right: 0.5ex;
+ }
li.ok:before {
content: '✔';
color: green;
- padding: 0 0.5ex;
- margin-right: 0.5ex;
}
li.err:before {
content: "✘";
color: white;
background-color: red;
- padding: 0 0.5ex;
- margin-right: 0.5ex;
+ }
+ li.info:before {
+ content: "i";
+ font-weight: bold;
+ color: blue;
}
</style>
</head>