浏览代码

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.
Daniel Rudolf 6 年之前
父节点
当前提交
8ce3b0c224
共有 2 个文件被更改,包括 32 次插入0 次删除
  1. 1 0
      config/config.yml.template
  2. 31 0
      lib/Pico.php

+ 1 - 0
config/config.yml.template

@@ -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;
                                     #     Example: http://example.com/pico/
 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
 
 ##

+ 31 - 0
lib/Pico.php

@@ -906,6 +906,7 @@ class Pico
             'site_title' => 'Pico',
             'base_url' => '',
             'rewrite_url' => null,
+            'debug' => null,
             'timezone' => null,
             'theme' => 'default',
             'theme_url' => null,
@@ -928,6 +929,10 @@ class Pico
             $this->config['rewrite_url'] = $this->isUrlRewritingEnabled();
         }
 
+        if ($this->config['debug'] === null) {
+            $this->config['debug'] = $this->isDebugModeEnabled();
+        }
+
         if (!$this->config['timezone']) {
             // 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
@@ -959,6 +964,9 @@ class Pico
             if ($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']) {
@@ -2120,6 +2128,29 @@ class Pico
         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
      *