Add debug mode

You can enable Pico's debug mode by setting the PICO_DEBUG environment variable. At the moment this just enables Twig's debug mode.
This commit is contained in:
Daniel Rudolf 2019-03-28 20:12:46 +01:00
parent edf849725d
commit 8ce3b0c224
No known key found for this signature in database
GPG key ID: A061F02CD8DE4538
2 changed files with 32 additions and 0 deletions

View file

@ -5,6 +5,7 @@ site_title: Pico # The title of your website
base_url: ~ # Pico will try to guess its base URL, if this fails, override it here; base_url: ~ # Pico will try to guess its base URL, if this fails, override it here;
# Example: http://example.com/pico/ # Example: http://example.com/pico/
rewrite_url: ~ # A boolean (true or false) indicating whether URL rewriting is forced rewrite_url: ~ # A boolean (true or false) indicating whether URL rewriting is forced
debug: ~ # Set this to true to enable Pico's debug mode
timezone: UTC # Your PHP installation might require you to manually specify a timezone timezone: UTC # Your PHP installation might require you to manually specify a timezone
## ##

View file

@ -906,6 +906,7 @@ class Pico
'site_title' => 'Pico', 'site_title' => 'Pico',
'base_url' => '', 'base_url' => '',
'rewrite_url' => null, 'rewrite_url' => null,
'debug' => null,
'timezone' => null, 'timezone' => null,
'theme' => 'default', 'theme' => 'default',
'theme_url' => null, 'theme_url' => null,
@ -928,6 +929,10 @@ class Pico
$this->config['rewrite_url'] = $this->isUrlRewritingEnabled(); $this->config['rewrite_url'] = $this->isUrlRewritingEnabled();
} }
if ($this->config['debug'] === null) {
$this->config['debug'] = $this->isDebugModeEnabled();
}
if (!$this->config['timezone']) { if (!$this->config['timezone']) {
// explicitly set a default timezone to prevent a E_NOTICE when no timezone is set; // explicitly set a default timezone to prevent a E_NOTICE when no timezone is set;
// the `date_default_timezone_get()` function always returns a timezone, at least UTC // the `date_default_timezone_get()` function always returns a timezone, at least UTC
@ -959,6 +964,9 @@ class Pico
if ($this->config['twig_config']['cache']) { if ($this->config['twig_config']['cache']) {
$this->config['twig_config']['cache'] = $this->getAbsolutePath($this->config['twig_config']['cache']); $this->config['twig_config']['cache'] = $this->getAbsolutePath($this->config['twig_config']['cache']);
} }
if ($this->config['twig_config']['debug'] === null) {
$this->config['twig_config']['debug'] = $this->isDebugModeEnabled();
}
} }
if (!$this->config['content_dir']) { if (!$this->config['content_dir']) {
@ -2120,6 +2128,29 @@ class Pico
return $this->config['rewrite_url']; return $this->config['rewrite_url'];
} }
/**
* Returns TRUE if Pico's debug mode is enabled
*
* @return bool TRUE if Pico's debug mode is enabled, FALSE otherwise
*/
public function isDebugModeEnabled()
{
$debugModeEnabled = $this->getConfig('debug');
if ($debugModeEnabled !== null) {
return $debugModeEnabled;
}
if (isset($_SERVER['PICO_DEBUG'])) {
$this->config['debug'] = (bool) $_SERVER['PICO_DEBUG'];
} elseif (isset($_SERVER['REDIRECT_PICO_DEBUG'])) {
$this->config['debug'] = (bool) $_SERVER['REDIRECT_PICO_DEBUG'];
} else {
$this->config['debug'] = false;
}
return $this->config['debug'];
}
/** /**
* Returns the URL to a given page * Returns the URL to a given page
* *