Do not require phar extension
[phancap.git] / src / phancap / Config.php
index bb39da1a326e53637e8627a75e70de94188e0bcd..e45f08b38042c7ff9f9dab36cc22517775a51e8c 100644 (file)
@@ -1,6 +1,29 @@
 <?php
+/**
+ * Part of phancap
+ *
+ * PHP version 5
+ *
+ * @category  Tools
+ * @package   Config
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link      http://cweiske.de/phancap.htm
+ */
 namespace phancap;
 
+/**
+ * Phancap configuration
+ *
+ * @category  Tools
+ * @package   Config
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @version   Release: @package_version@
+ * @link      http://cweiske.de/phancap.htm
+ */
 class Config
 {
     /**
@@ -87,7 +110,15 @@ class Config
      */
     public $screenshotMinAge = 'PT1H';
 
+    /**
+     * Cutycapt adapter options
+     */
+    public $cutycapt = array();
 
+
+    /**
+     * Initialize default values and loads configuration file paths
+     */
     public function __construct()
     {
         $this->cacheDir    = getcwd() . '/imgcache/';
@@ -100,6 +131,12 @@ class Config
         $this->loadConfigFilePaths();
     }
 
+    /**
+     * Load the first configuration file that exists
+     *
+     * @return void
+     * @uses   $cfgFileExists
+     */
     public function load()
     {
         $this->cfgFileExists = false;
@@ -121,12 +158,18 @@ class Config
      */
     protected function loadConfigFilePaths()
     {
-        $pharFile = \Phar::running();
-        if ($pharFile == '') {
-            $this->cfgFiles[] = __DIR__ . '/../../data/phancap.config.php';
-        } else {
+        $phar = false;
+        if (class_exists('\\Phar')) {
+            $pharFile = \Phar::running();
+            if ($pharFile != '') {
+                $phar = true;
+            }
+        }
+        if ($phar) {
             //remove phar:// from the path
             $this->cfgFiles[] = substr($pharFile, 7) . '.config.php';
+        } else {
+            $this->cfgFiles[] = __DIR__ . '/../../data/phancap.config.php';
         }
 
         //TODO: add ~/.config/phancap.php
@@ -134,6 +177,13 @@ class Config
         $this->cfgFiles[] = '/etc/phancap.php';
     }
 
+    /**
+     * Load values of a configuration file into this class
+     *
+     * @param string $filename Configuration file (.php)
+     *
+     * @return void
+     */
     protected function loadFile($filename)
     {
         include $filename;
@@ -143,16 +193,31 @@ class Config
         }
     }
 
+    /**
+     * Check if the cache directory exists and is writable
+     *
+     * @return void
+     * @throws \Exception When something is not ok
+     */
     public function setupCheck()
     {
         if (!is_dir($this->cacheDir)) {
-            throw new \Exception('Cache directory does not exist: ' . $this->cacheDir);
+            throw new \Exception(
+                'Cache directory does not exist: ' . $this->cacheDir
+            );
         }
         if (!is_writable($this->cacheDir)) {
-            throw new \Exception('Cache directory is not writable: ' . $this->cacheDir);
+            throw new \Exception(
+                'Cache directory is not writable: ' . $this->cacheDir
+            );
         }
     }
 
+    /**
+     * Returns the current URL, without fragmet.
+     *
+     * @return string Full URL
+     */
     protected function getCurrentUrl()
     {
         if (!isset($_SERVER['REQUEST_SCHEME'])) {
@@ -164,6 +229,8 @@ class Config
     }
 
     /**
+     * Returns the current URL without the file name in the path
+     *
      * @return string Directory of URL without trailing slash,
      *                and without .phar file
      */
@@ -174,7 +241,7 @@ class Config
         if (substr($url, -1) != '/') {
             $url = substr($url, 0, -strlen(basename($url)) - 1);
         }
-        if (\Phar::running()) {
+        if (class_exists('\\Phar') && \Phar::running()) {
             //remove .phar file name
             $url = substr($url, 0, -strlen(basename($url)) - 1);
         }